From 355ea57b8075eacca39d3e0cbcdec67585d095fe Mon Sep 17 00:00:00 2001 From: Rawi01 Date: Tue, 14 Jul 2020 11:17:38 +0200 Subject: Handle each Eclipse ASTs not more than two times (diet + full) --- src/core/lombok/eclipse/EclipseAST.java | 2 +- src/core/lombok/eclipse/TransformEclipseAST.java | 27 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) (limited to 'src/core/lombok/eclipse') 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 { 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 completlyHandled = new WeakHashMap(); static { String v = System.getProperty("lombok.histogram"); @@ -129,6 +131,30 @@ public class TransformEclipseAST { return existing; } + /** + * Check if lombok already handled the given AST. This method will return + * true 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 true 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 @@ -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. -- cgit From f44c642d406c2ad9ca6d679ca1b336e68ff28853 Mon Sep 17 00:00:00 2001 From: Rawi01 Date: Mon, 27 Jul 2020 13:37:59 +0200 Subject: Use enum instead of Boolean; switch to synchronized map --- src/core/lombok/eclipse/TransformEclipseAST.java | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'src/core/lombok/eclipse') diff --git a/src/core/lombok/eclipse/TransformEclipseAST.java b/src/core/lombok/eclipse/TransformEclipseAST.java index f7b6976f..59a0709e 100644 --- a/src/core/lombok/eclipse/TransformEclipseAST.java +++ b/src/core/lombok/eclipse/TransformEclipseAST.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2019 The Project Lombok Authors. + * Copyright (C) 2009-2020 The Project Lombok Authors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -24,6 +24,8 @@ package lombok.eclipse; import static lombok.eclipse.handlers.EclipseHandlerUtil.*; import java.lang.reflect.Field; +import java.util.Collections; +import java.util.Map; import java.util.WeakHashMap; import lombok.ConfigurationKeys; @@ -64,7 +66,7 @@ public class TransformEclipseAST { public static boolean disableLombok = false; private static final HistogramTracker lombokTracker; - private static WeakHashMap completlyHandled = new WeakHashMap(); + private static Map transformationStates = Collections.synchronizedMap(new WeakHashMap()); static { String v = System.getProperty("lombok.histogram"); @@ -143,14 +145,14 @@ public class TransformEclipseAST { * @return true 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; + State state = transformationStates.get(ast); + + if (state == State.FULL) return true; + if (state == State.DIET) { if (!EclipseAST.isComplete(ast)) return true; - - completlyHandled.put(ast, Boolean.TRUE); + transformationStates.put(ast, State.FULL); } else { - completlyHandled.put(ast, Boolean.FALSE); + transformationStates.put(ast, State.DIET); } return false; } @@ -270,4 +272,9 @@ public class TransformEclipseAST { nextPriority = Math.min(nextPriority, handlers.handleAnnotation(top, annotationNode, annotation, priority)); } } + + private static enum State { + DIET, + FULL + } } -- cgit From edbfdfe8c52c17a38bf2b526d14a4f622c5402f7 Mon Sep 17 00:00:00 2001 From: Kay Schubert Date: Mon, 17 Aug 2020 15:57:45 +0200 Subject: Issue 2552 - generate class initializer body only after field member injection --- src/core/lombok/eclipse/handlers/HandleFieldNameConstants.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/core/lombok/eclipse') diff --git a/src/core/lombok/eclipse/handlers/HandleFieldNameConstants.java b/src/core/lombok/eclipse/handlers/HandleFieldNameConstants.java index 9343011f..cee3912c 100644 --- a/src/core/lombok/eclipse/handlers/HandleFieldNameConstants.java +++ b/src/core/lombok/eclipse/handlers/HandleFieldNameConstants.java @@ -171,10 +171,10 @@ public class HandleFieldNameConstants extends EclipseAnnotationHandler