aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/lombok/eclipse/handlers/HandleFieldNameConstants.java40
-rw-r--r--src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java6
-rw-r--r--src/eclipseAgent/lombok/eclipse/agent/PatchDiagnostics.java11
-rwxr-xr-xsrc/eclipseAgent/lombok/launch/PatchFixesHider.java12
4 files changed, 40 insertions, 29 deletions
diff --git a/src/core/lombok/eclipse/handlers/HandleFieldNameConstants.java b/src/core/lombok/eclipse/handlers/HandleFieldNameConstants.java
index 9e81a068..1caccd59 100644
--- a/src/core/lombok/eclipse/handlers/HandleFieldNameConstants.java
+++ b/src/core/lombok/eclipse/handlers/HandleFieldNameConstants.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2014-2018 The Project Lombok Authors.
+ * Copyright (C) 2014-2019 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
@@ -27,15 +27,7 @@ import static lombok.eclipse.handlers.EclipseHandlerUtil.*;
import java.util.ArrayList;
import java.util.List;
-import lombok.AccessLevel;
-import lombok.ConfigurationKeys;
-import lombok.core.AST.Kind;
-import lombok.core.AnnotationValues;
-import lombok.eclipse.Eclipse;
-import lombok.eclipse.EclipseAnnotationHandler;
-import lombok.eclipse.EclipseNode;
-import lombok.experimental.FieldNameConstants;
-
+import org.eclipse.jdt.internal.compiler.ASTVisitor;
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
import org.eclipse.jdt.internal.compiler.ast.AllocationExpression;
import org.eclipse.jdt.internal.compiler.ast.Annotation;
@@ -51,6 +43,16 @@ import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
import org.eclipse.jdt.internal.compiler.lookup.TypeConstants;
import org.mangosdk.spi.ProviderFor;
+import lombok.AccessLevel;
+import lombok.ConfigurationKeys;
+import lombok.core.AST.Kind;
+import lombok.core.AnnotationValues;
+import lombok.eclipse.Eclipse;
+import lombok.eclipse.EclipseAnnotationHandler;
+import lombok.eclipse.EclipseNode;
+import lombok.eclipse.handlers.EclipseHandlerUtil.MemberExistsResult;
+import lombok.experimental.FieldNameConstants;
+
@ProviderFor(EclipseAnnotationHandler.class)
public class HandleFieldNameConstants extends EclipseAnnotationHandler<FieldNameConstants> {
public void generateFieldNameConstantsForType(EclipseNode typeNode, EclipseNode errorNode, AccessLevel level, boolean asEnum, String innerTypeName, boolean onlyExplicit) {
@@ -88,7 +90,7 @@ public class HandleFieldNameConstants extends EclipseAnnotationHandler<FieldName
return filterField(fieldDecl);
}
- public void handle(AnnotationValues<FieldNameConstants> annotation, Annotation ast, EclipseNode annotationNode) {
+ @Override public void handle(AnnotationValues<FieldNameConstants> annotation, Annotation ast, EclipseNode annotationNode) {
handleExperimentalFlagUsage(annotationNode, ConfigurationKeys.FIELD_NAME_CONSTANTS_FLAG_USAGE, "@FieldNameConstants");
EclipseNode node = annotationNode.up();
@@ -117,6 +119,7 @@ public class HandleFieldNameConstants extends EclipseAnnotationHandler<FieldName
private void createInnerTypeFieldNameConstants(EclipseNode typeNode, EclipseNode errorNode, ASTNode source, AccessLevel level, List<EclipseNode> fields, boolean asEnum, String innerTypeName) {
if (fields.isEmpty()) return;
+ ASTVisitor generatedByVisitor = new SetGeneratedByVisitor(source);
TypeDeclaration parent = (TypeDeclaration) typeNode.get();
EclipseNode fieldsType = findInnerClass(typeNode, innerTypeName);
boolean genConstr = false, genClinit = false;
@@ -125,11 +128,12 @@ public class HandleFieldNameConstants extends EclipseAnnotationHandler<FieldName
if (fieldsType == null) {
generatedInnerType = new TypeDeclaration(parent.compilationResult);
generatedInnerType.bits |= Eclipse.ECLIPSE_DO_NOT_TOUCH_FLAG;
- generatedInnerType.modifiers = toEclipseModifier(level) | (asEnum ? ClassFileConstants.AccEnum : ClassFileConstants.AccStatic | ClassFileConstants.AccFinal);
+ generatedInnerType.modifiers = toEclipseModifier(level) | (asEnum ? ClassFileConstants.AccEnum : (ClassFileConstants.AccStatic | ClassFileConstants.AccFinal));
generatedInnerType.name = name;
fieldsType = injectType(typeNode, generatedInnerType);
genConstr = true;
genClinit = asEnum;
+ generatedInnerType.traverse(generatedByVisitor, ((TypeDeclaration) typeNode.get()).scope);
} else {
TypeDeclaration builderTypeDeclaration = (TypeDeclaration) fieldsType.get();
if (asEnum && (builderTypeDeclaration.modifiers & ClassFileConstants.AccEnum) == 0) {
@@ -146,8 +150,6 @@ public class HandleFieldNameConstants extends EclipseAnnotationHandler<FieldName
if (genConstr) {
ConstructorDeclaration constructor = new ConstructorDeclaration(parent.compilationResult);
constructor.selector = name;
- constructor.declarationSourceStart = constructor.sourceStart = source.sourceStart;
- constructor.declarationSourceEnd = constructor.sourceEnd = source.sourceEnd;
constructor.modifiers = ClassFileConstants.AccPrivate;
ExplicitConstructorCall superCall = new ExplicitConstructorCall(0);
superCall.sourceStart = source.sourceStart;
@@ -157,11 +159,12 @@ public class HandleFieldNameConstants extends EclipseAnnotationHandler<FieldName
if (!asEnum) constructor.statements = new Statement[0];
injectMethod(fieldsType, constructor);
}
+
if (genClinit) {
Clinit cli = new Clinit(parent.compilationResult);
injectMethod(fieldsType, cli);
+ cli.traverse(generatedByVisitor, ((TypeDeclaration) fieldsType.get()).scope);
}
-
for (EclipseNode fieldNode : fields) {
FieldDeclaration field = (FieldDeclaration) fieldNode.get();
@@ -171,19 +174,20 @@ public class HandleFieldNameConstants extends EclipseAnnotationHandler<FieldName
long p = (long) pS << 32 | pE;
FieldDeclaration constantField = new FieldDeclaration(fName, pS, pE);
constantField.bits |= Eclipse.ECLIPSE_DO_NOT_TOUCH_FLAG;
- constantField.modifiers = asEnum ? 0 : ClassFileConstants.AccPublic | ClassFileConstants.AccStatic | ClassFileConstants.AccFinal;
- constantField.type = asEnum ? null : new QualifiedTypeReference(TypeConstants.JAVA_LANG_STRING, new long[] {p, p, p});
if (asEnum) {
AllocationExpression ac = new AllocationExpression();
ac.enumConstant = constantField;
ac.sourceStart = source.sourceStart;
ac.sourceEnd = source.sourceEnd;
constantField.initialization = ac;
+ constantField.modifiers = 0;
} else {
+ constantField.type = new QualifiedTypeReference(TypeConstants.JAVA_LANG_STRING, new long[] {p, p, p});
constantField.initialization = new StringLiteral(field.name, pS, pE, 0);
+ constantField.modifiers = ClassFileConstants.AccPublic | ClassFileConstants.AccStatic | ClassFileConstants.AccFinal;
}
- constantField.traverse(new SetGeneratedByVisitor(source), null);
injectField(fieldsType, constantField);
+ constantField.traverse(generatedByVisitor, ((TypeDeclaration) fieldsType.get()).initializerScope);
}
}
}
diff --git a/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java b/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java
index a6d745b6..0e74dfaf 100644
--- a/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java
+++ b/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009-2015 The Project Lombok Authors.
+ * Copyright (C) 2009-2019 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
@@ -392,8 +392,8 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable {
private static void patchIdentifierEndReparse(ScriptManager sm) {
sm.addScript(ScriptBuilder.wrapReturnValue()
.target(new MethodTarget("org.eclipse.jdt.core.dom.ASTConverter", "retrieveIdentifierEndPosition"))
- .wrapMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "fixRetrieveIdentifierEndPosition", "int", "int", "int"))
- .transplant().request(StackRequest.RETURN_VALUE, StackRequest.PARAM2).build());
+ .wrapMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "fixRetrieveIdentifierEndPosition", "int", "int", "int", "int"))
+ .transplant().request(StackRequest.RETURN_VALUE, StackRequest.PARAM1, StackRequest.PARAM2).build());
}
private static void patchRetrieveEllipsisStartPosition(ScriptManager sm) {
diff --git a/src/eclipseAgent/lombok/eclipse/agent/PatchDiagnostics.java b/src/eclipseAgent/lombok/eclipse/agent/PatchDiagnostics.java
index 82c4f522..157d92a3 100644
--- a/src/eclipseAgent/lombok/eclipse/agent/PatchDiagnostics.java
+++ b/src/eclipseAgent/lombok/eclipse/agent/PatchDiagnostics.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2012 The Project Lombok Authors.
+ * Copyright (C) 2012-2019 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
@@ -29,14 +29,19 @@ public class PatchDiagnostics {
* checks, and throw the exact same exception (thus, effectively, we don't change how eclipse operates), but, we <em>do</em> provide a useful message.
*/
public static boolean setSourceRangeCheck(Object astNode, int startPosition, int length) {
+ String nodeTxt;
if (startPosition >= 0 && length < 0) {
+ if (astNode == null) nodeTxt = "(NULL NODE)";
+ else nodeTxt = astNode.getClass() + ": " + astNode.toString();
throw new IllegalArgumentException("startPos = " + startPosition + " and length is " + length + ".\n" +
- "This breaks the rule that lengths are not allowed to be negative. Affected Node:\n" + astNode);
+ "This breaks the rule that lengths are not allowed to be negative. Affected Node:\n" + nodeTxt);
}
if (startPosition < 0 && length != 0) {
+ if (astNode == null) nodeTxt = "(NULL NODE)";
+ else nodeTxt = astNode.getClass() + ": " + astNode.toString();
throw new IllegalArgumentException("startPos = " + startPosition + " and length is " + length + ".\n" +
- "This breaks the rule that length must be 0 if startPosition is negative. Affected Node:\n" + astNode);
+ "This breaks the rule that length must be 0 if startPosition is negative. Affected Node:\n" + nodeTxt);
}
return false;
diff --git a/src/eclipseAgent/lombok/launch/PatchFixesHider.java b/src/eclipseAgent/lombok/launch/PatchFixesHider.java
index 5c409603..3741aba8 100755
--- a/src/eclipseAgent/lombok/launch/PatchFixesHider.java
+++ b/src/eclipseAgent/lombok/launch/PatchFixesHider.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2010-2015 The Project Lombok Authors.
+ * Copyright (C) 2010-2019 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
@@ -31,8 +31,6 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Stack;
-import lombok.eclipse.EclipseAugments;
-
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.IAnnotatable;
import org.eclipse.jdt.core.IAnnotation;
@@ -64,6 +62,8 @@ import org.eclipse.jdt.internal.core.dom.rewrite.TokenScanner;
import org.eclipse.jdt.internal.corext.refactoring.SearchResultGroup;
import org.eclipse.jdt.internal.corext.refactoring.structure.ASTNodeSearchUtil;
+import lombok.eclipse.EclipseAugments;
+
/** These contain a mix of the following:
* <ul>
* <li> 'dependency free' method wrappers that cross the shadowloader barrier.
@@ -476,8 +476,10 @@ final class PatchFixesHider {
return original == -1 ? start : original;
}
- public static int fixRetrieveIdentifierEndPosition(int original, int end) {
- return original == -1 ? end : original;
+ public static int fixRetrieveIdentifierEndPosition(int original, int start, int end) {
+ if (original == -1) return end;
+ if (original < start) return end;
+ return original;
}
public static int fixRetrieveEllipsisStartPosition(int original, int end) {