diff options
Diffstat (limited to 'src/core/lombok/javac/handlers')
-rw-r--r-- | src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java | 25 | ||||
-rw-r--r-- | src/core/lombok/javac/handlers/JavacHandlerUtil.java | 13 |
2 files changed, 36 insertions, 2 deletions
diff --git a/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java b/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java index 2981bfa7..0d0369b9 100644 --- a/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java +++ b/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2019 The Project Lombok Authors. + * Copyright (C) 2009-2020 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 @@ -381,6 +381,20 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas Name otherName = typeNode.toName("other"); Name thisName = typeNode.toName("this"); + List<JCAnnotation> annsOnParamOnMethod = List.nil(); + + String nearest = scanForNearestAnnotation(typeNode, "org.eclipse.jdt.annotation.NonNullByDefault"); + if (nearest != null) { + JCAnnotation m = maker.Annotation(genTypeRef(typeNode, "org.eclipse.jdt.annotation.Nullable"), List.<JCExpression>nil()); + annsOnParamOnMethod = annsOnParamOnMethod.prepend(m); + } + + nearest = scanForNearestAnnotation(typeNode, "javax.annotation.ParametersAreNullableByDefault", "javax.annotation.ParametersAreNonnullByDefault"); + if ("javax.annotation.ParametersAreNonnullByDefault".equals(nearest)) { + JCAnnotation m = maker.Annotation(genTypeRef(typeNode, "javax.annotation.Nullable"), List.<JCExpression>nil()); + annsOnParamOnMethod = annsOnParamOnMethod.prepend(m); + } + JCAnnotation overrideAnnotation = maker.Annotation(genJavaLangTypeRef(typeNode, "Override"), List.<JCExpression>nil()); List<JCAnnotation> annsOnMethod = List.of(overrideAnnotation); CheckerFrameworkVersion checkerFramework = getCheckerFrameworkVersion(typeNode); @@ -388,7 +402,14 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas annsOnMethod = annsOnMethod.prepend(maker.Annotation(genTypeRef(typeNode, CheckerFrameworkVersion.NAME__SIDE_EFFECT_FREE), List.<JCExpression>nil())); } JCModifiers mods = maker.Modifiers(Flags.PUBLIC, annsOnMethod); - JCExpression objectType = genJavaLangTypeRef(typeNode, "Object"); + JCExpression objectType; + if (annsOnParamOnMethod.isEmpty()) { + objectType = genJavaLangTypeRef(typeNode, "Object"); + } else { + objectType = chainDots(typeNode, "java", "lang", "Object"); + objectType = maker.AnnotatedType(annsOnParamOnMethod, objectType); + } + JCExpression returnType = maker.TypeIdent(CTC_BOOLEAN); long finalFlag = JavacHandlerUtil.addFinalIfNeeded(0L, typeNode.getContext()); diff --git a/src/core/lombok/javac/handlers/JavacHandlerUtil.java b/src/core/lombok/javac/handlers/JavacHandlerUtil.java index b3a5cf90..9359b1ae 100644 --- a/src/core/lombok/javac/handlers/JavacHandlerUtil.java +++ b/src/core/lombok/javac/handlers/JavacHandlerUtil.java @@ -1400,6 +1400,19 @@ public class JavacHandlerUtil { return result.toList(); } + public static String scanForNearestAnnotation(JavacNode node, String... anns) { + while (node != null) { + for (JavacNode ann : node.down()) { + if (ann.getKind() != Kind.ANNOTATION) continue; + JCAnnotation a = (JCAnnotation) ann.get(); + for (String annToFind : anns) if (typeMatches(annToFind, node, a.annotationType)) return annToFind; + } + node = node.up(); + } + + return null; + } + public static boolean hasNonNullAnnotations(JavacNode node) { for (JavacNode child : node.down()) { if (child.getKind() == Kind.ANNOTATION) { |