aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xAUTHORS1
-rw-r--r--src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java7
-rwxr-xr-xsrc/core/lombok/eclipse/handlers/HandleConstructor.java9
-rwxr-xr-xsrc/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java21
-rw-r--r--src/core/lombok/eclipse/handlers/HandleSetter.java5
-rw-r--r--src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java8
-rwxr-xr-xsrc/eclipseAgent/lombok/launch/PatchFixesHider.java17
-rw-r--r--src/utils/lombok/eclipse/Eclipse.java1
-rw-r--r--test/transform/resource/after-delombok/EqualsAndHashCodeWithNonNullByDefault.java23
-rw-r--r--test/transform/resource/after-ecj/EqualsAndHashCodeWithNonNullByDefault.java23
-rw-r--r--test/transform/resource/before/EqualsAndHashCodeWithNonNullByDefault.java6
11 files changed, 111 insertions, 10 deletions
diff --git a/AUTHORS b/AUTHORS
index 10ad3d14..ba83bf4e 100755
--- a/AUTHORS
+++ b/AUTHORS
@@ -19,6 +19,7 @@ Jacob Middag <jacob@gaddim.nl>
Jan Matèrne <jhm@apache.org>
Jan Rieke <it@janrieke.de>
Jappe van der Hel <jappe.vanderhel@gmail.com>
+John Paul Taylor II <johnpaultaylorii@gmail.com>
Karthik kathari <44122128+varkart@users.noreply.github.com>
Kevin Chirls <kchirls@users.noreply.github.com>
Liu DongMiao <liudongmiao@gmail.com>
diff --git a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
index 65e2c5c8..c313cf51 100644
--- a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
+++ b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
@@ -2608,6 +2608,13 @@ public class EclipseHandlerUtil {
applyAnnotationToVarDecl(typeNode, arg, lib.getNullableAnnotation(), lib.isTypeUse());
}
+ public static void createRelevantNullableAnnotation(EclipseNode typeNode, Argument arg, List<NullAnnotationLibrary> applied) {
+ NullAnnotationLibrary lib = typeNode.getAst().readConfiguration(ConfigurationKeys.ADD_NULL_ANNOTATIONS);
+ if (lib == null || applied.contains(lib)) return;
+
+ applyAnnotationToVarDecl(typeNode, arg, lib.getNullableAnnotation(), lib.isTypeUse());
+ }
+
public static void createRelevantNonNullAnnotation(EclipseNode typeNode, Argument arg) {
NullAnnotationLibrary lib = typeNode.getAst().readConfiguration(ConfigurationKeys.ADD_NULL_ANNOTATIONS);
if (lib == null) return;
diff --git a/src/core/lombok/eclipse/handlers/HandleConstructor.java b/src/core/lombok/eclipse/handlers/HandleConstructor.java
index e69c3267..52213846 100755
--- a/src/core/lombok/eclipse/handlers/HandleConstructor.java
+++ b/src/core/lombok/eclipse/handlers/HandleConstructor.java
@@ -41,6 +41,7 @@ import lombok.RequiredArgsConstructor;
import lombok.core.AST.Kind;
import lombok.core.configuration.CheckerFrameworkVersion;
import lombok.core.AnnotationValues;
+import lombok.eclipse.Eclipse;
import lombok.eclipse.EclipseAnnotationHandler;
import lombok.eclipse.EclipseNode;
import lombok.eclipse.handlers.EclipseHandlerUtil.MemberExistsResult;
@@ -414,6 +415,10 @@ public class HandleConstructor {
if (nullCheck != null) nullChecks.add(nullCheck);
}
parameter.annotations = copyAnnotations(source, copyableAnnotations);
+ if (parameter.annotations != null) {
+ parameter.bits |= Eclipse.HasTypeAnnotations;
+ constructor.bits |= Eclipse.HasTypeAnnotations;
+ }
params.add(parameter);
}
@@ -555,6 +560,10 @@ public class HandleConstructor {
Argument parameter = new Argument(field.name, fieldPos, copyType(field.type, source), Modifier.FINAL);
parameter.annotations = copyAnnotations(source, findCopyableAnnotations(fieldNode));
+ if (parameter.annotations != null) {
+ parameter.bits |= Eclipse.HasTypeAnnotations;
+ constructor.bits |= Eclipse.HasTypeAnnotations;
+ }
params.add(parameter);
}
diff --git a/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java b/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java
index a5e8dfb5..940612e7 100755
--- a/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java
+++ b/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java
@@ -44,6 +44,7 @@ import lombok.core.handlers.InclusionExclusionUtils.Included;
import lombok.core.AnnotationValues;
import lombok.core.configuration.CallSuperType;
import lombok.core.configuration.CheckerFrameworkVersion;
+import lombok.core.configuration.NullAnnotationLibrary;
import lombok.eclipse.Eclipse;
import lombok.eclipse.EclipseAnnotationHandler;
import lombok.eclipse.EclipseNode;
@@ -606,19 +607,20 @@ public class HandleEqualsAndHashCode extends EclipseAnnotationHandler<EqualsAndH
int pS = source.sourceStart; int pE = source.sourceEnd;
long p = (long) pS << 32 | pE;
- Annotation[] onParamType = null;
+ List<NullAnnotationLibrary> applied = new ArrayList<NullAnnotationLibrary>();
+ Annotation[] onParamNullable = null;
String nearest = scanForNearestAnnotation(type, "javax.annotation.ParametersAreNullableByDefault", "javax.annotation.ParametersAreNonnullByDefault");
if ("javax.annotation.ParametersAreNonnullByDefault".equals(nearest)) {
- onParamType = new Annotation[1];
- onParamType[0] = new MarkerAnnotation(generateQualifiedTypeRef(source, JAVAX_ANNOTATION_NULLABLE), 0);
+ onParamNullable = new Annotation[] { new MarkerAnnotation(generateQualifiedTypeRef(source, JAVAX_ANNOTATION_NULLABLE), 0) };
+ applied.add(NullAnnotationLibrary.JAVAX);
}
+ Annotation[] onParamTypeNullable = null;
nearest = scanForNearestAnnotation(type, "org.eclipse.jdt.annotation.NonNullByDefault");
if (nearest != null) {
- Annotation a = new MarkerAnnotation(generateQualifiedTypeRef(source, ORG_ECLIPSE_JDT_ANNOTATION_NULLABLE), 0);
- if (onParamType != null) onParamType = new Annotation[] {onParamType[0], a};
- else onParamType = new Annotation[] {a};
+ onParamTypeNullable = new Annotation[] { new MarkerAnnotation(generateQualifiedTypeRef(source, ORG_ECLIPSE_JDT_ANNOTATION_NULLABLE), 0) };
+ applied.add(NullAnnotationLibrary.ECLIPSE);
}
MethodDeclaration method = new MethodDeclaration(((CompilationUnitDeclaration) type.top().get()).compilationResult);
@@ -640,12 +642,13 @@ public class HandleEqualsAndHashCode extends EclipseAnnotationHandler<EqualsAndH
method.bodyStart = method.declarationSourceStart = method.sourceStart = source.sourceStart;
method.bodyEnd = method.declarationSourceEnd = method.sourceEnd = source.sourceEnd;
QualifiedTypeReference objectRef = new QualifiedTypeReference(TypeConstants.JAVA_LANG_OBJECT, new long[] { p, p, p });
- if (onParamType != null) objectRef.annotations = new Annotation[][] {null, null, onParamType};
+ if (onParamTypeNullable != null) objectRef.annotations = new Annotation[][] {null, null, onParamTypeNullable};
setGeneratedBy(objectRef, source);
method.arguments = new Argument[] {new Argument(new char[] { 'o' }, 0, objectRef, Modifier.FINAL)};
method.arguments[0].sourceStart = pS; method.arguments[0].sourceEnd = pE;
- if (!onParam.isEmpty()) method.arguments[0].annotations = onParam.toArray(new Annotation[0]);
- EclipseHandlerUtil.createRelevantNullableAnnotation(type, method.arguments[0]);
+ if (!onParam.isEmpty() || onParamNullable != null)
+ method.arguments[0].annotations = copyAnnotations(source, onParam.toArray(new Annotation[0]), onParamNullable);
+ EclipseHandlerUtil.createRelevantNullableAnnotation(type, method.arguments[0], applied);
setGeneratedBy(method.arguments[0], source);
List<Statement> statements = new ArrayList<Statement>();
diff --git a/src/core/lombok/eclipse/handlers/HandleSetter.java b/src/core/lombok/eclipse/handlers/HandleSetter.java
index fda1651d..f09f1485 100644
--- a/src/core/lombok/eclipse/handlers/HandleSetter.java
+++ b/src/core/lombok/eclipse/handlers/HandleSetter.java
@@ -35,6 +35,7 @@ import lombok.ConfigurationKeys;
import lombok.Setter;
import lombok.core.AST.Kind;
import lombok.core.AnnotationValues;
+import lombok.eclipse.Eclipse;
import lombok.eclipse.EclipseAnnotationHandler;
import lombok.eclipse.EclipseNode;
import lombok.experimental.Accessors;
@@ -256,6 +257,10 @@ public class HandleSetter extends EclipseAnnotationHandler<Setter> {
}
method.statements = statements.toArray(new Statement[0]);
param.annotations = copyAnnotations(source, copyableAnnotations, onParam.toArray(new Annotation[0]));
+ if (param.annotations != null) {
+ param.bits |= Eclipse.HasTypeAnnotations;
+ method.bits |= Eclipse.HasTypeAnnotations;
+ }
if (returnType != null && returnStatement != null) createRelevantNonNullAnnotation(sourceNode, method);
diff --git a/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java b/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java
index 2e35cf57..d893b724 100644
--- a/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java
+++ b/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java
@@ -332,12 +332,18 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable {
private static void patchHideGeneratedNodes(ScriptManager sm) {
sm.addScriptIfWitness(OSGI_TYPES, ScriptBuilder.wrapReturnValue()
- .target(new MethodTarget("org.eclipse.jdt.internal.corext.dom.LinkedNodeFinder", "findByNode"))
+ .target(new MethodTarget("org.eclipse.jdt.internal.corext.dom.LinkedNodeFinder", "findByNode", "org.eclipse.jdt.core.dom.SimpleName[]", "org.eclipse.jdt.core.dom.ASTNode", "org.eclipse.jdt.core.dom.SimpleName"))
.target(new MethodTarget("org.eclipse.jdt.internal.corext.dom.LinkedNodeFinder", "findByBinding"))
.wrapMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "removeGeneratedSimpleNames", "org.eclipse.jdt.core.dom.SimpleName[]",
"org.eclipse.jdt.core.dom.SimpleName[]"))
.request(StackRequest.RETURN_VALUE).build());
+ sm.addScriptIfWitness(OSGI_TYPES, ScriptBuilder.wrapReturnValue()
+ .target(new MethodTarget("org.eclipse.jdt.internal.corext.dom.LinkedNodeFinder", "findByNode", "org.eclipse.jdt.core.dom.Name[]", "org.eclipse.jdt.core.dom.ASTNode", "org.eclipse.jdt.core.dom.Name"))
+ .wrapMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "removeGeneratedNames", "org.eclipse.jdt.core.dom.Name[]",
+ "org.eclipse.jdt.core.dom.Name[]"))
+ .request(StackRequest.RETURN_VALUE).build());
+
sm.addScriptIfWitness(OSGI_TYPES, ScriptBuilder.exitEarly()
.target(new MethodTarget("org.eclipse.jdt.core.dom.ASTNode", "accept", "void", "org.eclipse.jdt.core.dom.ASTVisitor"))
.decisionMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "isBlockedVisitorAndGenerated", "boolean", "org.eclipse.jdt.core.dom.ASTNode", "org.eclipse.jdt.core.dom.ASTVisitor"))
diff --git a/src/eclipseAgent/lombok/launch/PatchFixesHider.java b/src/eclipseAgent/lombok/launch/PatchFixesHider.java
index e0c330a2..a844239f 100755
--- a/src/eclipseAgent/lombok/launch/PatchFixesHider.java
+++ b/src/eclipseAgent/lombok/launch/PatchFixesHider.java
@@ -39,6 +39,7 @@ import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.dom.Name;
import org.eclipse.jdt.core.dom.SimpleName;
import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
import org.eclipse.jdt.core.dom.Type;
@@ -780,6 +781,22 @@ final class PatchFixesHider {
return newSimpleNames;
}
+ public static Name[] removeGeneratedNames(Name[] in) throws Exception {
+ Field f = Name.class.getField("$isGenerated");
+
+ int count = 0;
+ for (int i = 0; i < in.length; i++) {
+ if (in[i] == null || !((Boolean)f.get(in[i])).booleanValue()) count++;
+ }
+ if (count == in.length) return in;
+ Name[] newNames = new Name[count];
+ count = 0;
+ for (int i = 0; i < in.length; i++) {
+ if (in[i] == null || !((Boolean)f.get(in[i])).booleanValue()) newNames[count++] = in[i];
+ }
+ return newNames;
+ }
+
public static Annotation[] convertAnnotations(Annotation[] out, IAnnotatable annotatable) {
IAnnotation[] in;
diff --git a/src/utils/lombok/eclipse/Eclipse.java b/src/utils/lombok/eclipse/Eclipse.java
index 0f42ddc6..624e521a 100644
--- a/src/utils/lombok/eclipse/Eclipse.java
+++ b/src/utils/lombok/eclipse/Eclipse.java
@@ -66,6 +66,7 @@ public class Eclipse {
public static final int AccRecord = ASTNode.Bit25; // ECM.AccRecord
public static final int IsCanonicalConstructor = ASTNode.Bit10; // ASTNode.IsCanonicalConstructor
public static final int IsImplicit = ASTNode.Bit11; // ASTNode.IsImplicit
+ public static final int HasTypeAnnotations = ASTNode.Bit21; // ASTNode.HasTypeAnnotations
private static final Pattern SPLIT_AT_DOT = Pattern.compile("\\.");
diff --git a/test/transform/resource/after-delombok/EqualsAndHashCodeWithNonNullByDefault.java b/test/transform/resource/after-delombok/EqualsAndHashCodeWithNonNullByDefault.java
new file mode 100644
index 00000000..37711004
--- /dev/null
+++ b/test/transform/resource/after-delombok/EqualsAndHashCodeWithNonNullByDefault.java
@@ -0,0 +1,23 @@
+import javax.annotation.ParametersAreNonnullByDefault;
+@ParametersAreNonnullByDefault
+class EqualsAndHashCodeWithNonNullByDefault {
+ @java.lang.Override
+ @java.lang.SuppressWarnings("all")
+ public boolean equals(@javax.annotation.Nullable final java.lang.Object o) {
+ if (o == this) return true;
+ if (!(o instanceof EqualsAndHashCodeWithNonNullByDefault)) return false;
+ final EqualsAndHashCodeWithNonNullByDefault other = (EqualsAndHashCodeWithNonNullByDefault) o;
+ if (!other.canEqual((java.lang.Object) this)) return false;
+ return true;
+ }
+ @java.lang.SuppressWarnings("all")
+ protected boolean canEqual(@javax.annotation.Nullable final java.lang.Object other) {
+ return other instanceof EqualsAndHashCodeWithNonNullByDefault;
+ }
+ @java.lang.Override
+ @java.lang.SuppressWarnings("all")
+ public int hashCode() {
+ final int result = 1;
+ return result;
+ }
+}
diff --git a/test/transform/resource/after-ecj/EqualsAndHashCodeWithNonNullByDefault.java b/test/transform/resource/after-ecj/EqualsAndHashCodeWithNonNullByDefault.java
new file mode 100644
index 00000000..0cd170b4
--- /dev/null
+++ b/test/transform/resource/after-ecj/EqualsAndHashCodeWithNonNullByDefault.java
@@ -0,0 +1,23 @@
+import javax.annotation.ParametersAreNonnullByDefault;
+@lombok.EqualsAndHashCode @ParametersAreNonnullByDefault class EqualsAndHashCodeWithNonNullByDefault {
+ EqualsAndHashCodeWithNonNullByDefault() {
+ super();
+ }
+ public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final @javax.annotation.Nullable java.lang.Object o) {
+ if ((o == this))
+ return true;
+ if ((! (o instanceof EqualsAndHashCodeWithNonNullByDefault)))
+ return false;
+ final EqualsAndHashCodeWithNonNullByDefault other = (EqualsAndHashCodeWithNonNullByDefault) o;
+ if ((! other.canEqual((java.lang.Object) this)))
+ return false;
+ return true;
+ }
+ protected @java.lang.SuppressWarnings("all") boolean canEqual(final @javax.annotation.Nullable java.lang.Object other) {
+ return (other instanceof EqualsAndHashCodeWithNonNullByDefault);
+ }
+ public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() {
+ final int result = 1;
+ return result;
+ }
+} \ No newline at end of file
diff --git a/test/transform/resource/before/EqualsAndHashCodeWithNonNullByDefault.java b/test/transform/resource/before/EqualsAndHashCodeWithNonNullByDefault.java
new file mode 100644
index 00000000..f91bce3c
--- /dev/null
+++ b/test/transform/resource/before/EqualsAndHashCodeWithNonNullByDefault.java
@@ -0,0 +1,6 @@
+//CONF: lombok.addNullAnnotations = javax
+import javax.annotation.ParametersAreNonnullByDefault;
+@lombok.EqualsAndHashCode
+@ParametersAreNonnullByDefault
+class EqualsAndHashCodeWithNonNullByDefault {
+} \ No newline at end of file