diff options
author | Rawi01 <Rawi01@users.noreply.github.com> | 2020-07-14 11:17:38 +0200 |
---|---|---|
committer | Roel Spilker <r.spilker@gmail.com> | 2020-08-27 22:59:59 +0200 |
commit | 355ea57b8075eacca39d3e0cbcdec67585d095fe (patch) | |
tree | e1e4c1494cf4ce46acad869bf169473d4524bea5 /src | |
parent | 0736f291747b1fc4d3ce3b7d9ccbaa129d15ed20 (diff) | |
download | lombok-355ea57b8075eacca39d3e0cbcdec67585d095fe.tar.gz lombok-355ea57b8075eacca39d3e0cbcdec67585d095fe.tar.bz2 lombok-355ea57b8075eacca39d3e0cbcdec67585d095fe.zip |
Handle each Eclipse ASTs not more than two times (diet + full)
Diffstat (limited to 'src')
-rw-r--r-- | src/core/lombok/eclipse/EclipseAST.java | 2 | ||||
-rw-r--r-- | src/core/lombok/eclipse/TransformEclipseAST.java | 27 |
2 files changed, 28 insertions, 1 deletions
diff --git a/src/core/lombok/eclipse/EclipseAST.java b/src/core/lombok/eclipse/EclipseAST.java index b45ac72d..d53856af 100644 --- a/src/core/lombok/eclipse/EclipseAST.java +++ b/src/core/lombok/eclipse/EclipseAST.java @@ -350,7 +350,7 @@ public class EclipseAST extends AST<EclipseAST, EclipseNode, ASTNode> { if (!changed) clearChanged(); } - private static boolean isComplete(CompilationUnitDeclaration unit) { + public static boolean isComplete(CompilationUnitDeclaration unit) { return (unit.bits & ASTNode.HasAllMethodBodies) != 0; } diff --git a/src/core/lombok/eclipse/TransformEclipseAST.java b/src/core/lombok/eclipse/TransformEclipseAST.java index 6fcde937..f7b6976f 100644 --- a/src/core/lombok/eclipse/TransformEclipseAST.java +++ b/src/core/lombok/eclipse/TransformEclipseAST.java @@ -24,6 +24,7 @@ package lombok.eclipse; import static lombok.eclipse.handlers.EclipseHandlerUtil.*; import java.lang.reflect.Field; +import java.util.WeakHashMap; import lombok.ConfigurationKeys; import lombok.core.LombokConfiguration; @@ -63,6 +64,7 @@ public class TransformEclipseAST { public static boolean disableLombok = false; private static final HistogramTracker lombokTracker; + private static WeakHashMap<CompilationUnitDeclaration, Boolean> completlyHandled = new WeakHashMap<CompilationUnitDeclaration, Boolean>(); static { String v = System.getProperty("lombok.histogram"); @@ -130,6 +132,30 @@ public class TransformEclipseAST { } /** + * Check if lombok already handled the given AST. This method will return + * <code>true</code> once for diet mode and once for full mode. + * + * The reason for this is that Eclipse invokes the transform method multiple + * times during compilation and it is enough to transform it once and not + * repeat the whole thing over and over again. + * + * @param ast The AST node belonging to the compilation unit (java speak for a single source file). + * @return <code>true</code> if this AST was already handled by lombok. + */ + public static boolean alreadyTransformed(CompilationUnitDeclaration ast) { + Boolean state = completlyHandled.get(ast); + if (state != null) { + if (state) return true; + if (!EclipseAST.isComplete(ast)) return true; + + completlyHandled.put(ast, Boolean.TRUE); + } else { + completlyHandled.put(ast, Boolean.FALSE); + } + return false; + } + + /** * This method is called immediately after Eclipse finishes building a CompilationUnitDeclaration, which is * the top-level AST node when Eclipse parses a source file. The signature is 'magic' - you should not * change it! @@ -144,6 +170,7 @@ public class TransformEclipseAST { if (disableLombok) return; if (Symbols.hasSymbol("lombok.disable")) return; + if (alreadyTransformed(ast)) return; // Do NOT abort if (ast.bits & ASTNode.HasAllMethodBodies) != 0 - that doesn't work. |