mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-14 04:16:19 +00:00
[fixes #3540] Store transformation state in CompilationUnit
This commit is contained in:
1 parent
d328ec35c1
commit
214665bd44
4 files changed
+48
-18
No files matched your search
@@ -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, ASTNode> ASTNode_generatedBy = FieldAugment.augment(ASTNode.class, ASTNode.class, "$generatedBy");
|
||||
public static final FieldAugment<Annotation, Boolean> Annotation_applied = FieldAugment.augment(Annotation.class, boolean.class, "lombok$applied");
|
||||
public static final FieldAugment<ICompilationUnit, Map<String, String>> CompilationUnit_javadoc = FieldAugment.augment(ICompilationUnit.class, Map.class, "$javadoc");
|
||||
public static final FieldAugment<CompilationUnitDeclaration, TransformationState> CompilationUnitDeclaration_transformationState = FieldAugment.augment(CompilationUnitDeclaration.class, Object.class, "$transformationState");
|
||||
|
||||
public static final class EclipseAugments {
|
||||
private EclipseAugments() {
|
||||
|
||||
@@ -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<CompilationUnitDeclaration, State> transformationStates = Collections.synchronizedMap(new WeakHashMap<CompilationUnitDeclaration, State>());
|
||||
|
||||
static {
|
||||
String v = System.getProperty("lombok.histogram");
|
||||
@@ -142,14 +139,14 @@ public class TransformEclipseAST {
|
||||
* @return <code>true</code> 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
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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";
|
||||
|
||||
Reference in new issue
Block a user