From 79bfcc4f7ae4bcd61f7f942bfefb940c77927b71 Mon Sep 17 00:00:00 2001 From: Werner Dietl Date: Mon, 27 Aug 2018 18:36:13 -0400 Subject: Add configuration key, handle whereever NULLABLE is handled, support Eclipse. --- src/core/lombok/javac/handlers/HandleWither.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/core/lombok/javac/handlers/HandleWither.java') diff --git a/src/core/lombok/javac/handlers/HandleWither.java b/src/core/lombok/javac/handlers/HandleWither.java index 87f3c16a..e6fc2d02 100644 --- a/src/core/lombok/javac/handlers/HandleWither.java +++ b/src/core/lombok/javac/handlers/HandleWither.java @@ -224,6 +224,7 @@ public class HandleWither extends JavacAnnotationHandler { List nonNulls = findAnnotations(field, NON_NULL_PATTERN); List nullables = findAnnotations(field, NULLABLE_PATTERN); + List copyAnnotations = findExactAnnotations(field, copyAnnotationNames(field.getAst())); Name methodName = field.toName(witherName); @@ -231,7 +232,7 @@ public class HandleWither extends JavacAnnotationHandler { JCBlock methodBody = null; long flags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, field.getContext()); - List annsOnParam = copyAnnotations(onParam).appendList(nonNulls).appendList(nullables); + List annsOnParam = copyAnnotations(onParam).appendList(nonNulls).appendList(nullables).appendList(copyAnnotations); JCVariableDecl param = maker.VarDef(maker.Modifiers(flags, annsOnParam), fieldDecl.name, fieldDecl.vartype, null); -- cgit From cc8370ab2d7b3ca15023364c99e53735e62e13d7 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Tue, 4 Sep 2018 01:47:59 +0200 Subject: code review and fixes for the ‘copyable annotations’ setting concept. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/lombok/ConfigurationKeys.java | 6 +-- src/core/lombok/core/handlers/HandlerUtil.java | 6 +-- .../eclipse/handlers/EclipseHandlerUtil.java | 18 ++++++++ .../lombok/eclipse/handlers/HandleBuilder.java | 13 ++++-- .../lombok/eclipse/handlers/HandleConstructor.java | 2 +- src/core/lombok/eclipse/handlers/HandleGetter.java | 2 +- src/core/lombok/eclipse/handlers/HandleSetter.java | 4 +- src/core/lombok/eclipse/handlers/HandleWither.java | 4 +- src/core/lombok/javac/handlers/HandleBuilder.java | 15 ++++--- .../lombok/javac/handlers/HandleConstructor.java | 4 +- src/core/lombok/javac/handlers/HandleGetter.java | 4 +- src/core/lombok/javac/handlers/HandleSetter.java | 4 +- src/core/lombok/javac/handlers/HandleWither.java | 4 +- .../lombok/javac/handlers/JavacHandlerUtil.java | 8 ++-- src/utils/lombok/eclipse/Eclipse.java | 22 +--------- .../resource/after-delombok/BuilderTypeAnnos.java | 45 +++++++++++++++++++ .../after-delombok/BuilderTypeAnnosCopy.java | 51 ---------------------- .../after-delombok/BuilderTypeAnnosNoCopy.java | 51 ---------------------- .../after-delombok/ConstructorsTypeAnnos.java | 18 ++++++++ .../after-delombok/ConstructorsTypeAnnosCopy.java | 17 -------- .../ConstructorsTypeAnnosNoCopy.java | 17 -------- .../resource/after-delombok/GetterTypeAnnos.java | 19 ++++++++ .../after-delombok/GetterTypeAnnosCopy.java | 18 -------- .../after-delombok/GetterTypeAnnosNoCopy.java | 17 -------- .../resource/after-delombok/SetterTypeAnnos.java | 18 ++++++++ .../after-delombok/SetterTypeAnnosCopy.java | 17 -------- .../after-delombok/SetterTypeAnnosNoCopy.java | 17 -------- .../resource/after-delombok/WitherTypeAnnos.java | 21 +++++++++ .../after-delombok/WitherTypeAnnosCopy.java | 21 --------- .../after-delombok/WitherTypeAnnosNoCopy.java | 21 --------- .../resource/after-ecj/BuilderTypeAnnos.java | 33 ++++++++++++++ .../resource/after-ecj/BuilderTypeAnnosCopy.java | 31 ------------- .../resource/after-ecj/BuilderTypeAnnosNoCopy.java | 31 ------------- .../resource/after-ecj/ConstructorsTypeAnnos.java | 14 ++++++ .../after-ecj/ConstructorsTypeAnnosCopy.java | 12 ----- .../after-ecj/ConstructorsTypeAnnosNoCopy.java | 12 ----- .../resource/after-ecj/GetterTypeAnnos.java | 17 ++++++++ .../resource/after-ecj/GetterTypeAnnosCopy.java | 15 ------- .../resource/after-ecj/GetterTypeAnnosNoCopy.java | 15 ------- .../resource/after-ecj/SetterTypeAnnos.java | 17 ++++++++ .../resource/after-ecj/SetterTypeAnnosCopy.java | 15 ------- .../resource/after-ecj/SetterTypeAnnosNoCopy.java | 15 ------- .../resource/after-ecj/WitherTypeAnnos.java | 18 ++++++++ .../resource/after-ecj/WitherTypeAnnosCopy.java | 16 ------- .../resource/after-ecj/WitherTypeAnnosNoCopy.java | 16 ------- .../resource/before/BuilderTypeAnnos.java | 14 ++++++ .../resource/before/BuilderTypeAnnosCopy.java | 14 ------ .../resource/before/BuilderTypeAnnosNoCopy.java | 12 ----- .../resource/before/ConstructorsTypeAnnos.java | 14 ++++++ .../resource/before/ConstructorsTypeAnnosCopy.java | 14 ------ .../before/ConstructorsTypeAnnosNoCopy.java | 12 ----- .../transform/resource/before/GetterTypeAnnos.java | 15 +++++++ .../resource/before/GetterTypeAnnosCopy.java | 16 ------- .../resource/before/GetterTypeAnnosNoCopy.java | 14 ------ .../transform/resource/before/SetterTypeAnnos.java | 15 +++++++ .../resource/before/SetterTypeAnnosCopy.java | 16 ------- .../resource/before/SetterTypeAnnosNoCopy.java | 14 ------ .../transform/resource/before/WitherTypeAnnos.java | 18 ++++++++ .../resource/before/WitherTypeAnnosCopy.java | 19 -------- .../resource/before/WitherTypeAnnosNoCopy.java | 17 -------- 60 files changed, 358 insertions(+), 627 deletions(-) create mode 100644 test/transform/resource/after-delombok/BuilderTypeAnnos.java delete mode 100644 test/transform/resource/after-delombok/BuilderTypeAnnosCopy.java delete mode 100644 test/transform/resource/after-delombok/BuilderTypeAnnosNoCopy.java create mode 100644 test/transform/resource/after-delombok/ConstructorsTypeAnnos.java delete mode 100644 test/transform/resource/after-delombok/ConstructorsTypeAnnosCopy.java delete mode 100644 test/transform/resource/after-delombok/ConstructorsTypeAnnosNoCopy.java create mode 100644 test/transform/resource/after-delombok/GetterTypeAnnos.java delete mode 100644 test/transform/resource/after-delombok/GetterTypeAnnosCopy.java delete mode 100644 test/transform/resource/after-delombok/GetterTypeAnnosNoCopy.java create mode 100644 test/transform/resource/after-delombok/SetterTypeAnnos.java delete mode 100644 test/transform/resource/after-delombok/SetterTypeAnnosCopy.java delete mode 100644 test/transform/resource/after-delombok/SetterTypeAnnosNoCopy.java create mode 100644 test/transform/resource/after-delombok/WitherTypeAnnos.java delete mode 100644 test/transform/resource/after-delombok/WitherTypeAnnosCopy.java delete mode 100644 test/transform/resource/after-delombok/WitherTypeAnnosNoCopy.java create mode 100644 test/transform/resource/after-ecj/BuilderTypeAnnos.java delete mode 100644 test/transform/resource/after-ecj/BuilderTypeAnnosCopy.java delete mode 100644 test/transform/resource/after-ecj/BuilderTypeAnnosNoCopy.java create mode 100644 test/transform/resource/after-ecj/ConstructorsTypeAnnos.java delete mode 100644 test/transform/resource/after-ecj/ConstructorsTypeAnnosCopy.java delete mode 100644 test/transform/resource/after-ecj/ConstructorsTypeAnnosNoCopy.java create mode 100644 test/transform/resource/after-ecj/GetterTypeAnnos.java delete mode 100644 test/transform/resource/after-ecj/GetterTypeAnnosCopy.java delete mode 100644 test/transform/resource/after-ecj/GetterTypeAnnosNoCopy.java create mode 100644 test/transform/resource/after-ecj/SetterTypeAnnos.java delete mode 100644 test/transform/resource/after-ecj/SetterTypeAnnosCopy.java delete mode 100644 test/transform/resource/after-ecj/SetterTypeAnnosNoCopy.java create mode 100644 test/transform/resource/after-ecj/WitherTypeAnnos.java delete mode 100644 test/transform/resource/after-ecj/WitherTypeAnnosCopy.java delete mode 100644 test/transform/resource/after-ecj/WitherTypeAnnosNoCopy.java create mode 100644 test/transform/resource/before/BuilderTypeAnnos.java delete mode 100644 test/transform/resource/before/BuilderTypeAnnosCopy.java delete mode 100644 test/transform/resource/before/BuilderTypeAnnosNoCopy.java create mode 100644 test/transform/resource/before/ConstructorsTypeAnnos.java delete mode 100644 test/transform/resource/before/ConstructorsTypeAnnosCopy.java delete mode 100644 test/transform/resource/before/ConstructorsTypeAnnosNoCopy.java create mode 100644 test/transform/resource/before/GetterTypeAnnos.java delete mode 100644 test/transform/resource/before/GetterTypeAnnosCopy.java delete mode 100644 test/transform/resource/before/GetterTypeAnnosNoCopy.java create mode 100644 test/transform/resource/before/SetterTypeAnnos.java delete mode 100644 test/transform/resource/before/SetterTypeAnnosCopy.java delete mode 100644 test/transform/resource/before/SetterTypeAnnosNoCopy.java create mode 100644 test/transform/resource/before/WitherTypeAnnos.java delete mode 100644 test/transform/resource/before/WitherTypeAnnosCopy.java delete mode 100644 test/transform/resource/before/WitherTypeAnnosNoCopy.java (limited to 'src/core/lombok/javac/handlers/HandleWither.java') diff --git a/src/core/lombok/ConfigurationKeys.java b/src/core/lombok/ConfigurationKeys.java index beb0d1e0..89748f60 100644 --- a/src/core/lombok/ConfigurationKeys.java +++ b/src/core/lombok/ConfigurationKeys.java @@ -565,10 +565,10 @@ public class ConfigurationKeys { public static final ConfigurationKey STOP_BUBBLING = new ConfigurationKey("config.stopBubbling", "Tell the configuration system it should stop looking for other configuration files (default: false).") {}; /** - * lombok configuration: {@code lombok.copyAnnotations} += <String: fully-qualified annotation class name>. + * lombok configuration: {@code lombok.copyableAnnotations} += <String: fully-qualified annotation class name>. * - * Copy these annotations to getters, setters, etc. + * Copy these annotations to getters, setters, withers, builder-setters, etc. */ - public static final ConfigurationKey> COPY_ANNOTATIONS = new ConfigurationKey>("lombok.copyAnnotations", "Copy these annotations to getters, setters, etc.") {}; + public static final ConfigurationKey> COPYABLE_ANNOTATIONS = new ConfigurationKey>("lombok.copyableAnnotations", "Copy these annotations to getters, setters, withers, builder-setters, etc.") {}; } diff --git a/src/core/lombok/core/handlers/HandlerUtil.java b/src/core/lombok/core/handlers/HandlerUtil.java index 48c48c20..1694e305 100644 --- a/src/core/lombok/core/handlers/HandlerUtil.java +++ b/src/core/lombok/core/handlers/HandlerUtil.java @@ -230,9 +230,9 @@ public class HandlerUtil { public static final String DEFAULT_EXCEPTION_FOR_NON_NULL = "java.lang.NullPointerException"; - /** Returns the configuration value for ConfigurationKeys.COPY_ANNOTATIONS. */ - public static List copyAnnotationNames(AST ast) { - return ast.readConfiguration(ConfigurationKeys.COPY_ANNOTATIONS); + /** Returns the configuration value for ConfigurationKeys.COPYABLE_ANNOTATIONS. */ + public static List getCopyableAnnotationNames(AST ast) { + return ast.readConfiguration(ConfigurationKeys.COPYABLE_ANNOTATIONS); } /** diff --git a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java index 1e29764a..e7a58de3 100644 --- a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java +++ b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java @@ -672,6 +672,24 @@ public class EclipseHandlerUtil { } } + private static final Annotation[] EMPTY_ANNOTATIONS_ARRAY = new Annotation[0]; + + /** + * Searches the given field node for annotations and returns each one that matches the provided list of names. + */ + public static Annotation[] findExactAnnotations(AbstractVariableDeclaration field, List names) { + List result = new ArrayList(); + if (field.annotations == null) return EMPTY_ANNOTATIONS_ARRAY; + for (Annotation annotation : field.annotations) { + TypeReference typeRef = annotation.type; + if (typeRef != null && typeRef.getTypeName() != null) { + String annoName = toQualifiedName(typeRef.getTypeName()); + if (names.contains(annoName)) result.add(annotation); + } + } + return result.toArray(EMPTY_ANNOTATIONS_ARRAY); + } + /** * Checks if the provided annotation type is likely to be the intended type for the given annotation node. * diff --git a/src/core/lombok/eclipse/handlers/HandleBuilder.java b/src/core/lombok/eclipse/handlers/HandleBuilder.java index 3e373a00..f05896ab 100644 --- a/src/core/lombok/eclipse/handlers/HandleBuilder.java +++ b/src/core/lombok/eclipse/handlers/HandleBuilder.java @@ -202,8 +202,8 @@ public class HandleBuilder extends EclipseAnnotationHandler { Annotation[] nonNulls = findAnnotations(fd, NON_NULL_PATTERN); Annotation[] nullables = findAnnotations(fd, NULLABLE_PATTERN); - Annotation[] copyAnnotations = findExactAnnotations(fd, copyAnnotationNames(fieldNode.getAst())); - + Annotation[] copyAnnotations = findExactAnnotations(fd, getCopyableAnnotationNames(fieldNode.getAst())); + BuilderFieldData bfd = new BuilderFieldData(); bfd.rawName = fieldNode.getName().toCharArray(); bfd.name = removePrefixFromField(fieldNode); @@ -380,9 +380,14 @@ public class HandleBuilder extends EclipseAnnotationHandler { if (param.getKind() != Kind.ARGUMENT) continue; BuilderFieldData bfd = new BuilderFieldData(); Argument arg = (Argument) param.get(); + + Annotation[] nonNulls = findAnnotations(arg, NON_NULL_PATTERN); + Annotation[] nullables = findAnnotations(arg, NULLABLE_PATTERN); + Annotation[] copyAnnotations = findExactAnnotations(arg, getCopyableAnnotationNames(param.getAst())); + bfd.rawName = arg.name; bfd.name = arg.name; - bfd.annotations = arg.annotations; + bfd.annotations = copyAnnotations(arg, nonNulls, nullables, copyAnnotations); bfd.type = arg.type; bfd.singularData = getSingularData(param, ast); bfd.originalFieldNode = param; @@ -774,7 +779,7 @@ public class HandleBuilder extends EclipseAnnotationHandler { String setterName = fluent ? fieldNode.getName() : HandlerUtil.buildAccessorName("set", fieldNode.getName()); MethodDeclaration setter = HandleSetter.createSetter(td, deprecate, fieldNode, setterName, nameOfSetFlag, chain, ClassFileConstants.AccPublic, - sourceNode, Collections.emptyList(), annotations != null ? Arrays.asList(annotations) : Collections.emptyList()); + sourceNode, Collections.emptyList(), annotations != null ? Arrays.asList(copyAnnotations(sourceNode.get(), annotations)) : Collections.emptyList()); injectMethod(builderType, setter); } diff --git a/src/core/lombok/eclipse/handlers/HandleConstructor.java b/src/core/lombok/eclipse/handlers/HandleConstructor.java index cb9c2b4b..3d947a73 100644 --- a/src/core/lombok/eclipse/handlers/HandleConstructor.java +++ b/src/core/lombok/eclipse/handlers/HandleConstructor.java @@ -405,7 +405,7 @@ public class HandleConstructor { Argument parameter = new Argument(fieldName, fieldPos, copyType(field.type, source), Modifier.FINAL); Annotation[] nonNulls = findAnnotations(field, NON_NULL_PATTERN); Annotation[] nullables = findAnnotations(field, NULLABLE_PATTERN); - Annotation[] copyAnnotations = findExactAnnotations(field, copyAnnotationNames(fieldNode.getAst())); + Annotation[] copyAnnotations = findExactAnnotations(field, getCopyableAnnotationNames(fieldNode.getAst())); if (nonNulls.length != 0) { Statement nullCheck = generateNullCheck(parameter, sourceNode); if (nullCheck != null) nullChecks.add(nullCheck); diff --git a/src/core/lombok/eclipse/handlers/HandleGetter.java b/src/core/lombok/eclipse/handlers/HandleGetter.java index 45ddb2cc..58af8c1e 100644 --- a/src/core/lombok/eclipse/handlers/HandleGetter.java +++ b/src/core/lombok/eclipse/handlers/HandleGetter.java @@ -274,7 +274,7 @@ public class HandleGetter extends EclipseAnnotationHandler { onMethod.toArray(new Annotation[0]), findAnnotations(field, NON_NULL_PATTERN), findAnnotations(field, NULLABLE_PATTERN), - findExactAnnotations(field, copyAnnotationNames(fieldNode.getAst())), + findExactAnnotations(field, getCopyableAnnotationNames(fieldNode.getAst())), findDelegatesAndMarkAsHandled(fieldNode), deprecated); } diff --git a/src/core/lombok/eclipse/handlers/HandleSetter.java b/src/core/lombok/eclipse/handlers/HandleSetter.java index bd34b313..ca81fef7 100644 --- a/src/core/lombok/eclipse/handlers/HandleSetter.java +++ b/src/core/lombok/eclipse/handlers/HandleSetter.java @@ -238,7 +238,7 @@ public class HandleSetter extends EclipseAnnotationHandler { Annotation[] nonNulls = findAnnotations(field, NON_NULL_PATTERN); Annotation[] nullables = findAnnotations(field, NULLABLE_PATTERN); - Annotation[] copyAnnotations = findExactAnnotations(field, copyAnnotationNames(fieldNode.getAst())); + Annotation[] copyableAnnotations = findExactAnnotations(field, getCopyableAnnotationNames(fieldNode.getAst())); List statements = new ArrayList(5); if (nonNulls.length == 0) { statements.add(assignment); @@ -256,7 +256,7 @@ public class HandleSetter extends EclipseAnnotationHandler { statements.add(returnStatement); } method.statements = statements.toArray(new Statement[0]); - param.annotations = copyAnnotations(source, nonNulls, nullables, copyAnnotations, onParam.toArray(new Annotation[0])); + param.annotations = copyAnnotations(source, nonNulls, nullables, copyableAnnotations, onParam.toArray(new Annotation[0])); method.traverse(new SetGeneratedByVisitor(source), parent.scope); return method; diff --git a/src/core/lombok/eclipse/handlers/HandleWither.java b/src/core/lombok/eclipse/handlers/HandleWither.java index e9831ce1..11032e9c 100644 --- a/src/core/lombok/eclipse/handlers/HandleWither.java +++ b/src/core/lombok/eclipse/handlers/HandleWither.java @@ -242,7 +242,7 @@ public class HandleWither extends EclipseAnnotationHandler { Annotation[] nonNulls = findAnnotations(field, NON_NULL_PATTERN); Annotation[] nullables = findAnnotations(field, NULLABLE_PATTERN); - Annotation[] copyAnnotations = findExactAnnotations(field, copyAnnotationNames(fieldNode.getAst())); + Annotation[] copyableAnnotations = findExactAnnotations(field, getCopyableAnnotationNames(fieldNode.getAst())); if (!makeAbstract) { List args = new ArrayList(); @@ -286,7 +286,7 @@ public class HandleWither extends EclipseAnnotationHandler { method.statements = statements.toArray(new Statement[0]); } - param.annotations = copyAnnotations(source, nonNulls, nullables, copyAnnotations, onParam.toArray(new Annotation[0])); + param.annotations = copyAnnotations(source, nonNulls, nullables, copyableAnnotations, onParam.toArray(new Annotation[0])); method.traverse(new SetGeneratedByVisitor(source), parent.scope); return method; diff --git a/src/core/lombok/javac/handlers/HandleBuilder.java b/src/core/lombok/javac/handlers/HandleBuilder.java index 75bfb01c..7577eeb2 100644 --- a/src/core/lombok/javac/handlers/HandleBuilder.java +++ b/src/core/lombok/javac/handlers/HandleBuilder.java @@ -149,15 +149,15 @@ public class HandleBuilder extends JavacAnnotationHandler { JCVariableDecl fd = (JCVariableDecl) fieldNode.get(); JavacNode isDefault = findAnnotation(Builder.Default.class, fieldNode, false); boolean isFinal = (fd.mods.flags & Flags.FINAL) != 0 || (valuePresent && !hasAnnotation(NonFinal.class, fieldNode)); - + List nonNulls = findAnnotations(fieldNode, NON_NULL_PATTERN); List nullables = findAnnotations(fieldNode, NULLABLE_PATTERN); - List copyAnnotations = findExactAnnotations(fieldNode, copyAnnotationNames(fieldNode.getAst())); - + List copyableAnnotations = findExactAnnotations(fieldNode, getCopyableAnnotationNames(fieldNode.getAst())); + BuilderFieldData bfd = new BuilderFieldData(); bfd.rawName = fd.name; bfd.name = removePrefixFromField(fieldNode); - bfd.annotations = nonNulls.appendList(nullables).appendList(copyAnnotations); + bfd.annotations = nonNulls.appendList(nullables).appendList(copyableAnnotations); bfd.type = fd.vartype; bfd.singularData = getSingularData(fieldNode); bfd.originalFieldNode = fieldNode; @@ -333,10 +333,15 @@ public class HandleBuilder extends JavacAnnotationHandler { for (JavacNode param : fillParametersFrom.down()) { if (param.getKind() != Kind.ARGUMENT) continue; BuilderFieldData bfd = new BuilderFieldData(); + + List nonNulls = findAnnotations(param, NON_NULL_PATTERN); + List nullables = findAnnotations(param, NULLABLE_PATTERN); + List copyableAnnotations = findExactAnnotations(param, getCopyableAnnotationNames(param.getAst())); + JCVariableDecl raw = (JCVariableDecl) param.get(); bfd.name = raw.name; bfd.rawName = raw.name; - bfd.annotations = raw.mods.annotations; + bfd.annotations = nonNulls.appendList(nullables).appendList(copyableAnnotations); bfd.type = raw.vartype; bfd.singularData = getSingularData(param); bfd.originalFieldNode = param; diff --git a/src/core/lombok/javac/handlers/HandleConstructor.java b/src/core/lombok/javac/handlers/HandleConstructor.java index b0fa3d29..1e45d73f 100644 --- a/src/core/lombok/javac/handlers/HandleConstructor.java +++ b/src/core/lombok/javac/handlers/HandleConstructor.java @@ -331,9 +331,9 @@ public class HandleConstructor { Name rawName = field.name; List nonNulls = findAnnotations(fieldNode, NON_NULL_PATTERN); List nullables = findAnnotations(fieldNode, NULLABLE_PATTERN); - List copyAnnotations = findExactAnnotations(fieldNode, copyAnnotationNames(fieldNode.getAst())); + List copyableAnnotations = findExactAnnotations(fieldNode, getCopyableAnnotationNames(fieldNode.getAst())); long flags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, typeNode.getContext()); - JCVariableDecl param = maker.VarDef(maker.Modifiers(flags, nonNulls.appendList(nullables).appendList(copyAnnotations)), fieldName, field.vartype, null); + JCVariableDecl param = maker.VarDef(maker.Modifiers(flags, nonNulls.appendList(nullables).appendList(copyableAnnotations)), fieldName, field.vartype, null); params.append(param); if (!nonNulls.isEmpty()) { JCStatement nullCheck = generateNullCheck(maker, fieldNode, param, source); diff --git a/src/core/lombok/javac/handlers/HandleGetter.java b/src/core/lombok/javac/handlers/HandleGetter.java index 6e4b2685..04b300a8 100644 --- a/src/core/lombok/javac/handlers/HandleGetter.java +++ b/src/core/lombok/javac/handlers/HandleGetter.java @@ -245,11 +245,11 @@ public class HandleGetter extends JavacAnnotationHandler { List nonNulls = findAnnotations(field, NON_NULL_PATTERN); List nullables = findAnnotations(field, NULLABLE_PATTERN); - List copyAnnotations = findExactAnnotations(field, copyAnnotationNames(field.getAst())); + List copyableAnnotations = findExactAnnotations(field, getCopyableAnnotationNames(field.getAst())); List delegates = findDelegatesAndRemoveFromField(field); - List annsOnMethod = copyAnnotations(onMethod).appendList(nonNulls).appendList(nullables).appendList(copyAnnotations); + List annsOnMethod = copyAnnotations(onMethod).appendList(nonNulls).appendList(nullables).appendList(copyableAnnotations); if (isFieldDeprecated(field)) { annsOnMethod = annsOnMethod.prepend(treeMaker.Annotation(genJavaLangTypeRef(field, "Deprecated"), List.nil())); } diff --git a/src/core/lombok/javac/handlers/HandleSetter.java b/src/core/lombok/javac/handlers/HandleSetter.java index 631ea193..e5e9481d 100644 --- a/src/core/lombok/javac/handlers/HandleSetter.java +++ b/src/core/lombok/javac/handlers/HandleSetter.java @@ -228,10 +228,10 @@ public class HandleSetter extends JavacAnnotationHandler { ListBuffer statements = new ListBuffer(); List nonNulls = findAnnotations(field, NON_NULL_PATTERN); List nullables = findAnnotations(field, NULLABLE_PATTERN); - List copyAnnotations = findExactAnnotations(field, copyAnnotationNames(field.getAst())); + List copyableAnnotations = findExactAnnotations(field, getCopyableAnnotationNames(field.getAst())); Name methodName = field.toName(setterName); - List annsOnParam = copyAnnotations(onParam).appendList(nonNulls).appendList(nullables).appendList(copyAnnotations); + List annsOnParam = copyAnnotations(onParam).appendList(nonNulls).appendList(nullables).appendList(copyableAnnotations); long flags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, field.getContext()); JCVariableDecl param = treeMaker.VarDef(treeMaker.Modifiers(flags, annsOnParam), fieldDecl.name, fieldDecl.vartype, null); diff --git a/src/core/lombok/javac/handlers/HandleWither.java b/src/core/lombok/javac/handlers/HandleWither.java index e6fc2d02..b0e32d61 100644 --- a/src/core/lombok/javac/handlers/HandleWither.java +++ b/src/core/lombok/javac/handlers/HandleWither.java @@ -224,7 +224,7 @@ public class HandleWither extends JavacAnnotationHandler { List nonNulls = findAnnotations(field, NON_NULL_PATTERN); List nullables = findAnnotations(field, NULLABLE_PATTERN); - List copyAnnotations = findExactAnnotations(field, copyAnnotationNames(field.getAst())); + List copyableAnnotations = findExactAnnotations(field, getCopyableAnnotationNames(field.getAst())); Name methodName = field.toName(witherName); @@ -232,7 +232,7 @@ public class HandleWither extends JavacAnnotationHandler { JCBlock methodBody = null; long flags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, field.getContext()); - List annsOnParam = copyAnnotations(onParam).appendList(nonNulls).appendList(nullables).appendList(copyAnnotations); + List annsOnParam = copyAnnotations(onParam).appendList(nonNulls).appendList(nullables).appendList(copyableAnnotations); JCVariableDecl param = maker.VarDef(maker.Modifiers(flags, annsOnParam), fieldDecl.name, fieldDecl.vartype, null); diff --git a/src/core/lombok/javac/handlers/JavacHandlerUtil.java b/src/core/lombok/javac/handlers/JavacHandlerUtil.java index cb729183..1cc28072 100644 --- a/src/core/lombok/javac/handlers/JavacHandlerUtil.java +++ b/src/core/lombok/javac/handlers/JavacHandlerUtil.java @@ -1343,15 +1343,13 @@ public class JavacHandlerUtil { for (JavacNode child : fieldNode.down()) { if (child.getKind() == Kind.ANNOTATION) { JCAnnotation annotation = (JCAnnotation) child.get(); - String annoname = annotation.annotationType.toString(); - if (names.contains(annoname)) { - result.append(annotation); - } + String annoName = annotation.annotationType.toString(); + if (names.contains(annoName)) result.append(annotation); } } return result.toList(); } - + /** * Generates a new statement that checks if the given variable is null, and if so, throws a configured exception with the * variable name as message. diff --git a/src/utils/lombok/eclipse/Eclipse.java b/src/utils/lombok/eclipse/Eclipse.java index 42adeeac..5b3c453e 100644 --- a/src/utils/lombok/eclipse/Eclipse.java +++ b/src/utils/lombok/eclipse/Eclipse.java @@ -31,11 +31,11 @@ import lombok.core.ClassLiteral; import lombok.core.FieldSelect; import org.eclipse.jdt.internal.compiler.ast.ASTNode; import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration; +import org.eclipse.jdt.internal.compiler.ast.AbstractVariableDeclaration; import org.eclipse.jdt.internal.compiler.ast.Annotation; import org.eclipse.jdt.internal.compiler.ast.ClassLiteralAccess; import org.eclipse.jdt.internal.compiler.ast.Clinit; import org.eclipse.jdt.internal.compiler.ast.Expression; -import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration; import org.eclipse.jdt.internal.compiler.ast.Literal; import org.eclipse.jdt.internal.compiler.ast.QualifiedNameReference; import org.eclipse.jdt.internal.compiler.ast.SingleNameReference; @@ -139,7 +139,7 @@ public class Eclipse { * * Only the simple name is checked - the package and any containing class are ignored. */ - public static Annotation[] findAnnotations(FieldDeclaration field, Pattern namePattern) { + public static Annotation[] findAnnotations(AbstractVariableDeclaration field, Pattern namePattern) { List result = new ArrayList(); if (field.annotations == null) return EMPTY_ANNOTATIONS_ARRAY; for (Annotation annotation : field.annotations) { @@ -155,24 +155,6 @@ public class Eclipse { return result.toArray(EMPTY_ANNOTATIONS_ARRAY); } - /** - * Searches the given field node for annotations and returns each one that matches the provided list of names. - */ - public static Annotation[] findExactAnnotations(FieldDeclaration field, List names) { - List result = new ArrayList(); - if (field.annotations == null) return EMPTY_ANNOTATIONS_ARRAY; - for (Annotation annotation : field.annotations) { - TypeReference typeRef = annotation.type; - if (typeRef != null && typeRef.getTypeName() != null) { - String annoname = toQualifiedName(typeRef.getTypeName()); - if (names.contains(annoname)) { - result.add(annotation); - } - } - } - return result.toArray(EMPTY_ANNOTATIONS_ARRAY); - } - /** Matches any of the 8 primitive names, such as {@code boolean}. */ private static final Pattern PRIMITIVE_TYPE_NAME_PATTERN = Pattern.compile( "^(boolean|byte|short|int|long|float|double|char)$"); diff --git a/test/transform/resource/after-delombok/BuilderTypeAnnos.java b/test/transform/resource/after-delombok/BuilderTypeAnnos.java new file mode 100644 index 00000000..8a31762a --- /dev/null +++ b/test/transform/resource/after-delombok/BuilderTypeAnnos.java @@ -0,0 +1,45 @@ +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; +import java.util.List; +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER}) +@interface TA { +} +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER}) +@interface TB { +} +class BuilderTypeAnnos { + @TA + @TB + private List foo; + @java.lang.SuppressWarnings("all") + BuilderTypeAnnos(@TA final List foo) { + this.foo = foo; + } + @java.lang.SuppressWarnings("all") + public static class BuilderTypeAnnosBuilder { + @java.lang.SuppressWarnings("all") + private List foo; + @java.lang.SuppressWarnings("all") + BuilderTypeAnnosBuilder() { + } + @java.lang.SuppressWarnings("all") + public BuilderTypeAnnosBuilder foo(@TA final List foo) { + this.foo = foo; + return this; + } + @java.lang.SuppressWarnings("all") + public BuilderTypeAnnos build() { + return new BuilderTypeAnnos(foo); + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public java.lang.String toString() { + return "BuilderTypeAnnos.BuilderTypeAnnosBuilder(foo=" + this.foo + ")"; + } + } + @java.lang.SuppressWarnings("all") + public static BuilderTypeAnnosBuilder builder() { + return new BuilderTypeAnnosBuilder(); + } +} + diff --git a/test/transform/resource/after-delombok/BuilderTypeAnnosCopy.java b/test/transform/resource/after-delombok/BuilderTypeAnnosCopy.java deleted file mode 100644 index 8b0ea537..00000000 --- a/test/transform/resource/after-delombok/BuilderTypeAnnosCopy.java +++ /dev/null @@ -1,51 +0,0 @@ -import java.lang.annotation.ElementType; -import java.lang.annotation.Target; -import java.util.List; - -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@interface TA { -} - -class BuilderTypeAnnos { - @TA - private List<@TA String> foo; - - @java.lang.SuppressWarnings("all") - BuilderTypeAnnos(@TA final List<@TA String> foo) { - this.foo = foo; - } - - - @java.lang.SuppressWarnings("all") - public static class BuilderTypeAnnosBuilder { - @java.lang.SuppressWarnings("all") - private List<@TA String> foo; - - @java.lang.SuppressWarnings("all") - BuilderTypeAnnosBuilder() { - } - - @java.lang.SuppressWarnings("all") - public BuilderTypeAnnosBuilder foo(@TA final List<@TA String> foo) { - this.foo = foo; - return this; - } - - @java.lang.SuppressWarnings("all") - public BuilderTypeAnnos build() { - return new BuilderTypeAnnos(foo); - } - - @java.lang.Override - @java.lang.SuppressWarnings("all") - public java.lang.String toString() { - return "BuilderTypeAnnos.BuilderTypeAnnosBuilder(foo=" + this.foo + ")"; - } - } - - @java.lang.SuppressWarnings("all") - public static BuilderTypeAnnosBuilder builder() { - return new BuilderTypeAnnosBuilder(); - } -} - diff --git a/test/transform/resource/after-delombok/BuilderTypeAnnosNoCopy.java b/test/transform/resource/after-delombok/BuilderTypeAnnosNoCopy.java deleted file mode 100644 index b08e03a3..00000000 --- a/test/transform/resource/after-delombok/BuilderTypeAnnosNoCopy.java +++ /dev/null @@ -1,51 +0,0 @@ -import java.lang.annotation.ElementType; -import java.lang.annotation.Target; -import java.util.List; - -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@interface TA { -} - -class BuilderTypeAnnos { - @TA - private List<@TA String> foo; - - @java.lang.SuppressWarnings("all") - BuilderTypeAnnos(final List<@TA String> foo) { - this.foo = foo; - } - - - @java.lang.SuppressWarnings("all") - public static class BuilderTypeAnnosBuilder { - @java.lang.SuppressWarnings("all") - private List<@TA String> foo; - - @java.lang.SuppressWarnings("all") - BuilderTypeAnnosBuilder() { - } - - @java.lang.SuppressWarnings("all") - public BuilderTypeAnnosBuilder foo(final List<@TA String> foo) { - this.foo = foo; - return this; - } - - @java.lang.SuppressWarnings("all") - public BuilderTypeAnnos build() { - return new BuilderTypeAnnos(foo); - } - - @java.lang.Override - @java.lang.SuppressWarnings("all") - public java.lang.String toString() { - return "BuilderTypeAnnos.BuilderTypeAnnosBuilder(foo=" + this.foo + ")"; - } - } - - @java.lang.SuppressWarnings("all") - public static BuilderTypeAnnosBuilder builder() { - return new BuilderTypeAnnosBuilder(); - } -} - diff --git a/test/transform/resource/after-delombok/ConstructorsTypeAnnos.java b/test/transform/resource/after-delombok/ConstructorsTypeAnnos.java new file mode 100644 index 00000000..2d59681c --- /dev/null +++ b/test/transform/resource/after-delombok/ConstructorsTypeAnnos.java @@ -0,0 +1,18 @@ +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; +import java.util.List; +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER}) +@interface TA { +} +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER}) +@interface TB { +} +class ConstructorsTypeAnnos { + @TA + @TB + List foo; + @java.lang.SuppressWarnings("all") + public ConstructorsTypeAnnos(@TA final List foo) { + this.foo = foo; + } +} diff --git a/test/transform/resource/after-delombok/ConstructorsTypeAnnosCopy.java b/test/transform/resource/after-delombok/ConstructorsTypeAnnosCopy.java deleted file mode 100644 index 28d6ed09..00000000 --- a/test/transform/resource/after-delombok/ConstructorsTypeAnnosCopy.java +++ /dev/null @@ -1,17 +0,0 @@ -import java.lang.annotation.ElementType; -import java.lang.annotation.Target; -import java.util.List; - -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@interface TA { -} - -class ConstructorsTypeAnnos { - @TA - List<@TA String> foo; - - @java.lang.SuppressWarnings("all") - public ConstructorsTypeAnnos(@TA final List<@TA String> foo) { - this.foo = foo; - } -} diff --git a/test/transform/resource/after-delombok/ConstructorsTypeAnnosNoCopy.java b/test/transform/resource/after-delombok/ConstructorsTypeAnnosNoCopy.java deleted file mode 100644 index e27131ef..00000000 --- a/test/transform/resource/after-delombok/ConstructorsTypeAnnosNoCopy.java +++ /dev/null @@ -1,17 +0,0 @@ -import java.lang.annotation.ElementType; -import java.lang.annotation.Target; -import java.util.List; - -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@interface TA { -} - -class ConstructorsTypeAnnos { - @TA - List<@TA String> foo; - - @java.lang.SuppressWarnings("all") - public ConstructorsTypeAnnos(final List<@TA String> foo) { - this.foo = foo; - } -} diff --git a/test/transform/resource/after-delombok/GetterTypeAnnos.java b/test/transform/resource/after-delombok/GetterTypeAnnos.java new file mode 100644 index 00000000..4a22c822 --- /dev/null +++ b/test/transform/resource/after-delombok/GetterTypeAnnos.java @@ -0,0 +1,19 @@ +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; +import java.util.List; +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER}) +@interface TA { +} +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER}) +@interface TB { +} +class GetterTypeAnnos { + @TA + @TB + List foo; + @TA + @java.lang.SuppressWarnings("all") + public List getFoo() { + return this.foo; + } +} diff --git a/test/transform/resource/after-delombok/GetterTypeAnnosCopy.java b/test/transform/resource/after-delombok/GetterTypeAnnosCopy.java deleted file mode 100644 index cde6cbdd..00000000 --- a/test/transform/resource/after-delombok/GetterTypeAnnosCopy.java +++ /dev/null @@ -1,18 +0,0 @@ -import java.lang.annotation.ElementType; -import java.lang.annotation.Target; -import java.util.List; - -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@interface TA { -} - -class GetterTypeAnnos { - @TA - List<@TA String> foo; - - @TA - @java.lang.SuppressWarnings("all") - public List<@TA String> getFoo() { - return this.foo; - } -} diff --git a/test/transform/resource/after-delombok/GetterTypeAnnosNoCopy.java b/test/transform/resource/after-delombok/GetterTypeAnnosNoCopy.java deleted file mode 100644 index 58054de6..00000000 --- a/test/transform/resource/after-delombok/GetterTypeAnnosNoCopy.java +++ /dev/null @@ -1,17 +0,0 @@ -import java.lang.annotation.ElementType; -import java.lang.annotation.Target; -import java.util.List; - -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@interface TA { -} - -class GetterTypeAnnos { - @TA - List<@TA String> foo; - - @java.lang.SuppressWarnings("all") - public List<@TA String> getFoo() { - return this.foo; - } -} diff --git a/test/transform/resource/after-delombok/SetterTypeAnnos.java b/test/transform/resource/after-delombok/SetterTypeAnnos.java new file mode 100644 index 00000000..77ddf9ce --- /dev/null +++ b/test/transform/resource/after-delombok/SetterTypeAnnos.java @@ -0,0 +1,18 @@ +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; +import java.util.List; +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER}) +@interface TA { +} +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER}) +@interface TB { +} +class SetterTypeAnnos { + @TA + @TB + List foo; + @java.lang.SuppressWarnings("all") + public void setFoo(@TA final List foo) { + this.foo = foo; + } +} diff --git a/test/transform/resource/after-delombok/SetterTypeAnnosCopy.java b/test/transform/resource/after-delombok/SetterTypeAnnosCopy.java deleted file mode 100644 index b45c3234..00000000 --- a/test/transform/resource/after-delombok/SetterTypeAnnosCopy.java +++ /dev/null @@ -1,17 +0,0 @@ -import java.lang.annotation.ElementType; -import java.lang.annotation.Target; -import java.util.List; - -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@interface TA { -} - -class SetterTypeAnnos { - @TA - List<@TA String> foo; - - @java.lang.SuppressWarnings("all") - public void setFoo(@TA final List<@TA String> foo) { - this.foo = foo; - } -} diff --git a/test/transform/resource/after-delombok/SetterTypeAnnosNoCopy.java b/test/transform/resource/after-delombok/SetterTypeAnnosNoCopy.java deleted file mode 100644 index e773bd9c..00000000 --- a/test/transform/resource/after-delombok/SetterTypeAnnosNoCopy.java +++ /dev/null @@ -1,17 +0,0 @@ -import java.lang.annotation.ElementType; -import java.lang.annotation.Target; -import java.util.List; - -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@interface TA { -} - -class SetterTypeAnnos { - @TA - List<@TA String> foo; - - @java.lang.SuppressWarnings("all") - public void setFoo(final List<@TA String> foo) { - this.foo = foo; - } -} diff --git a/test/transform/resource/after-delombok/WitherTypeAnnos.java b/test/transform/resource/after-delombok/WitherTypeAnnos.java new file mode 100644 index 00000000..b57438af --- /dev/null +++ b/test/transform/resource/after-delombok/WitherTypeAnnos.java @@ -0,0 +1,21 @@ +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; +import java.util.List; +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER}) +@interface TA { +} +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER}) +@interface TB { +} +class WitherTypeAnnos { + @TA + @TB + final List foo; + WitherTypeAnnos(@TA @TB List foo) { + this.foo = foo; + } + @java.lang.SuppressWarnings("all") + public WitherTypeAnnos withFoo(@TA final List foo) { + return this.foo == foo ? this : new WitherTypeAnnos(foo); + } +} diff --git a/test/transform/resource/after-delombok/WitherTypeAnnosCopy.java b/test/transform/resource/after-delombok/WitherTypeAnnosCopy.java deleted file mode 100644 index 8cbb7e5d..00000000 --- a/test/transform/resource/after-delombok/WitherTypeAnnosCopy.java +++ /dev/null @@ -1,21 +0,0 @@ -import java.lang.annotation.ElementType; -import java.lang.annotation.Target; -import java.util.List; - -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@interface TA { -} - -class WitherTypeAnnos { - @TA - final List<@TA String> foo; - - WitherTypeAnnos(@TA List<@TA String> foo) { - this.foo = foo; - } - - @java.lang.SuppressWarnings("all") - public WitherTypeAnnos withFoo(@TA final List<@TA String> foo) { - return this.foo == foo ? this : new WitherTypeAnnos(foo); - } -} diff --git a/test/transform/resource/after-delombok/WitherTypeAnnosNoCopy.java b/test/transform/resource/after-delombok/WitherTypeAnnosNoCopy.java deleted file mode 100644 index 18c25e04..00000000 --- a/test/transform/resource/after-delombok/WitherTypeAnnosNoCopy.java +++ /dev/null @@ -1,21 +0,0 @@ -import java.lang.annotation.ElementType; -import java.lang.annotation.Target; -import java.util.List; - -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@interface TA { -} - -class WitherTypeAnnos { - @TA - final List<@TA String> foo; - - WitherTypeAnnos(@TA List<@TA String> foo) { - this.foo = foo; - } - - @java.lang.SuppressWarnings("all") - public WitherTypeAnnos withFoo(final List<@TA String> foo) { - return this.foo == foo ? this : new WitherTypeAnnos(foo); - } -} diff --git a/test/transform/resource/after-ecj/BuilderTypeAnnos.java b/test/transform/resource/after-ecj/BuilderTypeAnnos.java new file mode 100644 index 00000000..1c310f38 --- /dev/null +++ b/test/transform/resource/after-ecj/BuilderTypeAnnos.java @@ -0,0 +1,33 @@ +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; +import java.util.List; +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER}) @interface TA { +} +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER}) @interface TB { +} +@lombok.Builder class BuilderTypeAnnos { + public static @java.lang.SuppressWarnings("all") class BuilderTypeAnnosBuilder { + private @java.lang.SuppressWarnings("all") List foo; + @java.lang.SuppressWarnings("all") BuilderTypeAnnosBuilder() { + super(); + } + public @java.lang.SuppressWarnings("all") BuilderTypeAnnosBuilder foo(final @TA List foo) { + this.foo = foo; + return this; + } + public @java.lang.SuppressWarnings("all") BuilderTypeAnnos build() { + return new BuilderTypeAnnos(foo); + } + public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + return (("BuilderTypeAnnos.BuilderTypeAnnosBuilder(foo=" + this.foo) + ")"); + } + } + private @TA @TB List foo; + @java.lang.SuppressWarnings("all") BuilderTypeAnnos(final @TA List foo) { + super(); + this.foo = foo; + } + public static @java.lang.SuppressWarnings("all") BuilderTypeAnnosBuilder builder() { + return new BuilderTypeAnnosBuilder(); + } +} diff --git a/test/transform/resource/after-ecj/BuilderTypeAnnosCopy.java b/test/transform/resource/after-ecj/BuilderTypeAnnosCopy.java deleted file mode 100644 index 8dfc8164..00000000 --- a/test/transform/resource/after-ecj/BuilderTypeAnnosCopy.java +++ /dev/null @@ -1,31 +0,0 @@ -import java.lang.annotation.ElementType; -import java.lang.annotation.Target; -import java.util.List; -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface TA { -} -@lombok.Builder class BuilderTypeAnnos { - public static @java.lang.SuppressWarnings("all") class BuilderTypeAnnosBuilder { - private @java.lang.SuppressWarnings("all") List foo; - @java.lang.SuppressWarnings("all") BuilderTypeAnnosBuilder() { - super(); - } - public @java.lang.SuppressWarnings("all") BuilderTypeAnnosBuilder foo(final @TA List foo) { - this.foo = foo; - return this; - } - public @java.lang.SuppressWarnings("all") BuilderTypeAnnos build() { - return new BuilderTypeAnnos(foo); - } - public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { - return (("BuilderTypeAnnos.BuilderTypeAnnosBuilder(foo=" + this.foo) + ")"); - } - } - private @TA List<@TA String> foo; - @java.lang.SuppressWarnings("all") BuilderTypeAnnos(final @TA List foo) { - super(); - this.foo = foo; - } - public static @java.lang.SuppressWarnings("all") BuilderTypeAnnosBuilder builder() { - return new BuilderTypeAnnosBuilder(); - } -} diff --git a/test/transform/resource/after-ecj/BuilderTypeAnnosNoCopy.java b/test/transform/resource/after-ecj/BuilderTypeAnnosNoCopy.java deleted file mode 100644 index a2dfcc2f..00000000 --- a/test/transform/resource/after-ecj/BuilderTypeAnnosNoCopy.java +++ /dev/null @@ -1,31 +0,0 @@ -import java.lang.annotation.ElementType; -import java.lang.annotation.Target; -import java.util.List; -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface TA { -} -@lombok.Builder class BuilderTypeAnnos { - public static @java.lang.SuppressWarnings("all") class BuilderTypeAnnosBuilder { - private @java.lang.SuppressWarnings("all") List foo; - @java.lang.SuppressWarnings("all") BuilderTypeAnnosBuilder() { - super(); - } - public @java.lang.SuppressWarnings("all") BuilderTypeAnnosBuilder foo(final List foo) { - this.foo = foo; - return this; - } - public @java.lang.SuppressWarnings("all") BuilderTypeAnnos build() { - return new BuilderTypeAnnos(foo); - } - public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { - return (("BuilderTypeAnnos.BuilderTypeAnnosBuilder(foo=" + this.foo) + ")"); - } - } - private @TA List<@TA String> foo; - @java.lang.SuppressWarnings("all") BuilderTypeAnnos(final List foo) { - super(); - this.foo = foo; - } - public static @java.lang.SuppressWarnings("all") BuilderTypeAnnosBuilder builder() { - return new BuilderTypeAnnosBuilder(); - } -} diff --git a/test/transform/resource/after-ecj/ConstructorsTypeAnnos.java b/test/transform/resource/after-ecj/ConstructorsTypeAnnos.java new file mode 100644 index 00000000..3491239f --- /dev/null +++ b/test/transform/resource/after-ecj/ConstructorsTypeAnnos.java @@ -0,0 +1,14 @@ +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; +import java.util.List; +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER}) @interface TA { +} +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER}) @interface TB { +} +@lombok.AllArgsConstructor class ConstructorsTypeAnnos { + @TA @TB List foo; + public @java.lang.SuppressWarnings("all") ConstructorsTypeAnnos(final @TA List foo) { + super(); + this.foo = foo; + } +} diff --git a/test/transform/resource/after-ecj/ConstructorsTypeAnnosCopy.java b/test/transform/resource/after-ecj/ConstructorsTypeAnnosCopy.java deleted file mode 100644 index ad372fc9..00000000 --- a/test/transform/resource/after-ecj/ConstructorsTypeAnnosCopy.java +++ /dev/null @@ -1,12 +0,0 @@ -import java.lang.annotation.ElementType; -import java.lang.annotation.Target; -import java.util.List; -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface TA { -} -@lombok.AllArgsConstructor class ConstructorsTypeAnnos { - @TA List<@TA String> foo; - public @java.lang.SuppressWarnings("all") ConstructorsTypeAnnos(final @TA List foo) { - super(); - this.foo = foo; - } -} diff --git a/test/transform/resource/after-ecj/ConstructorsTypeAnnosNoCopy.java b/test/transform/resource/after-ecj/ConstructorsTypeAnnosNoCopy.java deleted file mode 100644 index ce4b1b3b..00000000 --- a/test/transform/resource/after-ecj/ConstructorsTypeAnnosNoCopy.java +++ /dev/null @@ -1,12 +0,0 @@ -import java.lang.annotation.ElementType; -import java.lang.annotation.Target; -import java.util.List; -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface TA { -} -@lombok.AllArgsConstructor class ConstructorsTypeAnnos { - @TA List<@TA String> foo; - public @java.lang.SuppressWarnings("all") ConstructorsTypeAnnos(final List foo) { - super(); - this.foo = foo; - } -} diff --git a/test/transform/resource/after-ecj/GetterTypeAnnos.java b/test/transform/resource/after-ecj/GetterTypeAnnos.java new file mode 100644 index 00000000..9ffc7f1c --- /dev/null +++ b/test/transform/resource/after-ecj/GetterTypeAnnos.java @@ -0,0 +1,17 @@ +import lombok.Getter; +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; +import java.util.List; +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER}) @interface TA { +} +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER}) @interface TB { +} +class GetterTypeAnnos { + @Getter @TA @TB List foo; + GetterTypeAnnos() { + super(); + } + public @TA @java.lang.SuppressWarnings("all") List getFoo() { + return this.foo; + } +} diff --git a/test/transform/resource/after-ecj/GetterTypeAnnosCopy.java b/test/transform/resource/after-ecj/GetterTypeAnnosCopy.java deleted file mode 100644 index 1b4f03c5..00000000 --- a/test/transform/resource/after-ecj/GetterTypeAnnosCopy.java +++ /dev/null @@ -1,15 +0,0 @@ -import lombok.Getter; -import java.lang.annotation.ElementType; -import java.lang.annotation.Target; -import java.util.List; -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface TA { -} -class GetterTypeAnnos { - @Getter @TA List<@TA String> foo; - GetterTypeAnnos() { - super(); - } - public @TA @java.lang.SuppressWarnings("all") List getFoo() { - return this.foo; - } -} diff --git a/test/transform/resource/after-ecj/GetterTypeAnnosNoCopy.java b/test/transform/resource/after-ecj/GetterTypeAnnosNoCopy.java deleted file mode 100644 index a43d3215..00000000 --- a/test/transform/resource/after-ecj/GetterTypeAnnosNoCopy.java +++ /dev/null @@ -1,15 +0,0 @@ -import lombok.Getter; -import java.lang.annotation.ElementType; -import java.lang.annotation.Target; -import java.util.List; -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface TA { -} -class GetterTypeAnnos { - @Getter @TA List<@TA String> foo; - GetterTypeAnnos() { - super(); - } - public @java.lang.SuppressWarnings("all") List getFoo() { - return this.foo; - } -} diff --git a/test/transform/resource/after-ecj/SetterTypeAnnos.java b/test/transform/resource/after-ecj/SetterTypeAnnos.java new file mode 100644 index 00000000..860694ea --- /dev/null +++ b/test/transform/resource/after-ecj/SetterTypeAnnos.java @@ -0,0 +1,17 @@ +import lombok.Setter; +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; +import java.util.List; +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER}) @interface TA { +} +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER}) @interface TB { +} +class SetterTypeAnnos { + @Setter @TA @TB List foo; + SetterTypeAnnos() { + super(); + } + public @java.lang.SuppressWarnings("all") void setFoo(final @TA List foo) { + this.foo = foo; + } +} diff --git a/test/transform/resource/after-ecj/SetterTypeAnnosCopy.java b/test/transform/resource/after-ecj/SetterTypeAnnosCopy.java deleted file mode 100644 index ef290cbf..00000000 --- a/test/transform/resource/after-ecj/SetterTypeAnnosCopy.java +++ /dev/null @@ -1,15 +0,0 @@ -import lombok.Setter; -import java.lang.annotation.ElementType; -import java.lang.annotation.Target; -import java.util.List; -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface TA { -} -class SetterTypeAnnos { - @Setter @TA List<@TA String> foo; - SetterTypeAnnos() { - super(); - } - public @java.lang.SuppressWarnings("all") void setFoo(final @TA List foo) { - this.foo = foo; - } -} diff --git a/test/transform/resource/after-ecj/SetterTypeAnnosNoCopy.java b/test/transform/resource/after-ecj/SetterTypeAnnosNoCopy.java deleted file mode 100644 index 17e27782..00000000 --- a/test/transform/resource/after-ecj/SetterTypeAnnosNoCopy.java +++ /dev/null @@ -1,15 +0,0 @@ -import lombok.Setter; -import java.lang.annotation.ElementType; -import java.lang.annotation.Target; -import java.util.List; -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface TA { -} -class SetterTypeAnnos { - @Setter @TA List<@TA String> foo; - SetterTypeAnnos() { - super(); - } - public @java.lang.SuppressWarnings("all") void setFoo(final List foo) { - this.foo = foo; - } -} diff --git a/test/transform/resource/after-ecj/WitherTypeAnnos.java b/test/transform/resource/after-ecj/WitherTypeAnnos.java new file mode 100644 index 00000000..e41d9e13 --- /dev/null +++ b/test/transform/resource/after-ecj/WitherTypeAnnos.java @@ -0,0 +1,18 @@ +import lombok.experimental.Wither; +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; +import java.util.List; +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER}) @interface TA { +} +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER}) @interface TB { +} +class WitherTypeAnnos { + final @Wither @TA @TB List foo; + WitherTypeAnnos(@TA @TB List foo) { + super(); + this.foo = foo; + } + public @java.lang.SuppressWarnings("all") WitherTypeAnnos withFoo(final @TA List foo) { + return ((this.foo == foo) ? this : new WitherTypeAnnos(foo)); + } +} diff --git a/test/transform/resource/after-ecj/WitherTypeAnnosCopy.java b/test/transform/resource/after-ecj/WitherTypeAnnosCopy.java deleted file mode 100644 index b4f3c687..00000000 --- a/test/transform/resource/after-ecj/WitherTypeAnnosCopy.java +++ /dev/null @@ -1,16 +0,0 @@ -import lombok.experimental.Wither; -import java.lang.annotation.ElementType; -import java.lang.annotation.Target; -import java.util.List; -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface TA { -} -class WitherTypeAnnos { - final @Wither @TA List<@TA String> foo; - WitherTypeAnnos(@TA List<@TA String> foo) { - super(); - this.foo = foo; - } - public @java.lang.SuppressWarnings("all") WitherTypeAnnos withFoo(final @TA List foo) { - return ((this.foo == foo) ? this : new WitherTypeAnnos(foo)); - } -} diff --git a/test/transform/resource/after-ecj/WitherTypeAnnosNoCopy.java b/test/transform/resource/after-ecj/WitherTypeAnnosNoCopy.java deleted file mode 100644 index 4f0b0710..00000000 --- a/test/transform/resource/after-ecj/WitherTypeAnnosNoCopy.java +++ /dev/null @@ -1,16 +0,0 @@ -import lombok.experimental.Wither; -import java.lang.annotation.ElementType; -import java.lang.annotation.Target; -import java.util.List; -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface TA { -} -class WitherTypeAnnos { - final @Wither @TA List<@TA String> foo; - WitherTypeAnnos(@TA List<@TA String> foo) { - super(); - this.foo = foo; - } - public @java.lang.SuppressWarnings("all") WitherTypeAnnos withFoo(final List foo) { - return ((this.foo == foo) ? this : new WitherTypeAnnos(foo)); - } -} diff --git a/test/transform/resource/before/BuilderTypeAnnos.java b/test/transform/resource/before/BuilderTypeAnnos.java new file mode 100644 index 00000000..6b7bc1d8 --- /dev/null +++ b/test/transform/resource/before/BuilderTypeAnnos.java @@ -0,0 +1,14 @@ +//CONF: lombok.copyableAnnotations += TA +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; +import java.util.List; +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER}) +@interface TA { +} +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER}) +@interface TB { +} +@lombok.Builder +class BuilderTypeAnnos { + private @TA @TB List foo; +} diff --git a/test/transform/resource/before/BuilderTypeAnnosCopy.java b/test/transform/resource/before/BuilderTypeAnnosCopy.java deleted file mode 100644 index e5ea9e41..00000000 --- a/test/transform/resource/before/BuilderTypeAnnosCopy.java +++ /dev/null @@ -1,14 +0,0 @@ -//CONF: lombok.copyAnnotations += TA - -import java.lang.annotation.ElementType; -import java.lang.annotation.Target; -import java.util.List; - -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@interface TA { -} - -@lombok.Builder -class BuilderTypeAnnos { - private @TA List<@TA String> foo; -} diff --git a/test/transform/resource/before/BuilderTypeAnnosNoCopy.java b/test/transform/resource/before/BuilderTypeAnnosNoCopy.java deleted file mode 100644 index 2defba7b..00000000 --- a/test/transform/resource/before/BuilderTypeAnnosNoCopy.java +++ /dev/null @@ -1,12 +0,0 @@ -import java.lang.annotation.ElementType; -import java.lang.annotation.Target; -import java.util.List; - -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@interface TA { -} - -@lombok.Builder -class BuilderTypeAnnos { - private @TA List<@TA String> foo; -} diff --git a/test/transform/resource/before/ConstructorsTypeAnnos.java b/test/transform/resource/before/ConstructorsTypeAnnos.java new file mode 100644 index 00000000..d767f321 --- /dev/null +++ b/test/transform/resource/before/ConstructorsTypeAnnos.java @@ -0,0 +1,14 @@ +//CONF: lombok.copyableAnnotations += TA +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; +import java.util.List; +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER}) +@interface TA { +} +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER}) +@interface TB { +} +@lombok.AllArgsConstructor +class ConstructorsTypeAnnos { + @TA @TB List foo; +} diff --git a/test/transform/resource/before/ConstructorsTypeAnnosCopy.java b/test/transform/resource/before/ConstructorsTypeAnnosCopy.java deleted file mode 100644 index 229927c3..00000000 --- a/test/transform/resource/before/ConstructorsTypeAnnosCopy.java +++ /dev/null @@ -1,14 +0,0 @@ -//CONF: lombok.copyAnnotations += TA - -import java.lang.annotation.ElementType; -import java.lang.annotation.Target; -import java.util.List; - -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@interface TA { -} - -@lombok.AllArgsConstructor -class ConstructorsTypeAnnos { - @TA List<@TA String> foo; -} diff --git a/test/transform/resource/before/ConstructorsTypeAnnosNoCopy.java b/test/transform/resource/before/ConstructorsTypeAnnosNoCopy.java deleted file mode 100644 index 7bc27008..00000000 --- a/test/transform/resource/before/ConstructorsTypeAnnosNoCopy.java +++ /dev/null @@ -1,12 +0,0 @@ -import java.lang.annotation.ElementType; -import java.lang.annotation.Target; -import java.util.List; - -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@interface TA { -} - -@lombok.AllArgsConstructor -class ConstructorsTypeAnnos { - @TA List<@TA String> foo; -} diff --git a/test/transform/resource/before/GetterTypeAnnos.java b/test/transform/resource/before/GetterTypeAnnos.java new file mode 100644 index 00000000..34177503 --- /dev/null +++ b/test/transform/resource/before/GetterTypeAnnos.java @@ -0,0 +1,15 @@ +//CONF: lombok.copyableAnnotations += TA +import lombok.Getter; +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; +import java.util.List; +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER}) +@interface TA { +} +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER}) +@interface TB { +} +class GetterTypeAnnos { + @Getter + @TA @TB List foo; +} diff --git a/test/transform/resource/before/GetterTypeAnnosCopy.java b/test/transform/resource/before/GetterTypeAnnosCopy.java deleted file mode 100644 index b48b8337..00000000 --- a/test/transform/resource/before/GetterTypeAnnosCopy.java +++ /dev/null @@ -1,16 +0,0 @@ -//CONF: lombok.copyAnnotations += TA - -import lombok.Getter; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Target; -import java.util.List; - -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@interface TA { -} - -class GetterTypeAnnos { - @Getter - @TA List<@TA String> foo; -} diff --git a/test/transform/resource/before/GetterTypeAnnosNoCopy.java b/test/transform/resource/before/GetterTypeAnnosNoCopy.java deleted file mode 100644 index bf4d9486..00000000 --- a/test/transform/resource/before/GetterTypeAnnosNoCopy.java +++ /dev/null @@ -1,14 +0,0 @@ -import lombok.Getter; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Target; -import java.util.List; - -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@interface TA { -} - -class GetterTypeAnnos { - @Getter - @TA List<@TA String> foo; -} diff --git a/test/transform/resource/before/SetterTypeAnnos.java b/test/transform/resource/before/SetterTypeAnnos.java new file mode 100644 index 00000000..8031136d --- /dev/null +++ b/test/transform/resource/before/SetterTypeAnnos.java @@ -0,0 +1,15 @@ +//CONF: lombok.copyableAnnotations += TA +import lombok.Setter; +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; +import java.util.List; +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER}) +@interface TA { +} +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER}) +@interface TB { +} +class SetterTypeAnnos { + @Setter + @TA @TB List foo; +} diff --git a/test/transform/resource/before/SetterTypeAnnosCopy.java b/test/transform/resource/before/SetterTypeAnnosCopy.java deleted file mode 100644 index d9d086f0..00000000 --- a/test/transform/resource/before/SetterTypeAnnosCopy.java +++ /dev/null @@ -1,16 +0,0 @@ -//CONF: lombok.copyAnnotations += TA - -import lombok.Setter; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Target; -import java.util.List; - -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@interface TA { -} - -class SetterTypeAnnos { - @Setter - @TA List<@TA String> foo; -} diff --git a/test/transform/resource/before/SetterTypeAnnosNoCopy.java b/test/transform/resource/before/SetterTypeAnnosNoCopy.java deleted file mode 100644 index e3666543..00000000 --- a/test/transform/resource/before/SetterTypeAnnosNoCopy.java +++ /dev/null @@ -1,14 +0,0 @@ -import lombok.Setter; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Target; -import java.util.List; - -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@interface TA { -} - -class SetterTypeAnnos { - @Setter - @TA List<@TA String> foo; -} diff --git a/test/transform/resource/before/WitherTypeAnnos.java b/test/transform/resource/before/WitherTypeAnnos.java new file mode 100644 index 00000000..97cd3d9f --- /dev/null +++ b/test/transform/resource/before/WitherTypeAnnos.java @@ -0,0 +1,18 @@ +//CONF: lombok.copyableAnnotations += TA +import lombok.experimental.Wither; +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; +import java.util.List; +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER}) +@interface TA { +} +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER}) +@interface TB { +} +class WitherTypeAnnos { + @Wither final @TA @TB List foo; + + WitherTypeAnnos(@TA @TB List foo) { + this.foo = foo; + } +} diff --git a/test/transform/resource/before/WitherTypeAnnosCopy.java b/test/transform/resource/before/WitherTypeAnnosCopy.java deleted file mode 100644 index 645682f5..00000000 --- a/test/transform/resource/before/WitherTypeAnnosCopy.java +++ /dev/null @@ -1,19 +0,0 @@ -//CONF: lombok.copyAnnotations += TA - -import lombok.experimental.Wither; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Target; -import java.util.List; - -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@interface TA { -} - -class WitherTypeAnnos { - @Wither final @TA List<@TA String> foo; - - WitherTypeAnnos(@TA List<@TA String> foo) { - this.foo = foo; - } -} diff --git a/test/transform/resource/before/WitherTypeAnnosNoCopy.java b/test/transform/resource/before/WitherTypeAnnosNoCopy.java deleted file mode 100644 index d278af55..00000000 --- a/test/transform/resource/before/WitherTypeAnnosNoCopy.java +++ /dev/null @@ -1,17 +0,0 @@ -import lombok.experimental.Wither; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Target; -import java.util.List; - -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@interface TA { -} - -class WitherTypeAnnos { - @Wither final @TA List<@TA String> foo; - - WitherTypeAnnos(@TA List<@TA String> foo) { - this.foo = foo; - } -} -- cgit From d7873f2d21564e8e7f22409fe03681d7dd4c8c1e Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Tue, 11 Sep 2018 01:41:22 +0200 Subject: Replaced the notion of ‘nullable’ and ‘nonnull’ get copied to ‘any ‘copyable’ annotations get copied’, with ‘copyable’ defined as a specific FQN-style list of well-known nullity-indicating annotations, plus whatever you configured in lombok.config. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also some work on the notion of TYPE_USE annotations. --- src/core/lombok/ConfigurationKeys.java | 5 +- src/core/lombok/NonNull.java | 2 +- src/core/lombok/core/TypeLibrary.java | 6 ++ src/core/lombok/core/handlers/HandlerUtil.java | 39 +++++--- .../eclipse/handlers/EclipseHandlerUtil.java | 36 +++++-- .../lombok/eclipse/handlers/HandleBuilder.java | 12 +-- .../lombok/eclipse/handlers/HandleConstructor.java | 12 +-- src/core/lombok/eclipse/handlers/HandleGetter.java | 12 +-- src/core/lombok/eclipse/handlers/HandleSetter.java | 8 +- .../eclipse/handlers/HandleSuperBuilder.java | 9 +- src/core/lombok/eclipse/handlers/HandleWither.java | 8 +- src/core/lombok/javac/handlers/HandleBuilder.java | 12 +-- .../lombok/javac/handlers/HandleConstructor.java | 15 ++- src/core/lombok/javac/handlers/HandleGetter.java | 8 +- src/core/lombok/javac/handlers/HandleSetter.java | 8 +- .../lombok/javac/handlers/HandleSuperBuilder.java | 3 +- src/core/lombok/javac/handlers/HandleWither.java | 8 +- .../lombok/javac/handlers/JavacHandlerUtil.java | 53 +++++++++- .../BuilderSingularAnnotatedTypes.java | 110 +++++++++++++++++++++ .../after-ecj/BuilderSingularAnnotatedTypes.java | 105 ++++++++++++++++++++ .../before/BuilderSingularAnnotatedTypes.java | 12 +++ 21 files changed, 381 insertions(+), 102 deletions(-) create mode 100644 test/transform/resource/after-delombok/BuilderSingularAnnotatedTypes.java create mode 100644 test/transform/resource/after-ecj/BuilderSingularAnnotatedTypes.java create mode 100644 test/transform/resource/before/BuilderSingularAnnotatedTypes.java (limited to 'src/core/lombok/javac/handlers/HandleWither.java') diff --git a/src/core/lombok/ConfigurationKeys.java b/src/core/lombok/ConfigurationKeys.java index 89748f60..2cca27fa 100644 --- a/src/core/lombok/ConfigurationKeys.java +++ b/src/core/lombok/ConfigurationKeys.java @@ -27,6 +27,7 @@ import lombok.core.configuration.CallSuperType; import lombok.core.configuration.ConfigurationKey; import lombok.core.configuration.FlagUsageType; import lombok.core.configuration.NullCheckExceptionType; +import lombok.core.configuration.TypeName; /** * A container class containing all lombok configuration keys that do not belong to a specific annotation. @@ -565,10 +566,10 @@ public class ConfigurationKeys { public static final ConfigurationKey STOP_BUBBLING = new ConfigurationKey("config.stopBubbling", "Tell the configuration system it should stop looking for other configuration files (default: false).") {}; /** - * lombok configuration: {@code lombok.copyableAnnotations} += <String: fully-qualified annotation class name>. + * lombok configuration: {@code lombok.copyableAnnotations} += <TypeName: fully-qualified annotation class name>. * * Copy these annotations to getters, setters, withers, builder-setters, etc. */ - public static final ConfigurationKey> COPYABLE_ANNOTATIONS = new ConfigurationKey>("lombok.copyableAnnotations", "Copy these annotations to getters, setters, withers, builder-setters, etc.") {}; + public static final ConfigurationKey> COPYABLE_ANNOTATIONS = new ConfigurationKey>("lombok.copyableAnnotations", "Copy these annotations to getters, setters, withers, builder-setters, etc.") {}; } diff --git a/src/core/lombok/NonNull.java b/src/core/lombok/NonNull.java index 58538583..caf6ed05 100644 --- a/src/core/lombok/NonNull.java +++ b/src/core/lombok/NonNull.java @@ -41,7 +41,7 @@ import java.lang.annotation.Target; * this annotation will be deleted from the lombok package. If the need to update an import statement scares * you, you should use your own annotation named {@code @NonNull} instead of this one. */ -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.LOCAL_VARIABLE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.LOCAL_VARIABLE, ElementType.TYPE_USE}) @Retention(RetentionPolicy.CLASS) @Documented public @interface NonNull { diff --git a/src/core/lombok/core/TypeLibrary.java b/src/core/lombok/core/TypeLibrary.java index cdaf7a70..ceaf5f90 100644 --- a/src/core/lombok/core/TypeLibrary.java +++ b/src/core/lombok/core/TypeLibrary.java @@ -45,6 +45,12 @@ public class TypeLibrary { qualified = null; } + public TypeLibrary(TypeLibrary parent) { + unqualifiedToQualifiedMap = new HashMap(); + unqualified = null; + qualified = null; + } + public void lock() { this.locked = true; } diff --git a/src/core/lombok/core/handlers/HandlerUtil.java b/src/core/lombok/core/handlers/HandlerUtil.java index 1694e305..296b70b4 100644 --- a/src/core/lombok/core/handlers/HandlerUtil.java +++ b/src/core/lombok/core/handlers/HandlerUtil.java @@ -27,7 +27,6 @@ import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; -import java.util.regex.Pattern; import lombok.AllArgsConstructor; import lombok.ConfigurationKeys; @@ -77,6 +76,33 @@ public class HandlerUtil { return 43; } + public static final List NONNULL_ANNOTATIONS, BASE_COPYABLE_ANNOTATIONS; + static { + NONNULL_ANNOTATIONS = Collections.unmodifiableList(Arrays.asList(new String[] { + "lombok.NonNull", + "javax.annotation.Nonnull", + "edu.umd.cs.findbugs.annotations.NonNull", + "org.jetbrains.annotations.NotNull", + "android.support.annotation.NonNull", + "org.eclipse.jdt.annotation.NonNull", + })); + BASE_COPYABLE_ANNOTATIONS = Collections.unmodifiableList(Arrays.asList(new String[] { + "lombok.NonNull", + "javax.annotation.Nonnull", + "edu.umd.cs.findbugs.annotations.NonNull", + "org.jetbrains.annotations.NotNull", + "android.support.annotation.NonNull", + "org.eclipse.jdt.annotation.NonNull", + "javax.annotation.Nullable", + "javax.annotation.CheckForNull", + "edu.umd.cs.findbugs.annotations.UnknownNullness", + "edu.umd.cs.findbugs.annotations.Nullable", + "org.jetbrains.annotations.Nullable", + "android.support.annotation.Nullable", + "org.eclipse.jdt.annotation.Nullable", + })); + } + /** Checks if the given name is a valid identifier. * * If it is, this returns {@code true} and does nothing else. @@ -222,19 +248,8 @@ public class HandlerUtil { constructor and the implied starts-out-as-null state that goes with it is in fact mandatory' which happens with javax.validation.constraints.NotNull. Various problems with spring have also been reported. See issue #287, issue #271, and issue #43. */ - /** Matches the simple part of any annotation that lombok considers as indicative of NonNull status. */ - public static final Pattern NON_NULL_PATTERN = Pattern.compile("^(?:nonnull)$", Pattern.CASE_INSENSITIVE); - - /** Matches the simple part of any annotation that lombok considers as indicative of Nullable status. */ - public static final Pattern NULLABLE_PATTERN = Pattern.compile("^(?:nullable|checkfornull)$", Pattern.CASE_INSENSITIVE); - public static final String DEFAULT_EXCEPTION_FOR_NON_NULL = "java.lang.NullPointerException"; - /** Returns the configuration value for ConfigurationKeys.COPYABLE_ANNOTATIONS. */ - public static List getCopyableAnnotationNames(AST ast) { - return ast.readConfiguration(ConfigurationKeys.COPYABLE_ANNOTATIONS); - } - /** * Generates a getter name from a given field name. * diff --git a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java index e7a58de3..a972c1fe 100644 --- a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java +++ b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java @@ -48,6 +48,7 @@ import lombok.core.AnnotationValues; import lombok.core.AnnotationValues.AnnotationValue; import lombok.core.TypeResolver; import lombok.core.configuration.NullCheckExceptionType; +import lombok.core.configuration.TypeName; import lombok.core.debug.ProblemReporter; import lombok.core.handlers.HandlerUtil; import lombok.eclipse.Eclipse; @@ -672,19 +673,42 @@ public class EclipseHandlerUtil { } } + public static boolean hasNonNullAnnotations(EclipseNode node) { + AbstractVariableDeclaration avd = (AbstractVariableDeclaration) node.get(); + if (avd.annotations == null) return false; + for (Annotation annotation : avd.annotations) { + TypeReference typeRef = annotation.type; + if (typeRef != null && typeRef.getTypeName() != null) { + for (String bn : NONNULL_ANNOTATIONS) if (typeMatches(bn, node, typeRef)) return true; + } + } + return false; + } + private static final Annotation[] EMPTY_ANNOTATIONS_ARRAY = new Annotation[0]; /** - * Searches the given field node for annotations and returns each one that matches the provided list of names. + * Searches the given field node for annotations and returns each one that is 'copyable' (either via configuration or from the base list). */ - public static Annotation[] findExactAnnotations(AbstractVariableDeclaration field, List names) { + public static Annotation[] findCopyableAnnotations(EclipseNode node) { + AbstractVariableDeclaration avd = (AbstractVariableDeclaration) node.get(); + if (avd.annotations == null) return EMPTY_ANNOTATIONS_ARRAY; List result = new ArrayList(); - if (field.annotations == null) return EMPTY_ANNOTATIONS_ARRAY; - for (Annotation annotation : field.annotations) { + List configuredCopyable = node.getAst().readConfiguration(ConfigurationKeys.COPYABLE_ANNOTATIONS); + + for (Annotation annotation : avd.annotations) { TypeReference typeRef = annotation.type; + boolean match = false; if (typeRef != null && typeRef.getTypeName() != null) { - String annoName = toQualifiedName(typeRef.getTypeName()); - if (names.contains(annoName)) result.add(annotation); + for (TypeName cn : configuredCopyable) if (typeMatches(cn.toString(), node, typeRef)) { + result.add(annotation); + match = true; + break; + } + if (!match) for (String bn : BASE_COPYABLE_ANNOTATIONS) if (typeMatches(bn, node, typeRef)) { + result.add(annotation); + break; + } } } return result.toArray(EMPTY_ANNOTATIONS_ARRAY); diff --git a/src/core/lombok/eclipse/handlers/HandleBuilder.java b/src/core/lombok/eclipse/handlers/HandleBuilder.java index f05896ab..280afc26 100644 --- a/src/core/lombok/eclipse/handlers/HandleBuilder.java +++ b/src/core/lombok/eclipse/handlers/HandleBuilder.java @@ -200,14 +200,12 @@ public class HandleBuilder extends EclipseAnnotationHandler { EclipseNode isDefault = findAnnotation(Builder.Default.class, fieldNode); boolean isFinal = ((fd.modifiers & ClassFileConstants.AccFinal) != 0) || (valuePresent && !hasAnnotation(NonFinal.class, fieldNode)); - Annotation[] nonNulls = findAnnotations(fd, NON_NULL_PATTERN); - Annotation[] nullables = findAnnotations(fd, NULLABLE_PATTERN); - Annotation[] copyAnnotations = findExactAnnotations(fd, getCopyableAnnotationNames(fieldNode.getAst())); + Annotation[] copyableAnnotations = findCopyableAnnotations(fieldNode); BuilderFieldData bfd = new BuilderFieldData(); bfd.rawName = fieldNode.getName().toCharArray(); bfd.name = removePrefixFromField(fieldNode); - bfd.annotations = copyAnnotations(fd, nonNulls, nullables, copyAnnotations); + bfd.annotations = copyAnnotations(fd, copyableAnnotations); bfd.type = fd.type; bfd.singularData = getSingularData(fieldNode, ast); bfd.originalFieldNode = fieldNode; @@ -381,13 +379,11 @@ public class HandleBuilder extends EclipseAnnotationHandler { BuilderFieldData bfd = new BuilderFieldData(); Argument arg = (Argument) param.get(); - Annotation[] nonNulls = findAnnotations(arg, NON_NULL_PATTERN); - Annotation[] nullables = findAnnotations(arg, NULLABLE_PATTERN); - Annotation[] copyAnnotations = findExactAnnotations(arg, getCopyableAnnotationNames(param.getAst())); + Annotation[] copyableAnnotations = findCopyableAnnotations(param); bfd.rawName = arg.name; bfd.name = arg.name; - bfd.annotations = copyAnnotations(arg, nonNulls, nullables, copyAnnotations); + bfd.annotations = copyAnnotations(arg, copyableAnnotations); bfd.type = arg.type; bfd.singularData = getSingularData(param, ast); bfd.originalFieldNode = param; diff --git a/src/core/lombok/eclipse/handlers/HandleConstructor.java b/src/core/lombok/eclipse/handlers/HandleConstructor.java index 3d947a73..cb07115a 100644 --- a/src/core/lombok/eclipse/handlers/HandleConstructor.java +++ b/src/core/lombok/eclipse/handlers/HandleConstructor.java @@ -139,7 +139,7 @@ public class HandleConstructor { FieldDeclaration fieldDecl = (FieldDeclaration) child.get(); if (!filterField(fieldDecl)) continue; boolean isFinal = (fieldDecl.modifiers & ClassFileConstants.AccFinal) != 0; - boolean isNonNull = nullMarked && findAnnotations(fieldDecl, NON_NULL_PATTERN).length != 0; + boolean isNonNull = nullMarked && hasNonNullAnnotations(child); if ((isFinal || isNonNull) && fieldDecl.initialization == null) fields.add(child); } return fields; @@ -403,14 +403,12 @@ public class HandleConstructor { assigns.add(assignment); long fieldPos = (((long) field.sourceStart) << 32) | field.sourceEnd; Argument parameter = new Argument(fieldName, fieldPos, copyType(field.type, source), Modifier.FINAL); - Annotation[] nonNulls = findAnnotations(field, NON_NULL_PATTERN); - Annotation[] nullables = findAnnotations(field, NULLABLE_PATTERN); - Annotation[] copyAnnotations = findExactAnnotations(field, getCopyableAnnotationNames(fieldNode.getAst())); - if (nonNulls.length != 0) { + Annotation[] copyableAnnotations = findCopyableAnnotations(fieldNode); + if (hasNonNullAnnotations(fieldNode)) { Statement nullCheck = generateNullCheck(parameter, sourceNode); if (nullCheck != null) nullChecks.add(nullCheck); } - parameter.annotations = copyAnnotations(source, nonNulls, nullables, copyAnnotations); + parameter.annotations = copyAnnotations(source, copyableAnnotations); params.add(parameter); } @@ -547,7 +545,7 @@ public class HandleConstructor { assigns.add(nameRef); Argument parameter = new Argument(field.name, fieldPos, copyType(field.type, source), Modifier.FINAL); - parameter.annotations = copyAnnotations(source, findAnnotations(field, NON_NULL_PATTERN), findAnnotations(field, NULLABLE_PATTERN)); + parameter.annotations = copyAnnotations(source, findCopyableAnnotations(fieldNode)); params.add(parameter); } diff --git a/src/core/lombok/eclipse/handlers/HandleGetter.java b/src/core/lombok/eclipse/handlers/HandleGetter.java index 58af8c1e..7d3fe62f 100644 --- a/src/core/lombok/eclipse/handlers/HandleGetter.java +++ b/src/core/lombok/eclipse/handlers/HandleGetter.java @@ -236,8 +236,6 @@ public class HandleGetter extends EclipseAnnotationHandler { } public MethodDeclaration createGetter(TypeDeclaration parent, EclipseNode fieldNode, String name, int modifier, ASTNode source, boolean lazy, List onMethod) { - FieldDeclaration field = (FieldDeclaration) fieldNode.get(); - // Remember the type; lazy will change it; TypeReference returnType = copyType(((FieldDeclaration) fieldNode.get()).type, source); @@ -271,12 +269,10 @@ public class HandleGetter extends EclipseAnnotationHandler { } method.annotations = copyAnnotations(source, - onMethod.toArray(new Annotation[0]), - findAnnotations(field, NON_NULL_PATTERN), - findAnnotations(field, NULLABLE_PATTERN), - findExactAnnotations(field, getCopyableAnnotationNames(fieldNode.getAst())), - findDelegatesAndMarkAsHandled(fieldNode), - deprecated); + onMethod.toArray(new Annotation[0]), + findCopyableAnnotations(fieldNode), + findDelegatesAndMarkAsHandled(fieldNode), + deprecated); } method.traverse(new SetGeneratedByVisitor(source), parent.scope); diff --git a/src/core/lombok/eclipse/handlers/HandleSetter.java b/src/core/lombok/eclipse/handlers/HandleSetter.java index ca81fef7..529a7d19 100644 --- a/src/core/lombok/eclipse/handlers/HandleSetter.java +++ b/src/core/lombok/eclipse/handlers/HandleSetter.java @@ -236,11 +236,9 @@ public class HandleSetter extends EclipseAnnotationHandler { method.bodyStart = method.declarationSourceStart = method.sourceStart = source.sourceStart; method.bodyEnd = method.declarationSourceEnd = method.sourceEnd = source.sourceEnd; - Annotation[] nonNulls = findAnnotations(field, NON_NULL_PATTERN); - Annotation[] nullables = findAnnotations(field, NULLABLE_PATTERN); - Annotation[] copyableAnnotations = findExactAnnotations(field, getCopyableAnnotationNames(fieldNode.getAst())); + Annotation[] copyableAnnotations = findCopyableAnnotations(fieldNode); List statements = new ArrayList(5); - if (nonNulls.length == 0) { + if (!hasNonNullAnnotations(fieldNode)) { statements.add(assignment); } else { Statement nullCheck = generateNullCheck(field, sourceNode); @@ -256,7 +254,7 @@ public class HandleSetter extends EclipseAnnotationHandler { statements.add(returnStatement); } method.statements = statements.toArray(new Statement[0]); - param.annotations = copyAnnotations(source, nonNulls, nullables, copyableAnnotations, onParam.toArray(new Annotation[0])); + param.annotations = copyAnnotations(source, copyableAnnotations, onParam.toArray(new Annotation[0])); method.traverse(new SetGeneratedByVisitor(source), parent.scope); return method; diff --git a/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java b/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java index 3c07ac55..559cca20 100644 --- a/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java +++ b/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java @@ -493,12 +493,9 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler { statements.add(assignment); } - Annotation[] nonNulls = findAnnotations((FieldDeclaration)fieldNode.originalFieldNode.get(), NON_NULL_PATTERN); - if (nonNulls.length != 0) { - Statement nullCheck = generateNullCheck((FieldDeclaration)fieldNode.originalFieldNode.get(), sourceNode); - if (nullCheck != null) { - statements.add(nullCheck); - } + if (hasNonNullAnnotations(fieldNode.originalFieldNode)) { + Statement nullCheck = generateNullCheck((FieldDeclaration) fieldNode.originalFieldNode.get(), sourceNode); + if (nullCheck != null) statements.add(nullCheck); } } diff --git a/src/core/lombok/eclipse/handlers/HandleWither.java b/src/core/lombok/eclipse/handlers/HandleWither.java index 11032e9c..a99789a6 100644 --- a/src/core/lombok/eclipse/handlers/HandleWither.java +++ b/src/core/lombok/eclipse/handlers/HandleWither.java @@ -240,9 +240,7 @@ public class HandleWither extends EclipseAnnotationHandler { method.typeParameters = null; method.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG; - Annotation[] nonNulls = findAnnotations(field, NON_NULL_PATTERN); - Annotation[] nullables = findAnnotations(field, NULLABLE_PATTERN); - Annotation[] copyableAnnotations = findExactAnnotations(field, getCopyableAnnotationNames(fieldNode.getAst())); + Annotation[] copyableAnnotations = findCopyableAnnotations(fieldNode); if (!makeAbstract) { List args = new ArrayList(); @@ -278,7 +276,7 @@ public class HandleWither extends EclipseAnnotationHandler { method.bodyEnd = method.declarationSourceEnd = method.sourceEnd = source.sourceEnd; List statements = new ArrayList(5); - if (nonNulls.length > 0) { + if (hasNonNullAnnotations(fieldNode)) { Statement nullCheck = generateNullCheck(field, sourceNode); if (nullCheck != null) statements.add(nullCheck); } @@ -286,7 +284,7 @@ public class HandleWither extends EclipseAnnotationHandler { method.statements = statements.toArray(new Statement[0]); } - param.annotations = copyAnnotations(source, nonNulls, nullables, copyableAnnotations, onParam.toArray(new Annotation[0])); + param.annotations = copyAnnotations(source, copyableAnnotations, onParam.toArray(new Annotation[0])); method.traverse(new SetGeneratedByVisitor(source), parent.scope); return method; diff --git a/src/core/lombok/javac/handlers/HandleBuilder.java b/src/core/lombok/javac/handlers/HandleBuilder.java index 7577eeb2..8170898b 100644 --- a/src/core/lombok/javac/handlers/HandleBuilder.java +++ b/src/core/lombok/javac/handlers/HandleBuilder.java @@ -150,14 +150,10 @@ public class HandleBuilder extends JavacAnnotationHandler { JavacNode isDefault = findAnnotation(Builder.Default.class, fieldNode, false); boolean isFinal = (fd.mods.flags & Flags.FINAL) != 0 || (valuePresent && !hasAnnotation(NonFinal.class, fieldNode)); - List nonNulls = findAnnotations(fieldNode, NON_NULL_PATTERN); - List nullables = findAnnotations(fieldNode, NULLABLE_PATTERN); - List copyableAnnotations = findExactAnnotations(fieldNode, getCopyableAnnotationNames(fieldNode.getAst())); - BuilderFieldData bfd = new BuilderFieldData(); bfd.rawName = fd.name; bfd.name = removePrefixFromField(fieldNode); - bfd.annotations = nonNulls.appendList(nullables).appendList(copyableAnnotations); + bfd.annotations = findCopyableAnnotations(fieldNode); bfd.type = fd.vartype; bfd.singularData = getSingularData(fieldNode); bfd.originalFieldNode = fieldNode; @@ -334,14 +330,10 @@ public class HandleBuilder extends JavacAnnotationHandler { if (param.getKind() != Kind.ARGUMENT) continue; BuilderFieldData bfd = new BuilderFieldData(); - List nonNulls = findAnnotations(param, NON_NULL_PATTERN); - List nullables = findAnnotations(param, NULLABLE_PATTERN); - List copyableAnnotations = findExactAnnotations(param, getCopyableAnnotationNames(param.getAst())); - JCVariableDecl raw = (JCVariableDecl) param.get(); bfd.name = raw.name; bfd.rawName = raw.name; - bfd.annotations = nonNulls.appendList(nullables).appendList(copyableAnnotations); + bfd.annotations = findCopyableAnnotations(param); bfd.type = raw.vartype; bfd.singularData = getSingularData(param); bfd.originalFieldNode = param; diff --git a/src/core/lombok/javac/handlers/HandleConstructor.java b/src/core/lombok/javac/handlers/HandleConstructor.java index 1e45d73f..3c434d40 100644 --- a/src/core/lombok/javac/handlers/HandleConstructor.java +++ b/src/core/lombok/javac/handlers/HandleConstructor.java @@ -127,7 +127,7 @@ public class HandleConstructor { //Skip static fields. if ((fieldFlags & Flags.STATIC) != 0) continue; boolean isFinal = (fieldFlags & Flags.FINAL) != 0; - boolean isNonNull = nullMarked && !findAnnotations(child, NON_NULL_PATTERN).isEmpty(); + boolean isNonNull = nullMarked && hasNonNullAnnotations(child); if ((isFinal || isNonNull) && fieldDecl.init == null) fields.append(child); } return fields.toList(); @@ -329,13 +329,11 @@ public class HandleConstructor { JCVariableDecl field = (JCVariableDecl) fieldNode.get(); Name fieldName = removePrefixFromField(fieldNode); Name rawName = field.name; - List nonNulls = findAnnotations(fieldNode, NON_NULL_PATTERN); - List nullables = findAnnotations(fieldNode, NULLABLE_PATTERN); - List copyableAnnotations = findExactAnnotations(fieldNode, getCopyableAnnotationNames(fieldNode.getAst())); + List copyableAnnotations = findCopyableAnnotations(fieldNode); long flags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, typeNode.getContext()); - JCVariableDecl param = maker.VarDef(maker.Modifiers(flags, nonNulls.appendList(nullables).appendList(copyableAnnotations)), fieldName, field.vartype, null); + JCVariableDecl param = maker.VarDef(maker.Modifiers(flags, copyableAnnotations), fieldName, field.vartype, null); params.append(param); - if (!nonNulls.isEmpty()) { + if (hasNonNullAnnotations(fieldNode)) { JCStatement nullCheck = generateNullCheck(maker, fieldNode, param, source); if (nullCheck != null) nullChecks.append(nullCheck); } @@ -472,10 +470,9 @@ public class HandleConstructor { JCVariableDecl field = (JCVariableDecl) fieldNode.get(); Name fieldName = removePrefixFromField(fieldNode); JCExpression pType = cloneType(maker, field.vartype, source, typeNode.getContext()); - List nonNulls = findAnnotations(fieldNode, NON_NULL_PATTERN); - List nullables = findAnnotations(fieldNode, NULLABLE_PATTERN); + List copyableAnnotations = findCopyableAnnotations(fieldNode); long flags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, typeNode.getContext()); - JCVariableDecl param = maker.VarDef(maker.Modifiers(flags, nonNulls.appendList(nullables)), fieldName, pType, null); + JCVariableDecl param = maker.VarDef(maker.Modifiers(flags, copyableAnnotations), fieldName, pType, null); params.append(param); args.append(maker.Ident(fieldName)); } diff --git a/src/core/lombok/javac/handlers/HandleGetter.java b/src/core/lombok/javac/handlers/HandleGetter.java index 04b300a8..7a178f66 100644 --- a/src/core/lombok/javac/handlers/HandleGetter.java +++ b/src/core/lombok/javac/handlers/HandleGetter.java @@ -243,13 +243,9 @@ public class HandleGetter extends JavacAnnotationHandler { List throwsClauses = List.nil(); JCExpression annotationMethodDefaultValue = null; - List nonNulls = findAnnotations(field, NON_NULL_PATTERN); - List nullables = findAnnotations(field, NULLABLE_PATTERN); - List copyableAnnotations = findExactAnnotations(field, getCopyableAnnotationNames(field.getAst())); - + List copyableAnnotations = findCopyableAnnotations(field); List delegates = findDelegatesAndRemoveFromField(field); - - List annsOnMethod = copyAnnotations(onMethod).appendList(nonNulls).appendList(nullables).appendList(copyableAnnotations); + List annsOnMethod = copyAnnotations(onMethod).appendList(copyableAnnotations); if (isFieldDeprecated(field)) { annsOnMethod = annsOnMethod.prepend(treeMaker.Annotation(genJavaLangTypeRef(field, "Deprecated"), List.nil())); } diff --git a/src/core/lombok/javac/handlers/HandleSetter.java b/src/core/lombok/javac/handlers/HandleSetter.java index e5e9481d..28f5318d 100644 --- a/src/core/lombok/javac/handlers/HandleSetter.java +++ b/src/core/lombok/javac/handlers/HandleSetter.java @@ -226,17 +226,15 @@ public class HandleSetter extends JavacAnnotationHandler { JCAssign assign = treeMaker.Assign(fieldRef, treeMaker.Ident(fieldDecl.name)); ListBuffer statements = new ListBuffer(); - List nonNulls = findAnnotations(field, NON_NULL_PATTERN); - List nullables = findAnnotations(field, NULLABLE_PATTERN); - List copyableAnnotations = findExactAnnotations(field, getCopyableAnnotationNames(field.getAst())); + List copyableAnnotations = findCopyableAnnotations(field); Name methodName = field.toName(setterName); - List annsOnParam = copyAnnotations(onParam).appendList(nonNulls).appendList(nullables).appendList(copyableAnnotations); + List annsOnParam = copyAnnotations(onParam).appendList(copyableAnnotations); long flags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, field.getContext()); JCVariableDecl param = treeMaker.VarDef(treeMaker.Modifiers(flags, annsOnParam), fieldDecl.name, fieldDecl.vartype, null); - if (nonNulls.isEmpty()) { + if (!hasNonNullAnnotations(field)) { statements.append(treeMaker.Exec(assign)); } else { JCStatement nullCheck = generateNullCheck(treeMaker, field, source); diff --git a/src/core/lombok/javac/handlers/HandleSuperBuilder.java b/src/core/lombok/javac/handlers/HandleSuperBuilder.java index b8f572d5..bcb7ee33 100644 --- a/src/core/lombok/javac/handlers/HandleSuperBuilder.java +++ b/src/core/lombok/javac/handlers/HandleSuperBuilder.java @@ -431,8 +431,7 @@ public class HandleSuperBuilder extends JavacAnnotationHandler { statements.append(assign); } - List nonNulls = findAnnotations(bfd.originalFieldNode, NON_NULL_PATTERN); - if (!nonNulls.isEmpty()) { + if (hasNonNullAnnotations(bfd.originalFieldNode)) { JCStatement nullCheck = generateNullCheck(maker, bfd.originalFieldNode, source); if (nullCheck != null) statements.append(nullCheck); } diff --git a/src/core/lombok/javac/handlers/HandleWither.java b/src/core/lombok/javac/handlers/HandleWither.java index b0e32d61..33c4dec2 100644 --- a/src/core/lombok/javac/handlers/HandleWither.java +++ b/src/core/lombok/javac/handlers/HandleWither.java @@ -222,9 +222,7 @@ public class HandleWither extends JavacAnnotationHandler { JCVariableDecl fieldDecl = (JCVariableDecl) field.get(); - List nonNulls = findAnnotations(field, NON_NULL_PATTERN); - List nullables = findAnnotations(field, NULLABLE_PATTERN); - List copyableAnnotations = findExactAnnotations(field, getCopyableAnnotationNames(field.getAst())); + List copyableAnnotations = findCopyableAnnotations(field); Name methodName = field.toName(witherName); @@ -232,7 +230,7 @@ public class HandleWither extends JavacAnnotationHandler { JCBlock methodBody = null; long flags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, field.getContext()); - List annsOnParam = copyAnnotations(onParam).appendList(nonNulls).appendList(nullables).appendList(copyableAnnotations); + List annsOnParam = copyAnnotations(onParam).appendList(copyableAnnotations); JCVariableDecl param = maker.VarDef(maker.Modifiers(flags, annsOnParam), fieldDecl.name, fieldDecl.vartype, null); @@ -265,7 +263,7 @@ public class HandleWither extends JavacAnnotationHandler { JCConditional conditional = maker.Conditional(identityCheck, maker.Ident(field.toName("this")), newClass); JCReturn returnStatement = maker.Return(conditional); - if (nonNulls.isEmpty()) { + if (!hasNonNullAnnotations(field)) { statements.append(returnStatement); } else { JCStatement nullCheck = generateNullCheck(maker, field, source); diff --git a/src/core/lombok/javac/handlers/JavacHandlerUtil.java b/src/core/lombok/javac/handlers/JavacHandlerUtil.java index 1cc28072..b1557533 100644 --- a/src/core/lombok/javac/handlers/JavacHandlerUtil.java +++ b/src/core/lombok/javac/handlers/JavacHandlerUtil.java @@ -49,6 +49,7 @@ import lombok.core.LombokImmutableList; import lombok.core.AnnotationValues.AnnotationValue; import lombok.core.TypeResolver; import lombok.core.configuration.NullCheckExceptionType; +import lombok.core.configuration.TypeName; import lombok.core.handlers.HandlerUtil; import lombok.delombok.LombokOptionsFactory; import lombok.experimental.Accessors; @@ -1335,16 +1336,58 @@ public class JavacHandlerUtil { return result.toList(); } + public static boolean hasNonNullAnnotations(JavacNode node) { + for (JavacNode child : node.down()) { + if (child.getKind() == Kind.ANNOTATION) { + JCAnnotation annotation = (JCAnnotation) child.get(); + for (String nn : NONNULL_ANNOTATIONS) if (typeMatches(nn, node, annotation.annotationType)) return true; + } + } + + return false; + } + /** - * Searches the given field node for annotations and returns each one that matches the provided list of names. + * Searches the given field node for annotations and returns each one that is 'copyable' (either via configuration or from the base list). */ - public static List findExactAnnotations(JavacNode fieldNode, java.util.List names) { + public static List findCopyableAnnotations(JavacNode node) { + JCAnnotation anno = null; + String annoName = null; + for (JavacNode child : node.down()) { + if (child.getKind() == Kind.ANNOTATION) { + if (anno != null) { + annoName = ""; + break; + } + JCAnnotation annotation = (JCAnnotation) child.get(); + annoName = annotation.annotationType.toString(); + anno = annotation; + } + } + + if (annoName == null) return List.nil(); + + java.util.List configuredCopyable = node.getAst().readConfiguration(ConfigurationKeys.COPYABLE_ANNOTATIONS); + + if (!annoName.isEmpty()) { + for (TypeName cn : configuredCopyable) if (typeMatches(cn.toString(), node, anno.annotationType)) return List.of(anno); + for (String bn : BASE_COPYABLE_ANNOTATIONS) if (typeMatches(bn, node, anno.annotationType)) return List.of(anno); + } + ListBuffer result = new ListBuffer(); - for (JavacNode child : fieldNode.down()) { + for (JavacNode child : node.down()) { if (child.getKind() == Kind.ANNOTATION) { JCAnnotation annotation = (JCAnnotation) child.get(); - String annoName = annotation.annotationType.toString(); - if (names.contains(annoName)) result.append(annotation); + boolean match = false; + for (TypeName cn : configuredCopyable) if (typeMatches(cn.toString(), node, annotation.annotationType)) { + result.append(annotation); + match = true; + break; + } + if (!match) for (String bn : BASE_COPYABLE_ANNOTATIONS) if (typeMatches(bn, node, annotation.annotationType)) { + result.append(annotation); + break; + } } } return result.toList(); diff --git a/test/transform/resource/after-delombok/BuilderSingularAnnotatedTypes.java b/test/transform/resource/after-delombok/BuilderSingularAnnotatedTypes.java new file mode 100644 index 00000000..d621d376 --- /dev/null +++ b/test/transform/resource/after-delombok/BuilderSingularAnnotatedTypes.java @@ -0,0 +1,110 @@ +import java.util.Set; +import java.util.Map; +import lombok.NonNull; +class BuilderSingularAnnotatedTypes { + private Set<@NonNull String> foos; + private Map<@NonNull String, @NonNull Integer> bars; + @java.lang.SuppressWarnings("all") + BuilderSingularAnnotatedTypes(final Set<@NonNull String> foos, final Map<@NonNull String, @NonNull Integer> bars) { + this.foos = foos; + this.bars = bars; + } + @java.lang.SuppressWarnings("all") + public static class BuilderSingularAnnotatedTypesBuilder { + @java.lang.SuppressWarnings("all") + private java.util.ArrayList<@NonNull String> foos; + @java.lang.SuppressWarnings("all") + private java.util.ArrayList<@NonNull String> bars$key; + @java.lang.SuppressWarnings("all") + private java.util.ArrayList<@NonNull Integer> bars$value; + @java.lang.SuppressWarnings("all") + BuilderSingularAnnotatedTypesBuilder() { + } + @java.lang.SuppressWarnings("all") + public BuilderSingularAnnotatedTypesBuilder foo(final @NonNull String foo) { + if (this.foos == null) this.foos = new java.util.ArrayList<@NonNull String>(); + this.foos.add(foo); + return this; + } + @java.lang.SuppressWarnings("all") + public BuilderSingularAnnotatedTypesBuilder foos(final java.util.Collection foos) { + if (this.foos == null) this.foos = new java.util.ArrayList<@NonNull String>(); + this.foos.addAll(foos); + return this; + } + @java.lang.SuppressWarnings("all") + public BuilderSingularAnnotatedTypesBuilder clearFoos() { + if (this.foos != null) this.foos.clear(); + return this; + } + @java.lang.SuppressWarnings("all") + public BuilderSingularAnnotatedTypesBuilder bar(final @NonNull String barKey, final @NonNull Integer barValue) { + if (this.bars$key == null) { + this.bars$key = new java.util.ArrayList<@NonNull String>(); + this.bars$value = new java.util.ArrayList<@NonNull Integer>(); + } + this.bars$key.add(barKey); + this.bars$value.add(barValue); + return this; + } + @java.lang.SuppressWarnings("all") + public BuilderSingularAnnotatedTypesBuilder bars(final java.util.Map bars) { + if (this.bars$key == null) { + this.bars$key = new java.util.ArrayList<@NonNull String>(); + this.bars$value = new java.util.ArrayList<@NonNull Integer>(); + } + for (final java.util.Map.Entry $lombokEntry : bars.entrySet()) { + this.bars$key.add($lombokEntry.getKey()); + this.bars$value.add($lombokEntry.getValue()); + } + return this; + } + @java.lang.SuppressWarnings("all") + public BuilderSingularAnnotatedTypesBuilder clearBars() { + if (this.bars$key != null) { + this.bars$key.clear(); + this.bars$value.clear(); + } + return this; + } + @java.lang.SuppressWarnings("all") + public BuilderSingularAnnotatedTypes build() { + java.util.Set<@NonNull String> foos; + switch (this.foos == null ? 0 : this.foos.size()) { + case 0: + foos = java.util.Collections.emptySet(); + break; + case 1: + foos = java.util.Collections.singleton(this.foos.get(0)); + break; + default: + foos = new java.util.LinkedHashSet<@NonNull String>(this.foos.size() < 1073741824 ? 1 + this.foos.size() + (this.foos.size() - 3) / 3 : java.lang.Integer.MAX_VALUE); + foos.addAll(this.foos); + foos = java.util.Collections.unmodifiableSet(foos); + } + java.util.Map<@NonNull String, @NonNull Integer> bars; + switch (this.bars$key == null ? 0 : this.bars$key.size()) { + case 0: + bars = java.util.Collections.emptyMap(); + break; + case 1: + bars = java.util.Collections.singletonMap(this.bars$key.get(0), this.bars$value.get(0)); + break; + default: + bars = new java.util.LinkedHashMap<@NonNull String, @NonNull Integer>(this.bars$key.size() < 1073741824 ? 1 + this.bars$key.size() + (this.bars$key.size() - 3) / 3 : java.lang.Integer.MAX_VALUE); + for (int $i = 0; $i < this.bars$key.size(); $i++) bars.put(this.bars$key.get($i), (@NonNull Integer) this.bars$value.get($i)); + bars = java.util.Collections.unmodifiableMap(bars); + } + return new BuilderSingularAnnotatedTypes(foos, bars); + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public java.lang.String toString() { + return "BuilderSingularAnnotatedTypes.BuilderSingularAnnotatedTypesBuilder(foos=" + this.foos + ", bars$key=" + this.bars$key + ", bars$value=" + this.bars$value + ")"; + } + } + @java.lang.SuppressWarnings("all") + public static BuilderSingularAnnotatedTypesBuilder builder() { + return new BuilderSingularAnnotatedTypesBuilder(); + } +} \ No newline at end of file diff --git a/test/transform/resource/after-ecj/BuilderSingularAnnotatedTypes.java b/test/transform/resource/after-ecj/BuilderSingularAnnotatedTypes.java new file mode 100644 index 00000000..0168a13c --- /dev/null +++ b/test/transform/resource/after-ecj/BuilderSingularAnnotatedTypes.java @@ -0,0 +1,105 @@ +import java.util.Set; +import java.util.Map; +import lombok.NonNull; +import lombok.Singular; +@lombok.Builder class BuilderSingularAnnotatedTypes { + public static @java.lang.SuppressWarnings("all") class BuilderSingularAnnotatedTypesBuilder { + private @java.lang.SuppressWarnings("all") java.util.ArrayList<@NonNull String> foos; + private @java.lang.SuppressWarnings("all") java.util.ArrayList<@NonNull String> bars$key; + private @java.lang.SuppressWarnings("all") java.util.ArrayList<@NonNull Integer> bars$value; + @java.lang.SuppressWarnings("all") BuilderSingularAnnotatedTypesBuilder() { + super(); + } + public @java.lang.SuppressWarnings("all") BuilderSingularAnnotatedTypesBuilder foo(@NonNull String foo) { + if ((this.foos == null)) + this.foos = new java.util.ArrayList<@NonNull String>(); + this.foos.add(foo); + return this; + } + public @java.lang.SuppressWarnings("all") BuilderSingularAnnotatedTypesBuilder foos(java.util.Collection foos) { + if ((this.foos == null)) + this.foos = new java.util.ArrayList<@NonNull String>(); + this.foos.addAll(foos); + return this; + } + public @java.lang.SuppressWarnings("all") BuilderSingularAnnotatedTypesBuilder clearFoos() { + if ((this.foos != null)) + this.foos.clear(); + return this; + } + public @java.lang.SuppressWarnings("all") BuilderSingularAnnotatedTypesBuilder bar(@NonNull String barKey, @NonNull Integer barValue) { + if ((this.bars$key == null)) + { + this.bars$key = new java.util.ArrayList<@NonNull String>(); + this.bars$value = new java.util.ArrayList<@NonNull Integer>(); + } + this.bars$key.add(barKey); + this.bars$value.add(barValue); + return this; + } + public @java.lang.SuppressWarnings("all") BuilderSingularAnnotatedTypesBuilder bars(java.util.Map bars) { + if ((this.bars$key == null)) + { + this.bars$key = new java.util.ArrayList<@NonNull String>(); + this.bars$value = new java.util.ArrayList<@NonNull Integer>(); + } + for (java.util.Map.Entry $lombokEntry : bars.entrySet()) + { + this.bars$key.add($lombokEntry.getKey()); + this.bars$value.add($lombokEntry.getValue()); + } + return this; + } + public @java.lang.SuppressWarnings("all") BuilderSingularAnnotatedTypesBuilder clearBars() { + if ((this.bars$key != null)) + { + this.bars$key.clear(); + this.bars$value.clear(); + } + return this; + } + public @java.lang.SuppressWarnings("all") BuilderSingularAnnotatedTypes build() { + java.util.Set<@NonNull String> foos; + switch (((this.foos == null) ? 0 : this.foos.size())) { + case 0 : + foos = java.util.Collections.emptySet(); + break; + case 1 : + foos = java.util.Collections.singleton(this.foos.get(0)); + break; + default : + foos = new java.util.LinkedHashSet<@NonNull String>(((this.foos.size() < 0x40000000) ? ((1 + this.foos.size()) + ((this.foos.size() - 3) / 3)) : java.lang.Integer.MAX_VALUE)); + foos.addAll(this.foos); + foos = java.util.Collections.unmodifiableSet(foos); + } + java.util.Map<@NonNull String, @NonNull Integer> bars; + switch (((this.bars$key == null) ? 0 : this.bars$key.size())) { + case 0 : + bars = java.util.Collections.emptyMap(); + break; + case 1 : + bars = java.util.Collections.singletonMap(this.bars$key.get(0), this.bars$value.get(0)); + break; + default : + bars = new java.util.LinkedHashMap<@NonNull String, @NonNull Integer>(((this.bars$key.size() < 0x40000000) ? ((1 + this.bars$key.size()) + ((this.bars$key.size() - 3) / 3)) : java.lang.Integer.MAX_VALUE)); + for (int $i = 0;; ($i < this.bars$key.size()); $i ++) + bars.put(this.bars$key.get($i), this.bars$value.get($i)); + bars = java.util.Collections.unmodifiableMap(bars); + } + return new BuilderSingularAnnotatedTypes(foos, bars); + } + public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + return (((((("BuilderSingularAnnotatedTypes.BuilderSingularAnnotatedTypesBuilder(foos=" + this.foos) + ", bars$key=") + this.bars$key) + ", bars$value=") + this.bars$value) + ")"); + } + } + private @Singular Set<@NonNull String> foos; + private @Singular Map<@NonNull String, @NonNull Integer> bars; + @java.lang.SuppressWarnings("all") BuilderSingularAnnotatedTypes(final Set<@NonNull String> foos, final Map<@NonNull String, @NonNull Integer> bars) { + super(); + this.foos = foos; + this.bars = bars; + } + public static @java.lang.SuppressWarnings("all") BuilderSingularAnnotatedTypesBuilder builder() { + return new BuilderSingularAnnotatedTypesBuilder(); + } +} diff --git a/test/transform/resource/before/BuilderSingularAnnotatedTypes.java b/test/transform/resource/before/BuilderSingularAnnotatedTypes.java new file mode 100644 index 00000000..163507b9 --- /dev/null +++ b/test/transform/resource/before/BuilderSingularAnnotatedTypes.java @@ -0,0 +1,12 @@ +//VERSION 8: +import java.util.Set; +import java.util.Map; + +import lombok.NonNull; +import lombok.Singular; + +@lombok.Builder +class BuilderSingularAnnotatedTypes { + @Singular private Set<@NonNull String> foos; + @Singular private Map<@NonNull String, @NonNull Integer> bars; +} -- cgit