diff --git a/src/core/lombok/javac/JavacAST.java b/src/core/lombok/javac/JavacAST.java index 319d9dd2..215a2110 100644 --- a/src/core/lombok/javac/JavacAST.java +++ b/src/core/lombok/javac/JavacAST.java @@ -78,7 +78,6 @@ public class JavacAST extends AST { private final JavacTreeMaker treeMaker; private final Symtab symtab; private final JavacTypes javacTypes; - private final Log log; private final ErrorLog errorLogger; private final Context context; private static final URI NOT_CALCULATED_MARKER = URI.create("https://projectlombok.org/not/calculated"); @@ -87,16 +86,16 @@ public class JavacAST extends AST { /** * Creates a new JavacAST of the provided Compilation Unit. * - * @param messager A Messager for warning and error reporting. + * @param errorLog A logger for warning and error reporting. * @param context A Context object for interfacing with the compiler. * @param top The compilation unit, which serves as the top level node in the tree to be built. + * @param cleanup The registry for cleanup tasks. */ - public JavacAST(Messager messager, Context context, JCCompilationUnit top, CleanupRegistry cleanup) { + public JavacAST(ErrorLog errorLog, Context context, JCCompilationUnit top, CleanupRegistry cleanup) { super(sourceName(top), PackageName.getPackageName(top), new JavacImportList(top), statementTypes()); setTop(buildCompilationUnit(top)); this.context = context; - this.log = Log.instance(context); - this.errorLogger = ErrorLog.create(messager, log); + this.errorLogger = errorLog; this.elements = JavacElements.instance(context); this.treeMaker = new JavacTreeMaker(TreeMaker.instance(context)); this.symtab = Symtab.instance(context); @@ -571,7 +570,7 @@ public class JavacAST extends AST { JCCompilationUnit top = (JCCompilationUnit) top().get(); newSource = top.sourcefile; if (newSource != null) { - oldSource = log.useSource(newSource); + oldSource = errorLogger.useSource(newSource); if (pos == null) pos = astObject.pos(); } if (pos != null && node != null && attemptToRemoveErrorsInRange) { @@ -594,7 +593,7 @@ public class JavacAST extends AST { break; } } finally { - if (newSource != null) log.useSource(oldSource); + if (newSource != null) errorLogger.useSource(oldSource); } } @@ -645,6 +644,10 @@ public class JavacAST extends AST { this.warningCount = warningCount; } + final JavaFileObject useSource(JavaFileObject file) { + return log.useSource(file); + } + final void error(DiagnosticPosition pos, String message) { increment(errorCount); error1(pos, message); @@ -675,12 +678,13 @@ public class JavacAST extends AST { } } - static ErrorLog create(Messager messager, Log log) { + static ErrorLog create(Messager messager, Context context) { Field errorCount; try { errorCount = Permit.getField(messager.getClass(), "errorCount"); } catch (Throwable t) { errorCount = null; } + Log log = Log.instance(context); boolean hasMultipleErrors = false; for (Field field : log.getClass().getFields()) { if (field.getName().equals("multipleErrors")) { diff --git a/src/core/lombok/javac/JavacTransformer.java b/src/core/lombok/javac/JavacTransformer.java index a2e00680..e4da13f0 100644 --- a/src/core/lombok/javac/JavacTransformer.java +++ b/src/core/lombok/javac/JavacTransformer.java @@ -57,9 +57,13 @@ public class JavacTransformer { } public void transform(long priority, Context context, List compilationUnits, CleanupRegistry cleanup) { + if (compilationUnits.isEmpty()) { + return; + } + JavacAST.ErrorLog errorLog = JavacAST.ErrorLog.create(messager, context); for (JCCompilationUnit unit : compilationUnits) { if (!Boolean.TRUE.equals(LombokConfiguration.read(ConfigurationKeys.LOMBOK_DISABLE, JavacAST.getAbsoluteFileLocation(unit)))) { - JavacAST ast = new JavacAST(messager, context, unit, cleanup); + JavacAST ast = new JavacAST(errorLog, context, unit, cleanup); ast.traverse(new AnnotationVisitor(priority)); handlers.callASTVisitors(ast, priority); if (ast.isChanged()) LombokOptions.markChanged(context, (JCCompilationUnit) ast.top().get());