aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorReinier Zwitserloot <r.zwitserloot@projectlombok.org>2022-03-01 18:05:38 +0100
committerGitHub <noreply@github.com>2022-03-01 18:05:38 +0100
commit8c3ff7e9b08c4bf9c2b23cffb6042c31258e3ebb (patch)
tree56747d50cda77d9e96da9babfbd4cd1544766491 /src/core
parent560ded50127b12bd8168f8ae2bada47253f15bc8 (diff)
parentc67909e2039cdac449808464ff28a8e71a56b7a1 (diff)
downloadlombok-8c3ff7e9b08c4bf9c2b23cffb6042c31258e3ebb.tar.gz
lombok-8c3ff7e9b08c4bf9c2b23cffb6042c31258e3ebb.tar.bz2
lombok-8c3ff7e9b08c4bf9c2b23cffb6042c31258e3ebb.zip
Merge pull request #3121 from JohnPaulTaylorII/master
Fixes #3120
Diffstat (limited to 'src/core')
-rw-r--r--src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java7
-rwxr-xr-xsrc/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java21
2 files changed, 19 insertions, 9 deletions
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/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>();