diff options
24 files changed, 112 insertions, 41 deletions
diff --git a/doc/changelog.markdown b/doc/changelog.markdown index f1980523..2c5906af 100644 --- a/doc/changelog.markdown +++ b/doc/changelog.markdown @@ -7,7 +7,7 @@ Lombok Changelog * FEATURE: In [`lombok.config`](https://projectlombok.org/features/configuration) it is possible to import other config files, even from a `.zip` or `.jar`. * FEATURE: You can now configure a builder's 'setter' prefixes via `@Builder(setterPrefix = "set")` for example. We discourage doing this, but if some library you use requires them, have at it. [Pull Request #2174](https://github.com/rzwitserloot/lombok/pull/2174], [Issue #1805](https://github.com/rzwitserloot/lombok/issues/1805). * FEATURE: If you use `@Builder`'s `@Singular`, a plural form is also generated, which has the effect of adding all elements in the passed collection. If you pass a null reference, this would result in a message-less `NullPointerException`. Now, it results in that exception but with a useful message attached (uses the same config as `@NonNull`), or alternatively via a parameter on `@Singular`, you can choose to ignore such a call (add nothing, return immediately); this can be useful when deserializing (e.g. Jackson JSON) and JPA/Hibernate code. [Issue #2221](https://github.com/rzwitserloot/lombok/issues/2221]. [singular documentation](https://projectlombok.org/features/Builder). -* FEATURE: Tired of being unable to use `@javax.annotation.ParametersAreNonnullByDefault` or `@org.eclipse.jdt.annotation.NonNullByDefault` because then the equals method that lombok generates isn't valid? Fret no more; lombok can now add nullity annotations where relevant. Set the flavour of nullity annotation you prefer in your `lombok.config`. Applies to the return value of `toString` and `withX` methods, and the parameter of `equals`, `canEqual`, and the plural form of `@Singular` marked fields for builder classes. [Issue #788](https://github.com/rzwitserloot/lombok/issues/788) +* FEATURE: Tired of being unable to use `@javax.annotation.ParametersAreNonnullByDefault` or `@org.eclipse.jdt.annotation.NonNullByDefault` because then the equals method that lombok generates isn't valid? Fret no more; lombok can now add nullity annotations where relevant. Set the flavour of nullity annotation you prefer in your `lombok.config`. Applies to the return value of `toString`, `withX`, chainable `setX`, static constructors, `build`, `builder`, etcetera, and the parameter of `equals`, `canEqual`, and the plural form of `@Singular` marked fields for builder classes. [Issue #788](https://github.com/rzwitserloot/lombok/issues/788) * BUGFIX: `lombok.experimental.Wither` has been deprecated (it has been renamed to `lombok.With`). However, the intent is that lombok still handles the old annotation in case you haven't updated your lombok dep yet. However, only a star import on `lombok.experimental.*` worked; an explicit one would cause lombok to not generate any with method. [Issue #2235](https://github.com/rzwitserloot/lombok/issues/2235) * BUGFIX: Referring to an inner class inside the generics on a class marked with `@SuperBuilder` would cause the error `wrong number of type arguments; required 3` [Issue #2262](https://github.com/rzwitserloot/lombok/issues/2262); fixed by github user [`@Lekanich`](https://github.com/rzwitserloot/lombok/issues/2262) - thank you! * BUGFIX: Some of the code generated by `@Builder` did not include `this.` prefixes when accessing fields. While semantically it didn't matter, if you use the 'add this prefix for field accesses' save action in eclipse, the save action would break. [Issue #2327](https://github.com/rzwitserloot/lombok/issues/2327) diff --git a/src/core/lombok/eclipse/handlers/HandleBuilder.java b/src/core/lombok/eclipse/handlers/HandleBuilder.java index 19388eda..20bec50e 100755 --- a/src/core/lombok/eclipse/handlers/HandleBuilder.java +++ b/src/core/lombok/eclipse/handlers/HandleBuilder.java @@ -650,6 +650,7 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> { out.annotations = new Annotation[] {generateNamedAnnotation(source, CheckerFrameworkVersion.NAME__UNIQUE)}; } + createRelevantNonNullAnnotation(type, out); out.traverse(new SetGeneratedByVisitor(source), ((TypeDeclaration) type.get()).scope); return out; } @@ -796,6 +797,7 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> { out.annotations = new Annotation[] {generateNamedAnnotation(source, CheckerFrameworkVersion.NAME__SIDE_EFFECT_FREE)}; } out.arguments = generateBuildArgs(cfv, type, builderFields, source); + if (staticName == null) createRelevantNonNullAnnotation(type, out); out.traverse(new SetGeneratedByVisitor(source), (ClassScope) null); return out; } @@ -864,6 +866,7 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> { } else if (sefAnn != null) { out.annotations = new Annotation[] {sefAnn}; } + createRelevantNonNullAnnotation(type, out); out.traverse(new SetGeneratedByVisitor(source), ((TypeDeclaration) type.get()).scope); return out; } diff --git a/src/core/lombok/eclipse/handlers/HandleConstructor.java b/src/core/lombok/eclipse/handlers/HandleConstructor.java index f69a2d1c..129fa7c0 100755 --- a/src/core/lombok/eclipse/handlers/HandleConstructor.java +++ b/src/core/lombok/eclipse/handlers/HandleConstructor.java @@ -562,6 +562,7 @@ public class HandleConstructor { constructor.arguments = params.isEmpty() ? null : params.toArray(new Argument[0]); constructor.statements = new Statement[] { new ReturnStatement(statement, (int) (p >> 32), (int)p) }; + createRelevantNonNullAnnotation(type, constructor); constructor.traverse(new SetGeneratedByVisitor(source), typeDecl.scope); return constructor; } diff --git a/src/core/lombok/eclipse/handlers/HandleSetter.java b/src/core/lombok/eclipse/handlers/HandleSetter.java index 8ee54d0f..cb2ca3bf 100644 --- a/src/core/lombok/eclipse/handlers/HandleSetter.java +++ b/src/core/lombok/eclipse/handlers/HandleSetter.java @@ -260,6 +260,8 @@ public class HandleSetter extends EclipseAnnotationHandler<Setter> { method.statements = statements.toArray(new Statement[0]); param.annotations = copyAnnotations(source, copyableAnnotations, onParam.toArray(new Annotation[0])); + if (returnType != null && returnStatement != null) createRelevantNonNullAnnotation(sourceNode, method); + 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 0a5acd56..306c6439 100755 --- a/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java +++ b/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java @@ -599,6 +599,7 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler<SuperBuilder> { if (cfv.generateUnique()) out.annotations = new Annotation[] {generateNamedAnnotation(source, CheckerFrameworkVersion.NAME__UNIQUE)}; + createRelevantNonNullAnnotation(type, out); out.traverse(new SetGeneratedByVisitor(source), ((TypeDeclaration) type.get()).scope); return out; } @@ -633,6 +634,7 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler<SuperBuilder> { if (cfv.generateUnique()) out.annotations = new Annotation[] {generateNamedAnnotation(source, CheckerFrameworkVersion.NAME__UNIQUE)}; + createRelevantNonNullAnnotation(type, out); out.traverse(new SetGeneratedByVisitor(source), ((TypeDeclaration) type.get()).scope); return out; } @@ -850,8 +852,9 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler<SuperBuilder> { allocationStatement.arguments = new Expression[] {new ThisReference(0, 0)}; statements.add(new ReturnStatement(allocationStatement, 0, 0)); out.statements = statements.isEmpty() ? null : statements.toArray(new Statement[0]); - out.traverse(new SetGeneratedByVisitor(source), (ClassScope) null); out.arguments = HandleBuilder.generateBuildArgs(cfv, builderType, builderFields, source); + createRelevantNonNullAnnotation(builderType, out); + out.traverse(new SetGeneratedByVisitor(source), (ClassScope) null); return out; } diff --git a/src/core/lombok/eclipse/handlers/singulars/EclipseGuavaSingularizer.java b/src/core/lombok/eclipse/handlers/singulars/EclipseGuavaSingularizer.java index 5d656c91..392418ff 100755 --- a/src/core/lombok/eclipse/handlers/singulars/EclipseGuavaSingularizer.java +++ b/src/core/lombok/eclipse/handlers/singulars/EclipseGuavaSingularizer.java @@ -132,6 +132,7 @@ abstract class EclipseGuavaSingularizer extends EclipseSingularizer { md.annotations = generateSelfReturnAnnotations(deprecate, cfv, data.getSource()); data.setGeneratedByRecursive(md); + if (returnStatement != null) createRelevantNonNullAnnotation(builderType, md); injectMethod(builderType, md); } @@ -176,6 +177,7 @@ abstract class EclipseGuavaSingularizer extends EclipseSingularizer { md.selector = fluent ? prefixedSingularName : HandlerUtil.buildAccessorName("add", new String(data.getSingularName())).toCharArray(); md.annotations = generateSelfReturnAnnotations(deprecate, cfv, data.getSource()); + if (returnStatement != null) createRelevantNonNullAnnotation(builderType, md); data.setGeneratedByRecursive(md); HandleNonNull.INSTANCE.fix(injectMethod(builderType, md)); } @@ -207,13 +209,13 @@ abstract class EclipseGuavaSingularizer extends EclipseSingularizer { md.statements = statements.toArray(new Statement[0]); - md.arguments = new Argument[] {param}; md.returnType = returnType; char[] prefixedSelector = data.getSetterPrefix().length == 0 ? data.getPluralName() : HandlerUtil.buildAccessorName(new String(data.getSetterPrefix()), new String(data.getPluralName())).toCharArray(); md.selector = fluent ? prefixedSelector : HandlerUtil.buildAccessorName("addAll", new String(data.getPluralName())).toCharArray(); md.annotations = generateSelfReturnAnnotations(deprecate, cfv, data.getSource()); + if (returnStatement != null) createRelevantNonNullAnnotation(builderType, md); data.setGeneratedByRecursive(md); injectMethod(builderType, md); } diff --git a/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilListSetSingularizer.java b/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilListSetSingularizer.java index 024f5880..375f4e2c 100755 --- a/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilListSetSingularizer.java +++ b/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilListSetSingularizer.java @@ -122,6 +122,7 @@ abstract class EclipseJavaUtilListSetSingularizer extends EclipseJavaUtilSingula md.annotations = generateSelfReturnAnnotations(deprecate, cfv, data.getSource()); data.setGeneratedByRecursive(md); + if (returnStatement != null) createRelevantNonNullAnnotation(builderType, md); injectMethod(builderType, md); } @@ -154,6 +155,7 @@ abstract class EclipseJavaUtilListSetSingularizer extends EclipseJavaUtilSingula md.selector = fluent ? prefixedSingularName : HandlerUtil.buildAccessorName("add", new String(data.getSingularName())).toCharArray(); md.annotations = generateSelfReturnAnnotations(deprecate, cfv, data.getSource()); + if (returnStatement != null) createRelevantNonNullAnnotation(builderType, md); data.setGeneratedByRecursive(md); HandleNonNull.INSTANCE.fix(injectMethod(builderType, md)); } @@ -189,6 +191,7 @@ abstract class EclipseJavaUtilListSetSingularizer extends EclipseJavaUtilSingula md.selector = fluent ? prefixedSelector : HandlerUtil.buildAccessorName("addAll", new String(data.getPluralName())).toCharArray(); md.annotations = generateSelfReturnAnnotations(deprecate, cfv, data.getSource()); + if (returnStatement != null) createRelevantNonNullAnnotation(builderType, md); data.setGeneratedByRecursive(md); injectMethod(builderType, md); } diff --git a/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilMapSingularizer.java b/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilMapSingularizer.java index 843fd073..cb7d9ed6 100755 --- a/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilMapSingularizer.java +++ b/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilMapSingularizer.java @@ -191,6 +191,7 @@ public class EclipseJavaUtilMapSingularizer extends EclipseJavaUtilSingularizer md.returnType = returnType; md.annotations = generateSelfReturnAnnotations(deprecate, cfv, data.getSource()); + if (returnStatement != null) createRelevantNonNullAnnotation(builderType, md); data.setGeneratedByRecursive(md); injectMethod(builderType, md); } @@ -253,6 +254,7 @@ public class EclipseJavaUtilMapSingularizer extends EclipseJavaUtilSingularizer md.selector = setterName.toCharArray(); md.annotations = generateSelfReturnAnnotations(deprecate, cfv, data.getSource()); + if (returnStatement != null) createRelevantNonNullAnnotation(builderType, md); data.setGeneratedByRecursive(md); HandleNonNull.INSTANCE.fix(injectMethod(builderType, md)); } @@ -326,6 +328,7 @@ public class EclipseJavaUtilMapSingularizer extends EclipseJavaUtilSingularizer md.selector = setterName.toCharArray(); md.annotations = generateSelfReturnAnnotations(deprecate, cfv, data.getSource()); + if (returnStatement != null) createRelevantNonNullAnnotation(builderType, md); data.setGeneratedByRecursive(md); injectMethod(builderType, md); } diff --git a/src/core/lombok/javac/handlers/HandleBuilder.java b/src/core/lombok/javac/handlers/HandleBuilder.java index 5c4b4297..2f000546 100644 --- a/src/core/lombok/javac/handlers/HandleBuilder.java +++ b/src/core/lombok/javac/handlers/HandleBuilder.java @@ -611,7 +611,9 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> { } JCBlock body = maker.Block(0, statements.toList()); List<JCAnnotation> annsOnMethod = cfv.generateUnique() ? List.of(maker.Annotation(genTypeRef(type, CheckerFrameworkVersion.NAME__UNIQUE), List.<JCExpression>nil())) : List.<JCAnnotation>nil(); - return maker.MethodDef(maker.Modifiers(toJavacModifier(access), annsOnMethod), type.toName(toBuilderMethodName), namePlusTypeParamsToTypeReference(maker, type, type.toName(builderClassName), !isStatic, typeParams), List.<JCTypeParameter>nil(), List.<JCVariableDecl>nil(), List.<JCExpression>nil(), body, null); + JCMethodDecl methodDef = maker.MethodDef(maker.Modifiers(toJavacModifier(access), annsOnMethod), type.toName(toBuilderMethodName), namePlusTypeParamsToTypeReference(maker, type, type.toName(builderClassName), !isStatic, typeParams), List.<JCTypeParameter>nil(), List.<JCVariableDecl>nil(), List.<JCExpression>nil(), body, null); + createRelevantNonNullAnnotation(type, methodDef); + return methodDef; } private JCMethodDecl generateCleanMethod(java.util.List<BuilderFieldData> builderFields, JavacNode type, JCTree source) { @@ -714,7 +716,9 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> { List<JCAnnotation> annsOnMethod = cfv.generateSideEffectFree() ? List.of(maker.Annotation(genTypeRef(type, CheckerFrameworkVersion.NAME__SIDE_EFFECT_FREE), List.<JCExpression>nil())) : List.<JCAnnotation>nil(); List<JCVariableDecl> params = generateBuildArgs(cfv, type, builderFields); - return maker.MethodDef(maker.Modifiers(toJavacModifier(access), annsOnMethod), type.toName(buildName), returnType, List.<JCTypeParameter>nil(), params, thrownExceptions, body, null); + JCMethodDecl methodDef = maker.MethodDef(maker.Modifiers(toJavacModifier(access), annsOnMethod), type.toName(buildName), returnType, List.<JCTypeParameter>nil(), params, thrownExceptions, body, null); + if (builderName == null) createRelevantNonNullAnnotation(type, methodDef); + return methodDef; } public static JCMethodDecl generateDefaultProvider(Name methodName, JavacNode fieldNode, List<JCTypeParameter> params) { @@ -757,7 +761,9 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> { else if (annUnique != null) annsOnMethod = List.of(annUnique); else if (annSef != null) annsOnMethod = List.of(annSef); else annsOnMethod = List.nil(); - return maker.MethodDef(maker.Modifiers(modifiers, annsOnMethod), type.toName(builderMethodName), namePlusTypeParamsToTypeReference(maker, type, type.toName(builderClassName), !isStatic, typeParams), copyTypeParams(source, typeParams), List.<JCVariableDecl>nil(), List.<JCExpression>nil(), body, null); + JCMethodDecl methodDef = maker.MethodDef(maker.Modifiers(modifiers, annsOnMethod), type.toName(builderMethodName), namePlusTypeParamsToTypeReference(maker, type, type.toName(builderClassName), !isStatic, typeParams), copyTypeParams(source, typeParams), List.<JCVariableDecl>nil(), List.<JCExpression>nil(), body, null); + createRelevantNonNullAnnotation(type, methodDef); + return methodDef; } public void generateBuilderFields(JavacNode builderType, java.util.List<BuilderFieldData> builderFields, JCTree source) { diff --git a/src/core/lombok/javac/handlers/HandleConstructor.java b/src/core/lombok/javac/handlers/HandleConstructor.java index 4d7c61ad..d022995a 100644 --- a/src/core/lombok/javac/handlers/HandleConstructor.java +++ b/src/core/lombok/javac/handlers/HandleConstructor.java @@ -489,6 +489,8 @@ public class HandleConstructor { JCReturn returnStatement = maker.Return(maker.NewClass(null, List.<JCExpression>nil(), constructorType, args.toList(), null)); JCBlock body = maker.Block(0, List.<JCStatement>of(returnStatement)); - return recursiveSetGeneratedBy(maker.MethodDef(mods, typeNode.toName(name), returnType, typeParams.toList(), params.toList(), List.<JCExpression>nil(), body, null), source, typeNode.getContext()); + JCMethodDecl methodDef = maker.MethodDef(mods, typeNode.toName(name), returnType, typeParams.toList(), params.toList(), List.<JCExpression>nil(), body, null); + createRelevantNonNullAnnotation(typeNode, methodDef); + return recursiveSetGeneratedBy(methodDef, source, typeNode.getContext()); } } diff --git a/src/core/lombok/javac/handlers/HandleSetter.java b/src/core/lombok/javac/handlers/HandleSetter.java index 32bf574b..82c95719 100644 --- a/src/core/lombok/javac/handlers/HandleSetter.java +++ b/src/core/lombok/javac/handlers/HandleSetter.java @@ -277,8 +277,10 @@ public class HandleSetter extends JavacAnnotationHandler<Setter> { annsOnMethod = annsOnMethod.prepend(treeMaker.Annotation(genJavaLangTypeRef(field, "Deprecated"), List.<JCExpression>nil())); } - JCMethodDecl decl = recursiveSetGeneratedBy(treeMaker.MethodDef(treeMaker.Modifiers(access, annsOnMethod), methodName, methodType, - methodGenericParams, parameters, throwsClauses, methodBody, annotationMethodDefaultValue), source.get(), field.getContext()); + JCMethodDecl methodDef = treeMaker.MethodDef(treeMaker.Modifiers(access, annsOnMethod), methodName, methodType, + methodGenericParams, parameters, throwsClauses, methodBody, annotationMethodDefaultValue); + if (returnStatement != null) createRelevantNonNullAnnotation(source, methodDef); + JCMethodDecl decl = recursiveSetGeneratedBy(methodDef, source.get(), field.getContext()); copyJavadoc(field, decl, CopyJavadoc.SETTER, returnStatement != null); return decl; } diff --git a/src/core/lombok/javac/handlers/HandleSuperBuilder.java b/src/core/lombok/javac/handlers/HandleSuperBuilder.java index b4b75d79..ba330325 100644 --- a/src/core/lombok/javac/handlers/HandleSuperBuilder.java +++ b/src/core/lombok/javac/handlers/HandleSuperBuilder.java @@ -569,7 +569,9 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> { JCTypeApply returnType = maker.TypeApply(namePlusTypeParamsToTypeReference(maker, type, type.toName(builderClassName), false, List.<JCTypeParameter>nil()), typeParameterNames.toList()); List<JCAnnotation> annsOnMethod = cfv.generateUnique() ? List.of(maker.Annotation(genTypeRef(type, CheckerFrameworkVersion.NAME__SIDE_EFFECT_FREE), List.<JCExpression>nil())) : List.<JCAnnotation>nil(); - return maker.MethodDef(maker.Modifiers(modifiers, annsOnMethod), type.toName(builderMethodName), returnType, copyTypeParams(source, typeParams), List.<JCVariableDecl>nil(), List.<JCExpression>nil(), body, null); + JCMethodDecl methodDef = maker.MethodDef(maker.Modifiers(modifiers, annsOnMethod), type.toName(builderMethodName), returnType, copyTypeParams(source, typeParams), List.<JCVariableDecl>nil(), List.<JCExpression>nil(), body, null); + createRelevantNonNullAnnotation(type, methodDef); + return methodDef; } /** @@ -604,7 +606,9 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> { JCTypeApply returnType = maker.TypeApply(namePlusTypeParamsToTypeReference(maker, type, type.toName(builderClassName), false, List.<JCTypeParameter>nil()), typeParameterNames.toList()); List<JCAnnotation> annsOnMethod = cfv.generateUnique() ? List.of(maker.Annotation(genTypeRef(type, CheckerFrameworkVersion.NAME__SIDE_EFFECT_FREE), List.<JCExpression>nil())) : List.<JCAnnotation>nil(); - return maker.MethodDef(maker.Modifiers(modifiers, annsOnMethod), type.toName(TO_BUILDER_METHOD_NAME), returnType, List.<JCTypeParameter>nil(), List.<JCVariableDecl>nil(), List.<JCExpression>nil(), body, null); + JCMethodDecl methodDef = maker.MethodDef(maker.Modifiers(modifiers, annsOnMethod), type.toName(TO_BUILDER_METHOD_NAME), returnType, List.<JCTypeParameter>nil(), List.<JCVariableDecl>nil(), List.<JCExpression>nil(), body, null); + createRelevantNonNullAnnotation(type, methodDef); + return methodDef; } /** @@ -808,7 +812,9 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> { JCModifiers modifiers = maker.Modifiers(Flags.PUBLIC, annsOnMethod); List<JCVariableDecl> params = HandleBuilder.generateBuildArgs(cfv, type, builderFields); - return maker.MethodDef(modifiers, type.toName(buildName), cloneSelfType(returnType), List.<JCTypeParameter>nil(), params, thrownExceptions, body, null); + JCMethodDecl methodDef = maker.MethodDef(modifiers, type.toName(buildName), cloneSelfType(returnType), List.<JCTypeParameter>nil(), params, thrownExceptions, body, null); + createRelevantNonNullAnnotation(type, methodDef); + return methodDef; } private JCMethodDecl generateCleanMethod(java.util.List<BuilderFieldData> builderFields, JavacNode type, JCTree source) { diff --git a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java index f4128f12..ba052b5a 100644 --- a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java +++ b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java @@ -288,6 +288,7 @@ public class JavacSingularsRecipes { JCMethodDecl method = maker.MethodDef(mods, methodName, returnType, typeParams, jcVariableDecls, thrown, body, null); recursiveSetGeneratedBy(method, source, builderType.getContext()); + if (returnStatement != null) createRelevantNonNullAnnotation(builderType, method); injectMethod(builderType, method); } diff --git a/test/transform/resource/after-delombok/BuilderSingularNullBehavior1.java b/test/transform/resource/after-delombok/BuilderSingularNullBehavior1.java index 55420ac2..32ad0a68 100644 --- a/test/transform/resource/after-delombok/BuilderSingularNullBehavior1.java +++ b/test/transform/resource/after-delombok/BuilderSingularNullBehavior1.java @@ -18,31 +18,31 @@ class BuilderSingularNullBehavior1 { BuilderSingularNullBehavior1Builder() { } @java.lang.SuppressWarnings("all") - public BuilderSingularNullBehavior1.BuilderSingularNullBehavior1Builder name(final String name) { + public BuilderSingularNullBehavior1.@org.checkerframework.checker.nullness.qual.NonNull BuilderSingularNullBehavior1Builder name(final String name) { if (this.names == null) this.names = new java.util.ArrayList<String>(); this.names.add(name); return this; } @java.lang.SuppressWarnings("all") - public BuilderSingularNullBehavior1.BuilderSingularNullBehavior1Builder names(final java.util.@org.checkerframework.checker.nullness.qual.NonNull Collection<? extends String> names) { + public BuilderSingularNullBehavior1.@org.checkerframework.checker.nullness.qual.NonNull BuilderSingularNullBehavior1Builder names(final java.util.@org.checkerframework.checker.nullness.qual.NonNull Collection<? extends String> names) { assert names != null : "names cannot be null"; if (this.names == null) this.names = new java.util.ArrayList<String>(); this.names.addAll(names); return this; } @java.lang.SuppressWarnings("all") - public BuilderSingularNullBehavior1.BuilderSingularNullBehavior1Builder clearNames() { + public BuilderSingularNullBehavior1.@org.checkerframework.checker.nullness.qual.NonNull BuilderSingularNullBehavior1Builder clearNames() { if (this.names != null) this.names.clear(); return this; } @java.lang.SuppressWarnings("all") - public BuilderSingularNullBehavior1.BuilderSingularNullBehavior1Builder location(final String location) { + public BuilderSingularNullBehavior1.@org.checkerframework.checker.nullness.qual.NonNull BuilderSingularNullBehavior1Builder location(final String location) { if (this.locations == null) this.locations = new java.util.ArrayList<String>(); this.locations.add(location); return this; } @java.lang.SuppressWarnings("all") - public BuilderSingularNullBehavior1.BuilderSingularNullBehavior1Builder locations(final java.util.@org.checkerframework.checker.nullness.qual.Nullable Collection<? extends String> locations) { + public BuilderSingularNullBehavior1.@org.checkerframework.checker.nullness.qual.NonNull BuilderSingularNullBehavior1Builder locations(final java.util.@org.checkerframework.checker.nullness.qual.Nullable Collection<? extends String> locations) { if (locations != null) { if (this.locations == null) this.locations = new java.util.ArrayList<String>(); this.locations.addAll(locations); @@ -50,10 +50,11 @@ class BuilderSingularNullBehavior1 { return this; } @java.lang.SuppressWarnings("all") - public BuilderSingularNullBehavior1.BuilderSingularNullBehavior1Builder clearLocations() { + public BuilderSingularNullBehavior1.@org.checkerframework.checker.nullness.qual.NonNull BuilderSingularNullBehavior1Builder clearLocations() { if (this.locations != null) this.locations.clear(); return this; } + @org.checkerframework.checker.nullness.qual.NonNull @java.lang.SuppressWarnings("all") public BuilderSingularNullBehavior1 build() { java.util.List<String> names; @@ -87,7 +88,7 @@ class BuilderSingularNullBehavior1 { } } @java.lang.SuppressWarnings("all") - public static BuilderSingularNullBehavior1.BuilderSingularNullBehavior1Builder builder() { + public static BuilderSingularNullBehavior1.@org.checkerframework.checker.nullness.qual.NonNull BuilderSingularNullBehavior1Builder builder() { return new BuilderSingularNullBehavior1.BuilderSingularNullBehavior1Builder(); } } diff --git a/test/transform/resource/after-delombok/BuilderSingularNullBehavior2.java b/test/transform/resource/after-delombok/BuilderSingularNullBehavior2.java index ba70002b..e70877bf 100644 --- a/test/transform/resource/after-delombok/BuilderSingularNullBehavior2.java +++ b/test/transform/resource/after-delombok/BuilderSingularNullBehavior2.java @@ -12,12 +12,14 @@ class BuilderSingularNullBehavior2 { @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior2Builder() { } + @org.springframework.lang.NonNull @java.lang.SuppressWarnings("all") public BuilderSingularNullBehavior2.BuilderSingularNullBehavior2Builder location(final String location) { if (this.locations == null) this.locations = new java.util.ArrayList<String>(); this.locations.add(location); return this; } + @org.springframework.lang.NonNull @java.lang.SuppressWarnings("all") public BuilderSingularNullBehavior2.BuilderSingularNullBehavior2Builder locations(@org.springframework.lang.NonNull final java.util.Collection<? extends String> locations) { java.util.Objects.requireNonNull(locations, "locations cannot be null"); @@ -25,11 +27,13 @@ class BuilderSingularNullBehavior2 { this.locations.addAll(locations); return this; } + @org.springframework.lang.NonNull @java.lang.SuppressWarnings("all") public BuilderSingularNullBehavior2.BuilderSingularNullBehavior2Builder clearLocations() { if (this.locations != null) this.locations.clear(); return this; } + @org.springframework.lang.NonNull @java.lang.SuppressWarnings("all") public BuilderSingularNullBehavior2 build() { java.util.List<String> locations; @@ -52,6 +56,7 @@ class BuilderSingularNullBehavior2 { return "BuilderSingularNullBehavior2.BuilderSingularNullBehavior2Builder(locations=" + this.locations + ")"; } } + @org.springframework.lang.NonNull @java.lang.SuppressWarnings("all") public static BuilderSingularNullBehavior2.BuilderSingularNullBehavior2Builder builder() { return new BuilderSingularNullBehavior2.BuilderSingularNullBehavior2Builder(); diff --git a/test/transform/resource/after-delombok/StaticConstructor.java b/test/transform/resource/after-delombok/StaticConstructor.java new file mode 100644 index 00000000..f9c862d7 --- /dev/null +++ b/test/transform/resource/after-delombok/StaticConstructor.java @@ -0,0 +1,12 @@ +public class StaticConstructor { + String name; + @java.lang.SuppressWarnings("all") + private StaticConstructor(final String name) { + this.name = name; + } + @org.checkerframework.checker.nullness.qual.NonNull + @java.lang.SuppressWarnings("all") + public static StaticConstructor of(final String name) { + return new StaticConstructor(name); + } +}
\ No newline at end of file diff --git a/test/transform/resource/after-delombok/WithPlain.java b/test/transform/resource/after-delombok/WithPlain.java index 1a6ff22f..01fca04e 100644 --- a/test/transform/resource/after-delombok/WithPlain.java +++ b/test/transform/resource/after-delombok/WithPlain.java @@ -5,10 +5,12 @@ class WithPlain { this.i = i; this.foo = foo; } + @org.springframework.lang.NonNull @java.lang.SuppressWarnings("all") public WithPlain withI(final int i) { return this.i == i ? this : new WithPlain(i, this.foo); } + @org.springframework.lang.NonNull @java.lang.SuppressWarnings("all") public WithPlain withFoo(final int foo) { return this.foo == foo ? this : new WithPlain(this.i, foo); diff --git a/test/transform/resource/after-ecj/BuilderSingularNullBehavior1.java b/test/transform/resource/after-ecj/BuilderSingularNullBehavior1.java index a0725f8a..94ef45eb 100644 --- a/test/transform/resource/after-ecj/BuilderSingularNullBehavior1.java +++ b/test/transform/resource/after-ecj/BuilderSingularNullBehavior1.java @@ -8,31 +8,31 @@ import lombok.Singular; @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior1Builder() { super(); } - public @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior1.BuilderSingularNullBehavior1Builder name(final String name) { + public @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior1.@org.checkerframework.checker.nullness.qual.NonNull BuilderSingularNullBehavior1Builder name(final String name) { if ((this.names == null)) this.names = new java.util.ArrayList<String>(); this.names.add(name); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior1.BuilderSingularNullBehavior1Builder names(final java.util. @org.checkerframework.checker.nullness.qual.NonNull Collection<? extends String> names) { + public @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior1.@org.checkerframework.checker.nullness.qual.NonNull BuilderSingularNullBehavior1Builder names(final java.util. @org.checkerframework.checker.nullness.qual.NonNull Collection<? extends String> names) { assert (names != null): "names cannot be null"; if ((this.names == null)) this.names = new java.util.ArrayList<String>(); this.names.addAll(names); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior1.BuilderSingularNullBehavior1Builder clearNames() { + public @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior1.@org.checkerframework.checker.nullness.qual.NonNull BuilderSingularNullBehavior1Builder clearNames() { if ((this.names != null)) this.names.clear(); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior1.BuilderSingularNullBehavior1Builder location(final String location) { + public @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior1.@org.checkerframework.checker.nullness.qual.NonNull BuilderSingularNullBehavior1Builder location(final String location) { if ((this.locations == null)) this.locations = new java.util.ArrayList<String>(); this.locations.add(location); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior1.BuilderSingularNullBehavior1Builder locations(final java.util. @org.checkerframework.checker.nullness.qual.Nullable Collection<? extends String> locations) { + public @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior1.@org.checkerframework.checker.nullness.qual.NonNull BuilderSingularNullBehavior1Builder locations(final java.util. @org.checkerframework.checker.nullness.qual.Nullable Collection<? extends String> locations) { if ((locations != null)) { if ((this.locations == null)) @@ -41,12 +41,12 @@ import lombok.Singular; } return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior1.BuilderSingularNullBehavior1Builder clearLocations() { + public @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior1.@org.checkerframework.checker.nullness.qual.NonNull BuilderSingularNullBehavior1Builder clearLocations() { if ((this.locations != null)) this.locations.clear(); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior1 build() { + public @org.checkerframework.checker.nullness.qual.NonNull @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior1 build() { java.util.List<String> names; switch (((this.names == null) ? 0 : this.names.size())) { case 0 : @@ -82,7 +82,7 @@ import lombok.Singular; this.names = names; this.locations = locations; } - public static @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior1.BuilderSingularNullBehavior1Builder builder() { + public static @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior1.@org.checkerframework.checker.nullness.qual.NonNull BuilderSingularNullBehavior1Builder builder() { return new BuilderSingularNullBehavior1.BuilderSingularNullBehavior1Builder(); } }
\ No newline at end of file diff --git a/test/transform/resource/after-ecj/BuilderSingularNullBehavior2.java b/test/transform/resource/after-ecj/BuilderSingularNullBehavior2.java index 85f9fb21..cf4bd91b 100644 --- a/test/transform/resource/after-ecj/BuilderSingularNullBehavior2.java +++ b/test/transform/resource/after-ecj/BuilderSingularNullBehavior2.java @@ -6,25 +6,25 @@ import lombok.Singular; @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior2Builder() { super(); } - public @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior2.BuilderSingularNullBehavior2Builder location(final String location) { + public @org.springframework.lang.NonNull @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior2.BuilderSingularNullBehavior2Builder location(final String location) { if ((this.locations == null)) this.locations = new java.util.ArrayList<String>(); this.locations.add(location); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior2.BuilderSingularNullBehavior2Builder locations(final @org.springframework.lang.NonNull java.util.Collection<? extends String> locations) { + public @org.springframework.lang.NonNull @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior2.BuilderSingularNullBehavior2Builder locations(final @org.springframework.lang.NonNull java.util.Collection<? extends String> locations) { java.util.Objects.requireNonNull(locations, "locations cannot be null"); if ((this.locations == null)) this.locations = new java.util.ArrayList<String>(); this.locations.addAll(locations); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior2.BuilderSingularNullBehavior2Builder clearLocations() { + public @org.springframework.lang.NonNull @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior2.BuilderSingularNullBehavior2Builder clearLocations() { if ((this.locations != null)) this.locations.clear(); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior2 build() { + public @org.springframework.lang.NonNull @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior2 build() { java.util.List<String> locations; switch (((this.locations == null) ? 0 : this.locations.size())) { case 0 : @@ -47,7 +47,7 @@ import lombok.Singular; super(); this.locations = locations; } - public static @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior2.BuilderSingularNullBehavior2Builder builder() { + public static @org.springframework.lang.NonNull @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior2.BuilderSingularNullBehavior2Builder builder() { return new BuilderSingularNullBehavior2.BuilderSingularNullBehavior2Builder(); } }
\ No newline at end of file diff --git a/test/transform/resource/after-ecj/StaticConstructor.java b/test/transform/resource/after-ecj/StaticConstructor.java new file mode 100644 index 00000000..93308faa --- /dev/null +++ b/test/transform/resource/after-ecj/StaticConstructor.java @@ -0,0 +1,11 @@ +import lombok.AllArgsConstructor; +public @AllArgsConstructor(staticName = "of") class StaticConstructor { + String name; + private @java.lang.SuppressWarnings("all") StaticConstructor(final String name) { + super(); + this.name = name; + } + public static @org.checkerframework.checker.nullness.qual.NonNull @java.lang.SuppressWarnings("all") StaticConstructor of(final String name) { + return new StaticConstructor(name); + } +}
\ No newline at end of file diff --git a/test/transform/resource/after-ecj/WithPlain.java b/test/transform/resource/after-ecj/WithPlain.java index 4203f540..66a1455b 100644 --- a/test/transform/resource/after-ecj/WithPlain.java +++ b/test/transform/resource/after-ecj/WithPlain.java @@ -7,10 +7,10 @@ class WithPlain { this.i = i; this.foo = foo; } - public @java.lang.SuppressWarnings("all") WithPlain withI(final int i) { + public @org.springframework.lang.NonNull @java.lang.SuppressWarnings("all") WithPlain withI(final int i) { return ((this.i == i) ? this : new WithPlain(i, this.foo)); } - public @java.lang.SuppressWarnings("all") WithPlain withFoo(final int foo) { + public @org.springframework.lang.NonNull @java.lang.SuppressWarnings("all") WithPlain withFoo(final int foo) { return ((this.foo == foo) ? this : new WithPlain(this.i, foo)); } } diff --git a/test/transform/resource/before/StaticConstructor.java b/test/transform/resource/before/StaticConstructor.java new file mode 100644 index 00000000..eff1fa9b --- /dev/null +++ b/test/transform/resource/before/StaticConstructor.java @@ -0,0 +1,6 @@ +//CONF: lombok.addNullAnnotations = checkerframework +import lombok.AllArgsConstructor; +@AllArgsConstructor(staticName = "of") +public class StaticConstructor { + String name; +} diff --git a/test/transform/resource/before/ValueStaticConstructorOf.java b/test/transform/resource/before/ValueStaticConstructorOf.java index ac857ffd..bd318d40 100644 --- a/test/transform/resource/before/ValueStaticConstructorOf.java +++ b/test/transform/resource/before/ValueStaticConstructorOf.java @@ -1,12 +1,11 @@ import lombok.Value; @Value(staticConstructor = "of") public class ValueStaticConstructorOf { + String name; + Double price; - String name; - Double price; - - private ValueStaticConstructorOf(String name, Double price) { - this.name = name; - this.price = price; - } + private ValueStaticConstructorOf(String name, Double price) { + this.name = name; + this.price = price; + } } diff --git a/test/transform/resource/before/WithPlain.java b/test/transform/resource/before/WithPlain.java index 1b2a19c4..4f048242 100644 --- a/test/transform/resource/before/WithPlain.java +++ b/test/transform/resource/before/WithPlain.java @@ -1,3 +1,4 @@ +//CONF: lombok.addNullAnnotations = spring import lombok.With; class WithPlain { @lombok.With int i; |