From 728e3f957d134f42766d3726d1e0a793f809744c Mon Sep 17 00:00:00 2001 From: Manu Sridharan Date: Mon, 15 Jul 2024 15:46:13 -0700 Subject: [PATCH] Lazily load plugin checks when running auto-patching --- .../com/google/errorprone/ErrorProneAnalyzer.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/check_api/src/main/java/com/google/errorprone/ErrorProneAnalyzer.java b/check_api/src/main/java/com/google/errorprone/ErrorProneAnalyzer.java index c59458442d0..c1f1d10d4f0 100644 --- a/check_api/src/main/java/com/google/errorprone/ErrorProneAnalyzer.java +++ b/check_api/src/main/java/com/google/errorprone/ErrorProneAnalyzer.java @@ -72,12 +72,12 @@ public static ErrorProneAnalyzer createAnalyzer( refactoringCollection[0] = RefactoringCollection.refactor(epOptions.patchingOptions(), context); // Refaster refactorer or using builtin checks - CodeTransformer codeTransformer = + Supplier codeTransformer = epOptions .patchingOptions() .customRefactorer() .or( - () -> { + Suppliers.memoize(() -> { ScannerSupplier toUse = ErrorPronePlugins.loadPlugins(scannerSupplier, context); ImmutableSet namedCheckers = epOptions.patchingOptions().namedCheckers(); if (!namedCheckers.isEmpty()) { @@ -86,8 +86,7 @@ public static ErrorProneAnalyzer createAnalyzer( toUse = toUse.applyOverrides(epOptions); } return ErrorProneScannerTransformer.create(toUse.get()); - }) - .get(); + })); return createWithCustomDescriptionListener( codeTransformer, epOptions, context, refactoringCollection[0]); @@ -160,12 +159,12 @@ private static Supplier scansPlugins( } static ErrorProneAnalyzer createWithCustomDescriptionListener( - CodeTransformer codeTransformer, + Supplier codeTransformer, ErrorProneOptions errorProneOptions, Context context, DescriptionListener.Factory descriptionListenerFactory) { return new ErrorProneAnalyzer( - Suppliers.ofInstance(codeTransformer), + codeTransformer, errorProneOptions, context, descriptionListenerFactory);