From 22444b78e2b12680929acf1576b15a0717f267e2 Mon Sep 17 00:00:00 2001 From: JohnPaulTaylorII Date: Wed, 23 Feb 2022 13:29:58 -0500 Subject: Fixes #3120 --- .../lombok/eclipse/handlers/EclipseHandlerUtil.java | 7 +++++++ .../eclipse/handlers/HandleEqualsAndHashCode.java | 21 ++++++++++++--------- 2 files changed, 19 insertions(+), 9 deletions(-) (limited to 'src/core/lombok') 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 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 applied = new ArrayList(); + 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 statements = new ArrayList(); -- cgit