diff --git a/src/core/lombok/eclipse/EcjAugments.java b/src/core/lombok/eclipse/EcjAugments.java index cd7173a8..f759f5a4 100644 --- a/src/core/lombok/eclipse/EcjAugments.java +++ b/src/core/lombok/eclipse/EcjAugments.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2014 The Project Lombok Authors. + * Copyright (C) 2014-2023 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 @@ -21,12 +21,13 @@ */ package lombok.eclipse; -import java.util.Map; import java.util.List; +import java.util.Map; import java.util.concurrent.ConcurrentMap; import org.eclipse.jdt.internal.compiler.ast.ASTNode; import org.eclipse.jdt.internal.compiler.ast.Annotation; +import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration; import org.eclipse.jdt.internal.compiler.env.ICompilationUnit; import org.eclipse.jdt.internal.core.CompilationUnit; @@ -44,6 +45,7 @@ public final class EcjAugments { public static final FieldAugment ASTNode_generatedBy = FieldAugment.augment(ASTNode.class, ASTNode.class, "$generatedBy"); public static final FieldAugment Annotation_applied = FieldAugment.augment(Annotation.class, boolean.class, "lombok$applied"); public static final FieldAugment> CompilationUnit_javadoc = FieldAugment.augment(ICompilationUnit.class, Map.class, "$javadoc"); + public static final FieldAugment CompilationUnitDeclaration_transformationState = FieldAugment.augment(CompilationUnitDeclaration.class, Object.class, "$transformationState"); public static final class EclipseAugments { private EclipseAugments() { diff --git a/src/core/lombok/eclipse/TransformEclipseAST.java b/src/core/lombok/eclipse/TransformEclipseAST.java index 87b163c0..7fa5f215 100644 --- a/src/core/lombok/eclipse/TransformEclipseAST.java +++ b/src/core/lombok/eclipse/TransformEclipseAST.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2020 The Project Lombok Authors. + * Copyright (C) 2009-2023 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 @@ -21,12 +21,10 @@ */ package lombok.eclipse; +import static lombok.eclipse.EcjAugments.CompilationUnitDeclaration_transformationState; 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; import lombok.core.LombokConfiguration; @@ -63,7 +61,6 @@ public class TransformEclipseAST { public static boolean disableLombok = false; private static final HistogramTracker lombokTracker; - private static Map transformationStates = Collections.synchronizedMap(new WeakHashMap()); static { String v = System.getProperty("lombok.histogram"); @@ -142,14 +139,14 @@ public class TransformEclipseAST { * @return true if this AST was already handled by lombok. */ public static boolean alreadyTransformed(CompilationUnitDeclaration ast) { - State state = transformationStates.get(ast); + TransformationState state = CompilationUnitDeclaration_transformationState.get(ast); - if (state == State.FULL) return true; - if (state == State.DIET) { + if (state == TransformationState.FULL) return true; + if (state == TransformationState.DIET) { if (!EclipseAST.isComplete(ast)) return true; - transformationStates.put(ast, State.FULL); + CompilationUnitDeclaration_transformationState.set(ast, TransformationState.FULL); } else { - transformationStates.put(ast, State.DIET); + CompilationUnitDeclaration_transformationState.set(ast, TransformationState.DIET); } return false; } @@ -168,6 +165,10 @@ public class TransformEclipseAST { public static void transform(Parser parser, CompilationUnitDeclaration ast) { if (disableLombok) return; + // Skip module-info.java + char[] fileName = ast.getFileName(); + if (fileName != null && String.valueOf(fileName).endsWith("module-info.java")) return; + if (Symbols.hasSymbol("lombok.disable")) return; if (alreadyTransformed(ast)) return; @@ -270,9 +271,4 @@ public class TransformEclipseAST { nextPriority = Math.min(nextPriority, handlers.handleAnnotation(top, annotationNode, annotation, priority)); } } - - private static enum State { - DIET, - FULL - } } diff --git a/src/core/lombok/eclipse/TransformationState.java b/src/core/lombok/eclipse/TransformationState.java new file mode 100644 index 00000000..fe11fe65 --- /dev/null +++ b/src/core/lombok/eclipse/TransformationState.java @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2023 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 + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package lombok.eclipse; + +enum TransformationState { + DIET, + FULL +} \ No newline at end of file diff --git a/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java b/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java index aa548af0..d459c178 100644 --- a/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java +++ b/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2021 The Project Lombok Authors. + * Copyright (C) 2009-2023 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 @@ -702,6 +702,11 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable { .fieldName("$lombokAST").fieldType("Ljava/lang/Object;") .setPublic().setTransient().build()); + sm.addScript(ScriptBuilder.addField() + .targetClass("org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration") + .fieldName("$transformationState").fieldType("Ljava/lang/Object;") + .setPublic().setTransient().build()); + final String PARSER_SIG = "org.eclipse.jdt.internal.compiler.parser.Parser"; final String CUD_SIG = "org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration"; final String OBJECT_SIG = "java.lang.Object";