From c42bfbae39990b365a5f05eb23895da6203023bc Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Fri, 31 Jan 2020 06:33:33 +0100 Subject: [issue #2221] simplified configuration for `@Singular`-generated plural form nullchecks. --- doc/changelog.markdown | 2 +- src/core/lombok/ConfigurationKeys.java | 14 +--- src/core/lombok/Singular.java | 67 +-------------- .../core/configuration/NullCheckExceptionType.java | 5 +- .../eclipse/handlers/EclipseHandlerUtil.java | 10 +-- .../eclipse/handlers/EclipseSingularsRecipes.java | 52 +++--------- .../lombok/eclipse/handlers/HandleBuilder.java | 15 +--- .../lombok/eclipse/handlers/HandleConstructor.java | 2 +- .../lombok/eclipse/handlers/HandleNonNull.java | 2 +- src/core/lombok/eclipse/handlers/HandleSetter.java | 2 +- .../eclipse/handlers/HandleSuperBuilder.java | 6 +- src/core/lombok/eclipse/handlers/HandleWith.java | 2 +- src/core/lombok/javac/handlers/HandleBuilder.java | 16 +--- src/core/lombok/javac/handlers/HandleSetter.java | 2 +- .../lombok/javac/handlers/HandleSuperBuilder.java | 4 +- .../lombok/javac/handlers/JavacHandlerUtil.java | 8 +- .../javac/handlers/JavacSingularsRecipes.java | 48 +++++------ .../after-delombok/BuilderDefaultsWarnings.java | 4 +- .../BuilderSingularAnnotatedTypes.java | 8 +- ...lderSingularAnnotatedTypesWithSetterPrefix.java | 8 +- .../BuilderSingularGuavaListsSets.java | 20 +++-- .../after-delombok/BuilderSingularGuavaMaps.java | 12 ++- .../after-delombok/BuilderSingularLists.java | 12 ++- .../after-delombok/BuilderSingularMaps.java | 16 +++- .../BuilderSingularMapsWithSetterPrefix.java | 57 ++++++------- .../after-delombok/BuilderSingularNoAuto.java | 12 ++- .../BuilderSingularNoAutoWithSetterPrefix.java | 12 ++- .../BuilderSingularNullBehavior1.java | 91 +++------------------ .../BuilderSingularNullBehavior2.java | 52 ++---------- .../BuilderSingularRedirectToGuava.java | 12 ++- .../after-delombok/BuilderSingularSets.java | 16 +++- .../BuilderSingularSetsWithSetterPrefix.java | 16 +++- .../BuilderSingularToBuilderWithNull.java | 4 +- ...rSingularToBuilderWithNullWithSetterPrefix.java | 4 +- .../BuilderSingularWildcardListsWithToBuilder.java | 8 +- .../BuilderSingularWithPrefixes.java | 4 +- ...uilderSingularWithPrefixesWithSetterPrefix.java | 4 +- .../after-delombok/BuilderWithDeprecated.java | 8 +- .../after-delombok/BuilderWithToBuilder.java | 4 +- .../after-delombok/CheckerFrameworkBuilder.java | 4 +- .../CheckerFrameworkSuperBuilder.java | 4 +- .../resource/after-delombok/SuperBuilderBasic.java | 4 +- .../after-delombok/SuperBuilderBasicToBuilder.java | 4 +- .../SuperBuilderSingularAnnotatedTypes.java | 8 +- .../SuperBuilderWithCustomBuilderMethod.java | 4 +- .../after-delombok/SuperBuilderWithGenerics.java | 4 +- .../after-delombok/SuperBuilderWithGenerics2.java | 4 +- .../SuperBuilderWithGenericsAndToBuilder.java | 4 +- .../after-delombok/SuperBuilderWithPrefixes.java | 4 +- .../after-ecj/BuilderDefaultsWarnings.java | 4 +- .../after-ecj/BuilderSingularAnnotatedTypes.java | 8 +- ...lderSingularAnnotatedTypesWithSetterPrefix.java | 8 +- .../after-ecj/BuilderSingularGuavaListsSets.java | 20 +++-- .../after-ecj/BuilderSingularGuavaMaps.java | 12 ++- .../resource/after-ecj/BuilderSingularLists.java | 12 ++- .../resource/after-ecj/BuilderSingularMaps.java | 16 +++- .../BuilderSingularMapsWithSetterPrefix.java | 71 ++++++++-------- .../resource/after-ecj/BuilderSingularNoAuto.java | 12 ++- .../BuilderSingularNoAutoWithSetterPrefix.java | 12 ++- .../after-ecj/BuilderSingularNullBehavior1.java | 94 ++++------------------ .../after-ecj/BuilderSingularNullBehavior2.java | 49 ++--------- .../after-ecj/BuilderSingularRedirectToGuava.java | 12 ++- .../resource/after-ecj/BuilderSingularSets.java | 16 +++- .../BuilderSingularSetsWithSetterPrefix.java | 16 +++- .../BuilderSingularToBuilderWithNull.java | 4 +- ...rSingularToBuilderWithNullWithSetterPrefix.java | 4 +- .../BuilderSingularWildcardListsWithToBuilder.java | 8 +- .../after-ecj/BuilderSingularWithPrefixes.java | 4 +- ...uilderSingularWithPrefixesWithSetterPrefix.java | 4 +- .../resource/after-ecj/BuilderWithDeprecated.java | 8 +- .../resource/after-ecj/BuilderWithToBuilder.java | 4 +- .../after-ecj/CheckerFrameworkBuilder.java | 4 +- .../after-ecj/CheckerFrameworkSuperBuilder.java | 4 +- .../resource/after-ecj/SuperBuilderBasic.java | 4 +- .../after-ecj/SuperBuilderBasicToBuilder.java | 4 +- .../SuperBuilderSingularAnnotatedTypes.java | 8 +- .../SuperBuilderWithCustomBuilderMethod.java | 4 +- .../after-ecj/SuperBuilderWithGenerics.java | 4 +- .../after-ecj/SuperBuilderWithGenerics2.java | 4 +- .../SuperBuilderWithGenericsAndToBuilder.java | 4 +- .../after-ecj/SuperBuilderWithPrefixes.java | 4 +- .../BuilderSingularMapsWithSetterPrefix.java | 3 +- .../before/BuilderSingularNullBehavior1.java | 7 +- .../before/BuilderSingularNullBehavior2.java | 7 +- website/templates/features/Builder.html | 16 ++-- 85 files changed, 517 insertions(+), 643 deletions(-) diff --git a/doc/changelog.markdown b/doc/changelog.markdown index 1a549866..f1980523 100644 --- a/doc/changelog.markdown +++ b/doc/changelog.markdown @@ -6,7 +6,7 @@ Lombok Changelog * PLATFORM: Support for JDK14 (including `pattern match` instanceof expressions). * 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, and you can choose other behaviors as well via a parameter on the `@Singular` annotation and via `lombok.config`; you can even choose treat them as empty collections; 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: 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) * 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! diff --git a/src/core/lombok/ConfigurationKeys.java b/src/core/lombok/ConfigurationKeys.java index 86cb4650..49613fc4 100644 --- a/src/core/lombok/ConfigurationKeys.java +++ b/src/core/lombok/ConfigurationKeys.java @@ -23,7 +23,6 @@ package lombok; import java.util.List; -import lombok.Singular.NullCollectionBehavior; import lombok.core.configuration.CallSuperType; import lombok.core.configuration.CheckerFrameworkVersion; import lombok.core.configuration.ConfigurationKey; @@ -317,18 +316,6 @@ public class ConfigurationKeys { */ public static final ConfigurationKey SINGULAR_AUTO = new ConfigurationKey("lombok.singular.auto", "If true (default): Automatically singularize the assumed-to-be-plural name of your variable/parameter when using @Singular.") {}; - /** - * lombok configuration: {@code lombok.singular.nullCollections} = one of: [{@code NullPointerException}, {@code IllegalArgumentException}, {@code JDK}, {@code Guava}, or {@code ignore}]. - * - * Lombok generates a 'plural form' method, which takes in a collection and will add each element in it to the {@code @Singular} marked target. What should happen if {@code null} is passed instead of a collection instance?
    - *
  • If the chosen configuration is {@code NullPointerException} (the default), or {@code IllegalArgumentException}, that exception type is a thrown, with as message field-name must not be null.
  • - *
  • If the chosen configuration is {@code JDK}, a call to {@code java.util.Objects.requireNonNull} is generated with the fieldname passed along (which throws {@code NullPointerException}).
  • - *
  • If the chosen configuration is {@code Guava}, a call to {@code com.google.common.base.Preconditions.checkNotNull} is generated with the fieldname passed along (which throws {@code NullPointerException}).
  • - *
  • If the chosen configuration is {@code Ignore}, then no exception occurs, and the call does nothing; it acts as if an empty collection was passed.
  • - *
- */ - public static final ConfigurationKey SINGULAR_NULL_COLLECTIONS = new ConfigurationKey("lombok.singular.nullCollections", "Lombok generates a method to add all elements in a collection when using @Singular. What should happen if a null ref is passed? default: throw NullPointerException.") {}; - // ##### Standalones ##### // ----- Cleanup ----- @@ -360,6 +347,7 @@ public class ConfigurationKeys { *
  • If the chosen configuration is {@code JDK}, a call to {@code java.util.Objects.requireNonNull} is generated with the fieldname passed along (which throws {@code NullPointerException}).
  • *
  • If the chosen configuration is {@code Guava}, a call to {@code com.google.common.base.Preconditions.checkNotNull} is generated with the fieldname passed along (which throws {@code NullPointerException}).
  • * + * NB: The chosen nullcheck style is also used by {@code @Builder}'s {@code @Singular} annotation to check any collections passed to a plural-form method. */ public static final ConfigurationKey NON_NULL_EXCEPTION_TYPE = new ConfigurationKey("lombok.nonNull.exceptionType", "The type of the exception to throw if a passed-in argument is null (Default: NullPointerException).") {}; diff --git a/src/core/lombok/Singular.java b/src/core/lombok/Singular.java index f8cf6853..2ceaad58 100644 --- a/src/core/lombok/Singular.java +++ b/src/core/lombok/Singular.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015-2017 The Project Lombok Authors. + * Copyright (C) 2015-2020 The Project Lombok Authors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -27,10 +27,6 @@ import static java.lang.annotation.RetentionPolicy.*; import java.lang.annotation.Retention; import java.lang.annotation.Target; -import lombok.core.LombokImmutableList; -import lombok.core.configuration.ExampleValueString; -import lombok.core.configuration.NullCheckExceptionType; - /** * The singular annotation is used together with {@code @Builder} to create single element 'add' methods in the builder for collections. */ @@ -40,63 +36,6 @@ public @interface Singular { /** @return The singular name of this field. If it's a normal english plural, lombok will figure it out automatically. Otherwise, this parameter is mandatory. */ String value() default ""; - NullCollectionBehavior nullBehavior() default NullCollectionBehavior.NULL_POINTER_EXCEPTION; - - @ExampleValueString("[NullPointerException | IllegalArgumentException | JDK | Guava | Ignore]") - public enum NullCollectionBehavior { - ILLEGAL_ARGUMENT_EXCEPTION { - @Override public String getExceptionType() { - return NullCheckExceptionType.ILLEGAL_ARGUMENT_EXCEPTION.getExceptionType(); - } - - @Override public LombokImmutableList getMethod() { - return NullCheckExceptionType.ILLEGAL_ARGUMENT_EXCEPTION.getMethod(); - } - }, - NULL_POINTER_EXCEPTION { - @Override public String getExceptionType() { - return NullCheckExceptionType.NULL_POINTER_EXCEPTION.getExceptionType(); - } - - @Override public LombokImmutableList getMethod() { - return NullCheckExceptionType.NULL_POINTER_EXCEPTION.getMethod(); - } - }, - JDK { - @Override public String getExceptionType() { - return NullCheckExceptionType.JDK.getExceptionType(); - } - - @Override public LombokImmutableList getMethod() { - return NullCheckExceptionType.JDK.getMethod(); - } - }, - GUAVA { - @Override public String getExceptionType() { - return NullCheckExceptionType.GUAVA.getExceptionType(); - } - - @Override public LombokImmutableList getMethod() { - return NullCheckExceptionType.GUAVA.getMethod(); - } - }, - IGNORE { - @Override public String getExceptionType() { - return null; - } - - @Override public LombokImmutableList getMethod() { - return null; - } - }; - - - public String toExceptionMessage(String fieldName) { - return fieldName + " cannot be null"; - } - - public abstract String getExceptionType(); - - public abstract LombokImmutableList getMethod(); - } + /** @return If true, the plural variant (which takes a collection and adds each element inside) will treat {@code null} as an empty collection, i.e. do nothing. If {@code false) (the default), it is null checked as if annotated with {@code @lombok.NonNull}. */ + boolean ignoreNullCollections() default false; } diff --git a/src/core/lombok/core/configuration/NullCheckExceptionType.java b/src/core/lombok/core/configuration/NullCheckExceptionType.java index 4632916c..2c1b7ce6 100644 --- a/src/core/lombok/core/configuration/NullCheckExceptionType.java +++ b/src/core/lombok/core/configuration/NullCheckExceptionType.java @@ -74,8 +74,9 @@ public enum NullCheckExceptionType { private static final LombokImmutableList METHOD_JDK = LombokImmutableList.of("java", "util", "Objects", "requireNonNull"); private static final LombokImmutableList METHOD_GUAVA = LombokImmutableList.of("com", "google", "common", "base", "Preconditions", "checkNotNull"); - public String toExceptionMessage(String fieldName) { - return fieldName + " is marked non-null but is null"; + public String toExceptionMessage(String fieldName, String customMessage) { + if (customMessage == null) return fieldName + " is marked non-null but is null"; + return customMessage.replace("%s", fieldName); } public abstract String getExceptionType(); diff --git a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java index bd0ad23b..bdb88299 100644 --- a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java +++ b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java @@ -1992,7 +1992,7 @@ public class EclipseHandlerUtil { * Generates a new statement that checks if the given local variable is null, and if so, throws a specified exception with the * variable name as message. */ - public static Statement generateNullCheck(TypeReference type, char[] variable, EclipseNode sourceNode) { + public static Statement generateNullCheck(TypeReference type, char[] variable, EclipseNode sourceNode, String customMessage) { NullCheckExceptionType exceptionType = sourceNode.getAst().readConfiguration(ConfigurationKeys.NON_NULL_EXCEPTION_TYPE); if (exceptionType == null) exceptionType = NullCheckExceptionType.NULL_POINTER_EXCEPTION; @@ -2001,11 +2001,11 @@ public class EclipseHandlerUtil { int pS = source.sourceStart, pE = source.sourceEnd; long p = (long) pS << 32 | pE; - if (isPrimitive(type)) return null; + if (type != null && isPrimitive(type)) return null; SingleNameReference varName = new SingleNameReference(variable, p); setGeneratedBy(varName, source); - StringLiteral message = new StringLiteral(exceptionType.toExceptionMessage(new String(variable)).toCharArray(), pS, pE, 0); + StringLiteral message = new StringLiteral(exceptionType.toExceptionMessage(new String(variable), customMessage).toCharArray(), pS, pE, 0); setGeneratedBy(message, source); LombokImmutableList method = exceptionType.getMethod(); @@ -2071,8 +2071,8 @@ public class EclipseHandlerUtil { * * @param exName The name of the exception to throw; normally {@code java.lang.NullPointerException}. */ - public static Statement generateNullCheck(AbstractVariableDeclaration variable, EclipseNode sourceNode) { - return generateNullCheck(variable.type, variable.name, sourceNode); + public static Statement generateNullCheck(AbstractVariableDeclaration variable, EclipseNode sourceNode, String customMessage) { + return generateNullCheck(variable.type, variable.name, sourceNode, customMessage); } /** diff --git a/src/core/lombok/eclipse/handlers/EclipseSingularsRecipes.java b/src/core/lombok/eclipse/handlers/EclipseSingularsRecipes.java index cbbd4cc8..85243ec1 100755 --- a/src/core/lombok/eclipse/handlers/EclipseSingularsRecipes.java +++ b/src/core/lombok/eclipse/handlers/EclipseSingularsRecipes.java @@ -33,7 +33,6 @@ import java.util.Map; import org.eclipse.jdt.internal.compiler.ast.ASTNode; import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration; -import org.eclipse.jdt.internal.compiler.ast.AllocationExpression; import org.eclipse.jdt.internal.compiler.ast.Annotation; import org.eclipse.jdt.internal.compiler.ast.Argument; import org.eclipse.jdt.internal.compiler.ast.Block; @@ -49,16 +48,13 @@ import org.eclipse.jdt.internal.compiler.ast.NullLiteral; import org.eclipse.jdt.internal.compiler.ast.OperatorIds; import org.eclipse.jdt.internal.compiler.ast.ParameterizedQualifiedTypeReference; import org.eclipse.jdt.internal.compiler.ast.ParameterizedSingleTypeReference; -import org.eclipse.jdt.internal.compiler.ast.QualifiedNameReference; import org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference; import org.eclipse.jdt.internal.compiler.ast.Reference; import org.eclipse.jdt.internal.compiler.ast.ReturnStatement; import org.eclipse.jdt.internal.compiler.ast.SingleNameReference; import org.eclipse.jdt.internal.compiler.ast.SingleTypeReference; import org.eclipse.jdt.internal.compiler.ast.Statement; -import org.eclipse.jdt.internal.compiler.ast.StringLiteral; import org.eclipse.jdt.internal.compiler.ast.ThisReference; -import org.eclipse.jdt.internal.compiler.ast.ThrowStatement; import org.eclipse.jdt.internal.compiler.ast.TypeReference; import org.eclipse.jdt.internal.compiler.ast.Wildcard; import org.eclipse.jdt.internal.compiler.lookup.ClassScope; @@ -67,12 +63,10 @@ import org.eclipse.jdt.internal.compiler.lookup.TypeConstants; import org.eclipse.jdt.internal.compiler.lookup.TypeIds; import lombok.AccessLevel; -import lombok.Singular.NullCollectionBehavior; import lombok.core.LombokImmutableList; import lombok.core.SpiLoadUtil; import lombok.core.TypeLibrary; import lombok.core.configuration.CheckerFrameworkVersion; -import lombok.eclipse.Eclipse; import lombok.eclipse.EclipseNode; public class EclipseSingularsRecipes { @@ -135,14 +129,14 @@ public class EclipseSingularsRecipes { private final List typeArgs; private final String targetFqn; private final EclipseSingularizer singularizer; - private final NullCollectionBehavior nullCollectionBehavior; + private final boolean ignoreNullCollections; private final ASTNode source; - public SingularData(EclipseNode annotation, char[] singularName, char[] pluralName, List typeArgs, String targetFqn, EclipseSingularizer singularizer, ASTNode source, NullCollectionBehavior nullCollectionBehavior) { - this(annotation, singularName, pluralName, typeArgs, targetFqn, singularizer, source, nullCollectionBehavior, new char[0]); + public SingularData(EclipseNode annotation, char[] singularName, char[] pluralName, List typeArgs, String targetFqn, EclipseSingularizer singularizer, ASTNode source, boolean ignoreNullCollections) { + this(annotation, singularName, pluralName, typeArgs, targetFqn, singularizer, source, ignoreNullCollections, new char[0]); } - public SingularData(EclipseNode annotation, char[] singularName, char[] pluralName, List typeArgs, String targetFqn, EclipseSingularizer singularizer, ASTNode source, NullCollectionBehavior nullCollectionBehavior, char[] setterPrefix) { + public SingularData(EclipseNode annotation, char[] singularName, char[] pluralName, List typeArgs, String targetFqn, EclipseSingularizer singularizer, ASTNode source, boolean ignoreNullCollections, char[] setterPrefix) { this.annotation = annotation; this.singularName = singularName; this.pluralName = pluralName; @@ -150,7 +144,7 @@ public class EclipseSingularsRecipes { this.targetFqn = targetFqn; this.singularizer = singularizer; this.source = source; - this.nullCollectionBehavior = nullCollectionBehavior; + this.ignoreNullCollections = ignoreNullCollections; this.setterPrefix = setterPrefix; } @@ -198,8 +192,8 @@ public class EclipseSingularsRecipes { return singularizer; } - public NullCollectionBehavior getNullCollectionBehavior() { - return nullCollectionBehavior; + public boolean isIgnoreNullCollections() { + return ignoreNullCollections; } public String getTargetSimpleType() { @@ -439,9 +433,9 @@ public class EclipseSingularsRecipes { } protected void nullBehaviorize(EclipseNode typeNode, SingularData data, List statements, Argument arg) { - NullCollectionBehavior behavior = data.getNullCollectionBehavior(); + boolean ignoreNullCollections = data.isIgnoreNullCollections(); - if (behavior == NullCollectionBehavior.IGNORE) { + if (ignoreNullCollections) { Expression isNotNull = new EqualExpression(new SingleNameReference(data.getPluralName(), 0L), new NullLiteral(0, 0), OperatorIds.NOT_EQUAL); Block b = new Block(0); b.statements = statements.toArray(new Statement[statements.size()]); @@ -452,32 +446,8 @@ public class EclipseSingularsRecipes { } EclipseHandlerUtil.createRelevantNonNullAnnotation(typeNode, arg); - - String exceptionTypeStr = behavior.getExceptionType(); - StringLiteral message = new StringLiteral(behavior.toExceptionMessage(new String(data.getPluralName())).toCharArray(), 0, 0, 0); - if (exceptionTypeStr != null) { - Expression isNull = new EqualExpression(new SingleNameReference(data.getPluralName(), 0L), new NullLiteral(0, 0), OperatorIds.EQUAL_EQUAL); - int partCount = 1; - for (int i = 0; i < exceptionTypeStr.length(); i++) if (exceptionTypeStr.charAt(i) == '.') partCount++; - long[] ps = new long[partCount]; - Arrays.fill(ps, 0L); - AllocationExpression alloc = new AllocationExpression(); - alloc.type = new QualifiedTypeReference(Eclipse.fromQualifiedName(exceptionTypeStr), ps); - alloc.arguments = new Expression[] {message}; - Statement t = new ThrowStatement(alloc, 0, 0); - statements.add(0, new IfStatement(isNull, t, 0, 0)); - return; - } - - MessageSend invoke = new MessageSend(); - LombokImmutableList method = behavior.getMethod(); - char[][] utilityTypeName = new char[method.size() - 1][]; - for (int i = 0; i < method.size() - 1; i++) utilityTypeName[i] = method.get(i).toCharArray(); - - invoke.receiver = new QualifiedNameReference(utilityTypeName, new long[method.size() - 1], 0, 0); - invoke.selector = method.get(method.size() - 1).toCharArray(); - invoke.arguments = new Expression[] {new SingleNameReference(data.getPluralName(), 0L), message}; - statements.add(0, invoke); + Statement nullCheck = EclipseHandlerUtil.generateNullCheck(null, data.getPluralName(), typeNode, "%s cannot be null"); + statements.add(0, nullCheck); } protected abstract char[][] getEmptyMakerReceiver(String targetFqn); diff --git a/src/core/lombok/eclipse/handlers/HandleBuilder.java b/src/core/lombok/eclipse/handlers/HandleBuilder.java index 578fa2a3..19388eda 100755 --- a/src/core/lombok/eclipse/handlers/HandleBuilder.java +++ b/src/core/lombok/eclipse/handlers/HandleBuilder.java @@ -79,7 +79,6 @@ import org.mangosdk.spi.ProviderFor; import lombok.AccessLevel; import lombok.Builder; import lombok.Builder.ObtainVia; -import lombok.Singular.NullCollectionBehavior; import lombok.ConfigurationKeys; import lombok.Singular; import lombok.ToString; @@ -1036,21 +1035,9 @@ public class HandleBuilder extends EclipseAnnotationHandler { return null; } - NullCollectionBehavior behavior = getNullBehaviorFor(ann, singularInstance, node); - return new SingularData(child, singularName, pluralName, typeArgs == null ? Collections.emptyList() : Arrays.asList(typeArgs), targetFqn, singularizer, source, behavior, setterPrefix.toCharArray()); + return new SingularData(child, singularName, pluralName, typeArgs == null ? Collections.emptyList() : Arrays.asList(typeArgs), targetFqn, singularizer, source, singularInstance.ignoreNullCollections(), setterPrefix.toCharArray()); } return null; } - - static NullCollectionBehavior getNullBehaviorFor(AnnotationValues ann, Singular singularInstance, EclipseNode node) { - NullCollectionBehavior behavior; - if (ann.isExplicit("nullBehavior")) { - behavior = singularInstance.nullBehavior(); - } else { - behavior = node.getAst().readConfiguration(ConfigurationKeys.SINGULAR_NULL_COLLECTIONS); - } - if (behavior == null) return NullCollectionBehavior.NULL_POINTER_EXCEPTION; - return behavior; - } } diff --git a/src/core/lombok/eclipse/handlers/HandleConstructor.java b/src/core/lombok/eclipse/handlers/HandleConstructor.java index a5716d9c..f69a2d1c 100755 --- a/src/core/lombok/eclipse/handlers/HandleConstructor.java +++ b/src/core/lombok/eclipse/handlers/HandleConstructor.java @@ -411,7 +411,7 @@ public class HandleConstructor { Argument parameter = new Argument(fieldName, fieldPos, copyType(field.type, source), Modifier.FINAL); Annotation[] copyableAnnotations = findCopyableAnnotations(fieldNode); if (hasNonNullAnnotations(fieldNode)) { - Statement nullCheck = generateNullCheck(parameter, sourceNode); + Statement nullCheck = generateNullCheck(parameter, sourceNode, null); if (nullCheck != null) nullChecks.add(nullCheck); } parameter.annotations = copyAnnotations(source, copyableAnnotations); diff --git a/src/core/lombok/eclipse/handlers/HandleNonNull.java b/src/core/lombok/eclipse/handlers/HandleNonNull.java index c61ce02d..c4d42c2e 100644 --- a/src/core/lombok/eclipse/handlers/HandleNonNull.java +++ b/src/core/lombok/eclipse/handlers/HandleNonNull.java @@ -145,7 +145,7 @@ public class HandleNonNull extends EclipseAnnotationHandler { // and if they exist, create a new method in the class: 'private static T lombok$nullCheck(T expr, String msg) {if (expr == null) throw NPE; return expr;}' and // wrap all references to it in the super/this to a call to this method. - Statement nullCheck = generateNullCheck(param, annotationNode); + Statement nullCheck = generateNullCheck(param, annotationNode, null); if (nullCheck == null) { // @NonNull applied to a primitive. Kinda pointless. Let's generate a warning. diff --git a/src/core/lombok/eclipse/handlers/HandleSetter.java b/src/core/lombok/eclipse/handlers/HandleSetter.java index eda2c271..8ee54d0f 100644 --- a/src/core/lombok/eclipse/handlers/HandleSetter.java +++ b/src/core/lombok/eclipse/handlers/HandleSetter.java @@ -245,7 +245,7 @@ public class HandleSetter extends EclipseAnnotationHandler { if (!hasNonNullAnnotations(fieldNode) && !hasNonNullAnnotations(fieldNode, onParam)) { statements.add(assignment); } else { - Statement nullCheck = generateNullCheck(field.type, paramName, sourceNode); + Statement nullCheck = generateNullCheck(field.type, paramName, sourceNode, null); if (nullCheck != null) statements.add(nullCheck); statements.add(assignment); } diff --git a/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java b/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java index 4b450a07..0a5acd56 100755 --- a/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java +++ b/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java @@ -79,7 +79,6 @@ import org.mangosdk.spi.ProviderFor; import lombok.AccessLevel; import lombok.Builder; import lombok.Builder.ObtainVia; -import lombok.Singular.NullCollectionBehavior; import lombok.ConfigurationKeys; import lombok.Singular; import lombok.ToString; @@ -567,7 +566,7 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler { } if (hasNonNullAnnotations(fieldNode.originalFieldNode)) { - Statement nullCheck = generateNullCheck((FieldDeclaration) fieldNode.originalFieldNode.get(), sourceNode); + Statement nullCheck = generateNullCheck((FieldDeclaration) fieldNode.originalFieldNode.get(), sourceNode, null); if (nullCheck != null) statements.add(nullCheck); } } @@ -1044,8 +1043,7 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler { return null; } - NullCollectionBehavior behavior = HandleBuilder.getNullBehaviorFor(ann, singularInstance, node); - return new SingularData(child, singularName, pluralName, typeArgs == null ? Collections.emptyList() : Arrays.asList(typeArgs), targetFqn, singularizer, source, behavior); + return new SingularData(child, singularName, pluralName, typeArgs == null ? Collections.emptyList() : Arrays.asList(typeArgs), targetFqn, singularizer, source, singularInstance.ignoreNullCollections()); } return null; diff --git a/src/core/lombok/eclipse/handlers/HandleWith.java b/src/core/lombok/eclipse/handlers/HandleWith.java index 4771818d..5cdc02df 100644 --- a/src/core/lombok/eclipse/handlers/HandleWith.java +++ b/src/core/lombok/eclipse/handlers/HandleWith.java @@ -278,7 +278,7 @@ public class HandleWith extends EclipseAnnotationHandler { List statements = new ArrayList(5); if (hasNonNullAnnotations(fieldNode)) { - Statement nullCheck = generateNullCheck(field, sourceNode); + Statement nullCheck = generateNullCheck(field, sourceNode, null); if (nullCheck != null) statements.add(nullCheck); } statements.add(returnStatement); diff --git a/src/core/lombok/javac/handlers/HandleBuilder.java b/src/core/lombok/javac/handlers/HandleBuilder.java index 75f3de2c..5c4b4297 100644 --- a/src/core/lombok/javac/handlers/HandleBuilder.java +++ b/src/core/lombok/javac/handlers/HandleBuilder.java @@ -61,7 +61,6 @@ import lombok.Builder; import lombok.Builder.ObtainVia; import lombok.ConfigurationKeys; import lombok.Singular; -import lombok.Singular.NullCollectionBehavior; import lombok.ToString; import lombok.core.AST.Kind; import lombok.core.AnnotationValues; @@ -908,22 +907,9 @@ public class HandleBuilder extends JavacAnnotationHandler { return null; } - NullCollectionBehavior behavior = getNullBehaviorFor(ann, singularInstance, node); - - return new SingularData(child, singularName, pluralName, typeArgs, targetFqn, singularizer, behavior, setterPrefix); + return new SingularData(child, singularName, pluralName, typeArgs, targetFqn, singularizer, singularInstance.ignoreNullCollections(), setterPrefix); } return null; } - - static NullCollectionBehavior getNullBehaviorFor(AnnotationValues ann, Singular singularInstance, JavacNode node) { - NullCollectionBehavior behavior; - if (ann.isExplicit("nullBehavior")) { - behavior = singularInstance.nullBehavior(); - } else { - behavior = node.getAst().readConfiguration(ConfigurationKeys.SINGULAR_NULL_COLLECTIONS); - } - if (behavior == null) return NullCollectionBehavior.NULL_POINTER_EXCEPTION; - return behavior; - } } diff --git a/src/core/lombok/javac/handlers/HandleSetter.java b/src/core/lombok/javac/handlers/HandleSetter.java index 9c7ce042..32bf574b 100644 --- a/src/core/lombok/javac/handlers/HandleSetter.java +++ b/src/core/lombok/javac/handlers/HandleSetter.java @@ -248,7 +248,7 @@ public class HandleSetter extends JavacAnnotationHandler { if (!hasNonNullAnnotations(field) && !hasNonNullAnnotations(field, onParam)) { statements.append(treeMaker.Exec(assign)); } else { - JCStatement nullCheck = generateNullCheck(treeMaker, fieldDecl.vartype, paramName, source); + JCStatement nullCheck = generateNullCheck(treeMaker, fieldDecl.vartype, paramName, source, null); if (nullCheck != null) statements.append(nullCheck); statements.append(treeMaker.Exec(assign)); } diff --git a/src/core/lombok/javac/handlers/HandleSuperBuilder.java b/src/core/lombok/javac/handlers/HandleSuperBuilder.java index 692ee60b..b4b75d79 100644 --- a/src/core/lombok/javac/handlers/HandleSuperBuilder.java +++ b/src/core/lombok/javac/handlers/HandleSuperBuilder.java @@ -59,7 +59,6 @@ import com.sun.tools.javac.util.Name; import lombok.AccessLevel; import lombok.Builder; import lombok.Builder.ObtainVia; -import lombok.Singular.NullCollectionBehavior; import lombok.ConfigurationKeys; import lombok.Singular; import lombok.ToString; @@ -976,8 +975,7 @@ public class HandleSuperBuilder extends JavacAnnotationHandler { return null; } - NullCollectionBehavior behavior = HandleBuilder.getNullBehaviorFor(ann, singularInstance, node); - return new SingularData(child, singularName, pluralName, typeArgs, targetFqn, singularizer, behavior); + return new SingularData(child, singularName, pluralName, typeArgs, targetFqn, singularizer, singularInstance.ignoreNullCollections()); } return null; diff --git a/src/core/lombok/javac/handlers/JavacHandlerUtil.java b/src/core/lombok/javac/handlers/JavacHandlerUtil.java index 0ef8c359..3ec9f159 100644 --- a/src/core/lombok/javac/handlers/JavacHandlerUtil.java +++ b/src/core/lombok/javac/handlers/JavacHandlerUtil.java @@ -1537,12 +1537,12 @@ public class JavacHandlerUtil { * Generates a new statement that checks if the given local is null, and if so, throws a configured exception with the * local variable name as message. */ - public static JCStatement generateNullCheck(JavacTreeMaker maker, JCExpression typeNode, Name varName, JavacNode source) { + public static JCStatement generateNullCheck(JavacTreeMaker maker, JCExpression typeNode, Name varName, JavacNode source, String customMessage) { NullCheckExceptionType exceptionType = source.getAst().readConfiguration(ConfigurationKeys.NON_NULL_EXCEPTION_TYPE); if (exceptionType == null) exceptionType = NullCheckExceptionType.NULL_POINTER_EXCEPTION; - if (isPrimitive(typeNode)) return null; - JCLiteral message = maker.Literal(exceptionType.toExceptionMessage(varName.toString())); + if (typeNode != null && isPrimitive(typeNode)) return null; + JCLiteral message = maker.Literal(exceptionType.toExceptionMessage(varName.toString(), customMessage)); LombokImmutableList method = exceptionType.getMethod(); if (method != null) { @@ -1569,7 +1569,7 @@ public class JavacHandlerUtil { * stripped as a result of @Accessors.prefix. */ public static JCStatement generateNullCheck(JavacTreeMaker maker, JCVariableDecl varDecl, JavacNode source) { - return generateNullCheck(maker, varDecl.vartype, varDecl.name, source); + return generateNullCheck(maker, varDecl.vartype, varDecl.name, source, null); } /** diff --git a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java index 9dab3da5..f4128f12 100644 --- a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java +++ b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java @@ -37,7 +37,6 @@ import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.tree.JCTree.JCAnnotation; import com.sun.tools.javac.tree.JCTree.JCBlock; import com.sun.tools.javac.tree.JCTree.JCExpression; -import com.sun.tools.javac.tree.JCTree.JCLiteral; import com.sun.tools.javac.tree.JCTree.JCMethodDecl; import com.sun.tools.javac.tree.JCTree.JCModifiers; import com.sun.tools.javac.tree.JCTree.JCStatement; @@ -51,7 +50,6 @@ import com.sun.tools.javac.util.Name; import lombok.AccessLevel; import lombok.ConfigurationKeys; -import lombok.Singular.NullCollectionBehavior; import lombok.core.LombokImmutableList; import lombok.core.SpiLoadUtil; import lombok.core.TypeLibrary; @@ -122,13 +120,13 @@ public class JavacSingularsRecipes { private final String targetFqn; private final JavacSingularizer singularizer; private final String setterPrefix; - private final NullCollectionBehavior nullCollectionBehavior; + private final boolean ignoreNullCollections; - public SingularData(JavacNode annotation, Name singularName, Name pluralName, List typeArgs, String targetFqn, JavacSingularizer singularizer, NullCollectionBehavior nullCollectionBehavior) { - this(annotation, singularName, pluralName, typeArgs, targetFqn, singularizer, nullCollectionBehavior, ""); + public SingularData(JavacNode annotation, Name singularName, Name pluralName, List typeArgs, String targetFqn, JavacSingularizer singularizer, boolean ignoreNullCollections) { + this(annotation, singularName, pluralName, typeArgs, targetFqn, singularizer, ignoreNullCollections, ""); } - public SingularData(JavacNode annotation, Name singularName, Name pluralName, List typeArgs, String targetFqn, JavacSingularizer singularizer, NullCollectionBehavior nullCollectionBehavior, String setterPrefix) { + public SingularData(JavacNode annotation, Name singularName, Name pluralName, List typeArgs, String targetFqn, JavacSingularizer singularizer, boolean ignoreNullCollections, String setterPrefix) { this.annotation = annotation; this.singularName = singularName; this.pluralName = pluralName; @@ -136,7 +134,7 @@ public class JavacSingularsRecipes { this.targetFqn = targetFqn; this.singularizer = singularizer; this.setterPrefix = setterPrefix; - this.nullCollectionBehavior = nullCollectionBehavior; + this.ignoreNullCollections = ignoreNullCollections; } public JavacNode getAnnotation() { @@ -167,8 +165,8 @@ public class JavacSingularsRecipes { return singularizer; } - public NullCollectionBehavior getNullCollectionBehavior() { - return nullCollectionBehavior; + public boolean isIgnoreNullCollections() { + return ignoreNullCollections; } public String getTargetSimpleType() { @@ -273,17 +271,19 @@ public class JavacSingularsRecipes { generateClearMethod(cfv, deprecate, maker, returnTypeMaker.make(), returnStatementMaker.make(), data, builderType, source, access); } - private void finishAndInjectMethod(CheckerFrameworkVersion cfv, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean deprecate, ListBuffer statements, Name methodName, List jcVariableDecls, AccessLevel access, NullCollectionBehavior nullBehavior) { + private void finishAndInjectMethod(CheckerFrameworkVersion cfv, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean deprecate, ListBuffer statements, Name methodName, List jcVariableDecls, AccessLevel access, Boolean ignoreNullCollections) { if (returnStatement != null) statements.append(returnStatement); JCBlock body = maker.Block(0, statements.toList()); JCModifiers mods = makeMods(maker, cfv, builderType, deprecate, access); List typeParams = List.nil(); List thrown = List.nil(); - if (nullBehavior == NullCollectionBehavior.IGNORE) { - for (JCVariableDecl d : jcVariableDecls) createRelevantNullableAnnotation(builderType, d); - } else if (nullBehavior != null) { - for (JCVariableDecl d : jcVariableDecls) createRelevantNonNullAnnotation(builderType, d); + if (ignoreNullCollections != null) { + if (ignoreNullCollections.booleanValue()) { + for (JCVariableDecl d : jcVariableDecls) createRelevantNullableAnnotation(builderType, d); + } else { + for (JCVariableDecl d : jcVariableDecls) createRelevantNonNullAnnotation(builderType, d); + } } JCMethodDecl method = maker.MethodDef(mods, methodName, returnType, typeParams, jcVariableDecls, thrown, body, null); @@ -343,33 +343,21 @@ public class JavacSingularsRecipes { JCExpression paramType = getPluralMethodParamType(builderType); paramType = addTypeArgs(getTypeArgumentsCount(), true, builderType, paramType, data.getTypeArgs(), source); long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext()); - NullCollectionBehavior behavior = data.getNullCollectionBehavior(); - if (behavior == null) behavior = NullCollectionBehavior.IGNORE; + boolean ignoreNullCollections = data.isIgnoreNullCollections(); JCModifiers paramMods = maker.Modifiers(paramFlags); JCVariableDecl param = maker.VarDef(paramMods, data.getPluralName(), paramType, null); statements.prepend(createConstructBuilderVarIfNeeded(maker, data, builderType, source)); - if (behavior == NullCollectionBehavior.IGNORE) { + if (ignoreNullCollections) { JCExpression incomingIsNotNull = maker.Binary(CTC_NOT_EQUAL, maker.Ident(data.getPluralName()), maker.Literal(CTC_BOT, null)); JCStatement onNotNull = maker.Block(0, statements.toList()); statements = new ListBuffer(); statements.add(maker.If(incomingIsNotNull, onNotNull, null)); } else { - JCLiteral message = maker.Literal(behavior.toExceptionMessage(data.getPluralName().toString())); - if (behavior.getExceptionType() != null) { - JCExpression incomingIsNull = maker.Binary(CTC_EQUAL, maker.Ident(data.getPluralName()), maker.Literal(CTC_BOT, null)); - JCExpression exType = genTypeRef(builderType, behavior.getExceptionType()); - JCExpression exception = maker.NewClass(null, List.nil(), exType, List.of(message), null); - JCStatement onNull = maker.Throw(exception); - statements.prepend(maker.If(incomingIsNull, onNull, null)); - } else { - LombokImmutableList method = behavior.getMethod(); - JCExpression invoke = maker.Apply(List.nil(), chainDots(builderType, method), List.of(maker.Ident(data.getPluralName()), message)); - statements.prepend(maker.Exec(invoke)); - } + statements.prepend(JavacHandlerUtil.generateNullCheck(maker, null, data.getPluralName(), builderType, "%s cannot be null")); } - finishAndInjectMethod(cfv, maker, returnType, returnStatement, data, builderType, source, deprecate, statements, name, List.of(param), access, behavior); + finishAndInjectMethod(cfv, maker, returnType, returnStatement, data, builderType, source, deprecate, statements, name, List.of(param), access, ignoreNullCollections); } protected ListBuffer generatePluralMethodStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) { diff --git a/test/transform/resource/after-delombok/BuilderDefaultsWarnings.java b/test/transform/resource/after-delombok/BuilderDefaultsWarnings.java index 04cd3bbb..3c84c71b 100644 --- a/test/transform/resource/after-delombok/BuilderDefaultsWarnings.java +++ b/test/transform/resource/after-delombok/BuilderDefaultsWarnings.java @@ -38,7 +38,9 @@ public class BuilderDefaultsWarnings { } @java.lang.SuppressWarnings("all") public BuilderDefaultsWarnings.BuilderDefaultsWarningsBuilder items(final java.util.Collection items) { - if (items == null) throw new java.lang.NullPointerException("items cannot be null"); + if (items == null) { + throw new java.lang.NullPointerException("items cannot be null"); + } if (this.items == null) this.items = new java.util.ArrayList(); this.items.addAll(items); return this; diff --git a/test/transform/resource/after-delombok/BuilderSingularAnnotatedTypes.java b/test/transform/resource/after-delombok/BuilderSingularAnnotatedTypes.java index 4cc247ef..f6fa22de 100644 --- a/test/transform/resource/after-delombok/BuilderSingularAnnotatedTypes.java +++ b/test/transform/resource/after-delombok/BuilderSingularAnnotatedTypes.java @@ -36,7 +36,9 @@ class BuilderSingularAnnotatedTypes { } @java.lang.SuppressWarnings("all") public BuilderSingularAnnotatedTypes.BuilderSingularAnnotatedTypesBuilder foos(final java.util.Collection foos) { - if (foos == null) throw new java.lang.NullPointerException("foos cannot be null"); + if (foos == null) { + throw new java.lang.NullPointerException("foos cannot be null"); + } if (this.foos == null) this.foos = new java.util.ArrayList<@MyAnnotation @NonNull String>(); this.foos.addAll(foos); return this; @@ -64,7 +66,9 @@ class BuilderSingularAnnotatedTypes { } @java.lang.SuppressWarnings("all") public BuilderSingularAnnotatedTypes.BuilderSingularAnnotatedTypesBuilder bars(final java.util.Map bars) { - if (bars == null) throw new java.lang.NullPointerException("bars cannot be null"); + if (bars == null) { + throw new java.lang.NullPointerException("bars cannot be null"); + } if (this.bars$key == null) { this.bars$key = new java.util.ArrayList<@MyAnnotation @NonNull String>(); this.bars$value = new java.util.ArrayList<@MyAnnotation @NonNull Integer>(); diff --git a/test/transform/resource/after-delombok/BuilderSingularAnnotatedTypesWithSetterPrefix.java b/test/transform/resource/after-delombok/BuilderSingularAnnotatedTypesWithSetterPrefix.java index 90cc5570..6dbbeee4 100644 --- a/test/transform/resource/after-delombok/BuilderSingularAnnotatedTypesWithSetterPrefix.java +++ b/test/transform/resource/after-delombok/BuilderSingularAnnotatedTypesWithSetterPrefix.java @@ -36,7 +36,9 @@ class BuilderSingularAnnotatedTypesWithSetterPrefix { } @java.lang.SuppressWarnings("all") public BuilderSingularAnnotatedTypesWithSetterPrefix.BuilderSingularAnnotatedTypesWithSetterPrefixBuilder withFoos(final java.util.Collection foos) { - if (foos == null) throw new java.lang.NullPointerException("foos cannot be null"); + if (foos == null) { + throw new java.lang.NullPointerException("foos cannot be null"); + } if (this.foos == null) this.foos = new java.util.ArrayList<@MyAnnotation @NonNull String>(); this.foos.addAll(foos); return this; @@ -64,7 +66,9 @@ class BuilderSingularAnnotatedTypesWithSetterPrefix { } @java.lang.SuppressWarnings("all") public BuilderSingularAnnotatedTypesWithSetterPrefix.BuilderSingularAnnotatedTypesWithSetterPrefixBuilder withBars(final java.util.Map bars) { - if (bars == null) throw new java.lang.NullPointerException("bars cannot be null"); + if (bars == null) { + throw new java.lang.NullPointerException("bars cannot be null"); + } if (this.bars$key == null) { this.bars$key = new java.util.ArrayList<@MyAnnotation @NonNull String>(); this.bars$value = new java.util.ArrayList<@MyAnnotation @NonNull Integer>(); diff --git a/test/transform/resource/after-delombok/BuilderSingularGuavaListsSets.java b/test/transform/resource/after-delombok/BuilderSingularGuavaListsSets.java index 650ab2fd..32b7c084 100644 --- a/test/transform/resource/after-delombok/BuilderSingularGuavaListsSets.java +++ b/test/transform/resource/after-delombok/BuilderSingularGuavaListsSets.java @@ -41,7 +41,9 @@ class BuilderSingularGuavaListsSets { } @java.lang.SuppressWarnings("all") public BuilderSingularGuavaListsSets.BuilderSingularGuavaListsSetsBuilder cards(final java.lang.Iterable cards) { - if (cards == null) throw new java.lang.NullPointerException("cards cannot be null"); + if (cards == null) { + throw new java.lang.NullPointerException("cards cannot be null"); + } if (this.cards == null) this.cards = com.google.common.collect.ImmutableList.builder(); this.cards.addAll(cards); return this; @@ -59,7 +61,9 @@ class BuilderSingularGuavaListsSets { } @java.lang.SuppressWarnings("all") public BuilderSingularGuavaListsSets.BuilderSingularGuavaListsSetsBuilder frogs(final java.lang.Iterable frogs) { - if (frogs == null) throw new java.lang.NullPointerException("frogs cannot be null"); + if (frogs == null) { + throw new java.lang.NullPointerException("frogs cannot be null"); + } if (this.frogs == null) this.frogs = com.google.common.collect.ImmutableList.builder(); this.frogs.addAll(frogs); return this; @@ -77,7 +81,9 @@ class BuilderSingularGuavaListsSets { } @java.lang.SuppressWarnings("all") public BuilderSingularGuavaListsSets.BuilderSingularGuavaListsSetsBuilder rawSet(final java.lang.Iterable rawSet) { - if (rawSet == null) throw new java.lang.NullPointerException("rawSet cannot be null"); + if (rawSet == null) { + throw new java.lang.NullPointerException("rawSet cannot be null"); + } if (this.rawSet == null) this.rawSet = com.google.common.collect.ImmutableSet.builder(); this.rawSet.addAll(rawSet); return this; @@ -95,7 +101,9 @@ class BuilderSingularGuavaListsSets { } @java.lang.SuppressWarnings("all") public BuilderSingularGuavaListsSets.BuilderSingularGuavaListsSetsBuilder passes(final java.lang.Iterable passes) { - if (passes == null) throw new java.lang.NullPointerException("passes cannot be null"); + if (passes == null) { + throw new java.lang.NullPointerException("passes cannot be null"); + } if (this.passes == null) this.passes = com.google.common.collect.ImmutableSortedSet.naturalOrder(); this.passes.addAll(passes); return this; @@ -113,7 +121,9 @@ class BuilderSingularGuavaListsSets { } @java.lang.SuppressWarnings("all") public BuilderSingularGuavaListsSets.BuilderSingularGuavaListsSetsBuilder users(final com.google.common.collect.Table users) { - if (users == null) throw new java.lang.NullPointerException("users cannot be null"); + if (users == null) { + throw new java.lang.NullPointerException("users cannot be null"); + } if (this.users == null) this.users = com.google.common.collect.ImmutableTable.builder(); this.users.putAll(users); return this; diff --git a/test/transform/resource/after-delombok/BuilderSingularGuavaMaps.java b/test/transform/resource/after-delombok/BuilderSingularGuavaMaps.java index 6af1bf8d..9e3c6c15 100644 --- a/test/transform/resource/after-delombok/BuilderSingularGuavaMaps.java +++ b/test/transform/resource/after-delombok/BuilderSingularGuavaMaps.java @@ -31,7 +31,9 @@ class BuilderSingularGuavaMaps { } @java.lang.SuppressWarnings("all") public BuilderSingularGuavaMaps.BuilderSingularGuavaMapsBuilder battleaxes(final java.util.Map battleaxes) { - if (battleaxes == null) throw new java.lang.NullPointerException("battleaxes cannot be null"); + if (battleaxes == null) { + throw new java.lang.NullPointerException("battleaxes cannot be null"); + } if (this.battleaxes == null) this.battleaxes = com.google.common.collect.ImmutableMap.builder(); this.battleaxes.putAll(battleaxes); return this; @@ -49,7 +51,9 @@ class BuilderSingularGuavaMaps { } @java.lang.SuppressWarnings("all") public BuilderSingularGuavaMaps.BuilderSingularGuavaMapsBuilder vertices(final java.util.Map vertices) { - if (vertices == null) throw new java.lang.NullPointerException("vertices cannot be null"); + if (vertices == null) { + throw new java.lang.NullPointerException("vertices cannot be null"); + } if (this.vertices == null) this.vertices = com.google.common.collect.ImmutableSortedMap.naturalOrder(); this.vertices.putAll(vertices); return this; @@ -67,7 +71,9 @@ class BuilderSingularGuavaMaps { } @java.lang.SuppressWarnings("all") public BuilderSingularGuavaMaps.BuilderSingularGuavaMapsBuilder rawMap(final java.util.Map rawMap) { - if (rawMap == null) throw new java.lang.NullPointerException("rawMap cannot be null"); + if (rawMap == null) { + throw new java.lang.NullPointerException("rawMap cannot be null"); + } if (this.rawMap == null) this.rawMap = com.google.common.collect.ImmutableBiMap.builder(); this.rawMap.putAll(rawMap); return this; diff --git a/test/transform/resource/after-delombok/BuilderSingularLists.java b/test/transform/resource/after-delombok/BuilderSingularLists.java index 43eb7702..f722dfcd 100644 --- a/test/transform/resource/after-delombok/BuilderSingularLists.java +++ b/test/transform/resource/after-delombok/BuilderSingularLists.java @@ -30,7 +30,9 @@ class BuilderSingularLists { } @java.lang.SuppressWarnings("all") public BuilderSingularLists.BuilderSingularListsBuilder children(final java.util.Collection children) { - if (children == null) throw new java.lang.NullPointerException("children cannot be null"); + if (children == null) { + throw new java.lang.NullPointerException("children cannot be null"); + } if (this.children == null) this.children = new java.util.ArrayList(); this.children.addAll(children); return this; @@ -48,7 +50,9 @@ class BuilderSingularLists { } @java.lang.SuppressWarnings("all") public BuilderSingularLists.BuilderSingularListsBuilder scarves(final java.util.Collection scarves) { - if (scarves == null) throw new java.lang.NullPointerException("scarves cannot be null"); + if (scarves == null) { + throw new java.lang.NullPointerException("scarves cannot be null"); + } if (this.scarves == null) this.scarves = new java.util.ArrayList(); this.scarves.addAll(scarves); return this; @@ -66,7 +70,9 @@ class BuilderSingularLists { } @java.lang.SuppressWarnings("all") public BuilderSingularLists.BuilderSingularListsBuilder rawList(final java.util.Collection rawList) { - if (rawList == null) throw new java.lang.NullPointerException("rawList cannot be null"); + if (rawList == null) { + throw new java.lang.NullPointerException("rawList cannot be null"); + } if (this.rawList == null) this.rawList = new java.util.ArrayList(); this.rawList.addAll(rawList); return this; diff --git a/test/transform/resource/after-delombok/BuilderSingularMaps.java b/test/transform/resource/after-delombok/BuilderSingularMaps.java index d10dd090..f6073141 100644 --- a/test/transform/resource/after-delombok/BuilderSingularMaps.java +++ b/test/transform/resource/after-delombok/BuilderSingularMaps.java @@ -46,7 +46,9 @@ class BuilderSingularMaps { } @SuppressWarnings("all") public BuilderSingularMaps.BuilderSingularMapsBuilder women(java.util.Map women) { - if (women == null) throw new NullPointerException("women cannot be null"); + if (women == null) { + throw new NullPointerException("women cannot be null"); + } if (this.women$key == null) { this.women$key = new java.util.ArrayList(); this.women$value = new java.util.ArrayList(); @@ -77,7 +79,9 @@ class BuilderSingularMaps { } @SuppressWarnings("all") public BuilderSingularMaps.BuilderSingularMapsBuilder men(java.util.Map men) { - if (men == null) throw new NullPointerException("men cannot be null"); + if (men == null) { + throw new NullPointerException("men cannot be null"); + } if (this.men$key == null) { this.men$key = new java.util.ArrayList(); this.men$value = new java.util.ArrayList(); @@ -108,7 +112,9 @@ class BuilderSingularMaps { } @SuppressWarnings("all") public BuilderSingularMaps.BuilderSingularMapsBuilder rawMap(java.util.Map rawMap) { - if (rawMap == null) throw new NullPointerException("rawMap cannot be null"); + if (rawMap == null) { + throw new NullPointerException("rawMap cannot be null"); + } if (this.rawMap$key == null) { this.rawMap$key = new java.util.ArrayList(); this.rawMap$value = new java.util.ArrayList(); @@ -139,7 +145,9 @@ class BuilderSingularMaps { } @SuppressWarnings("all") public BuilderSingularMaps.BuilderSingularMapsBuilder stringMap(java.util.Map stringMap) { - if (stringMap == null) throw new NullPointerException("stringMap cannot be null"); + if (stringMap == null) { + throw new NullPointerException("stringMap cannot be null"); + } if (this.stringMap$key == null) { this.stringMap$key = new java.util.ArrayList(); this.stringMap$value = new java.util.ArrayList(); diff --git a/test/transform/resource/after-delombok/BuilderSingularMapsWithSetterPrefix.java b/test/transform/resource/after-delombok/BuilderSingularMapsWithSetterPrefix.java index baa8f311..b3e92fb0 100644 --- a/test/transform/resource/after-delombok/BuilderSingularMapsWithSetterPrefix.java +++ b/test/transform/resource/after-delombok/BuilderSingularMapsWithSetterPrefix.java @@ -46,15 +46,16 @@ class BuilderSingularMapsWithSetterPrefix { } @SuppressWarnings("all") public BuilderSingularMapsWithSetterPrefix.BuilderSingularMapsWithSetterPrefixBuilder withWomen(java.util.Map women) { - if (women != null) { - if (this.women$key == null) { - this.women$key = new java.util.ArrayList(); - this.women$value = new java.util.ArrayList(); - } - for (java.util.Map.Entry $lombokEntry : women.entrySet()) { - this.women$key.add($lombokEntry.getKey()); - this.women$value.add($lombokEntry.getValue()); - } + if (women == null) { + throw new NullPointerException("women cannot be null"); + } + if (this.women$key == null) { + this.women$key = new java.util.ArrayList(); + this.women$value = new java.util.ArrayList(); + } + for (java.util.Map.Entry $lombokEntry : women.entrySet()) { + this.women$key.add($lombokEntry.getKey()); + this.women$value.add($lombokEntry.getValue()); } return this; } @@ -78,15 +79,16 @@ class BuilderSingularMapsWithSetterPrefix { } @SuppressWarnings("all") public BuilderSingularMapsWithSetterPrefix.BuilderSingularMapsWithSetterPrefixBuilder withMen(java.util.Map men) { - if (men != null) { - if (this.men$key == null) { - this.men$key = new java.util.ArrayList(); - this.men$value = new java.util.ArrayList(); - } - for (java.util.Map.Entry $lombokEntry : men.entrySet()) { - this.men$key.add($lombokEntry.getKey()); - this.men$value.add($lombokEntry.getValue()); - } + if (men == null) { + throw new NullPointerException("men cannot be null"); + } + if (this.men$key == null) { + this.men$key = new java.util.ArrayList(); + this.men$value = new java.util.ArrayList(); + } + for (java.util.Map.Entry $lombokEntry : men.entrySet()) { + this.men$key.add($lombokEntry.getKey()); + this.men$value.add($lombokEntry.getValue()); } return this; } @@ -142,15 +144,16 @@ class BuilderSingularMapsWithSetterPrefix { } @SuppressWarnings("all") public BuilderSingularMapsWithSetterPrefix.BuilderSingularMapsWithSetterPrefixBuilder withStringMap(java.util.Map stringMap) { - if (stringMap != null) { - if (this.stringMap$key == null) { - this.stringMap$key = new java.util.ArrayList(); - this.stringMap$value = new java.util.ArrayList(); - } - for (java.util.Map.Entry $lombokEntry : stringMap.entrySet()) { - this.stringMap$key.add($lombokEntry.getKey()); - this.stringMap$value.add($lombokEntry.getValue()); - } + if (stringMap == null) { + throw new NullPointerException("stringMap cannot be null"); + } + if (this.stringMap$key == null) { + this.stringMap$key = new java.util.ArrayList(); + this.stringMap$value = new java.util.ArrayList(); + } + for (java.util.Map.Entry $lombokEntry : stringMap.entrySet()) { + this.stringMap$key.add($lombokEntry.getKey()); + this.stringMap$value.add($lombokEntry.getValue()); } return this; } diff --git a/test/transform/resource/after-delombok/BuilderSingularNoAuto.java b/test/transform/resource/after-delombok/BuilderSingularNoAuto.java index 6b2fd5b2..ba6ddc52 100644 --- a/test/transform/resource/after-delombok/BuilderSingularNoAuto.java +++ b/test/transform/resource/after-delombok/BuilderSingularNoAuto.java @@ -28,7 +28,9 @@ class BuilderSingularNoAuto { } @java.lang.SuppressWarnings("all") public BuilderSingularNoAuto.BuilderSingularNoAutoBuilder things(final java.util.Collection things) { - if (things == null) throw new java.lang.NullPointerException("things cannot be null"); + if (things == null) { + throw new java.lang.NullPointerException("things cannot be null"); + } if (this.things == null) this.things = new java.util.ArrayList(); this.things.addAll(things); return this; @@ -46,7 +48,9 @@ class BuilderSingularNoAuto { } @java.lang.SuppressWarnings("all") public BuilderSingularNoAuto.BuilderSingularNoAutoBuilder widgets(final java.util.Collection widgets) { - if (widgets == null) throw new java.lang.NullPointerException("widgets cannot be null"); + if (widgets == null) { + throw new java.lang.NullPointerException("widgets cannot be null"); + } if (this.widgets == null) this.widgets = new java.util.ArrayList(); this.widgets.addAll(widgets); return this; @@ -64,7 +68,9 @@ class BuilderSingularNoAuto { } @java.lang.SuppressWarnings("all") public BuilderSingularNoAuto.BuilderSingularNoAutoBuilder items(final java.util.Collection items) { - if (items == null) throw new java.lang.NullPointerException("items cannot be null"); + if (items == null) { + throw new java.lang.NullPointerException("items cannot be null"); + } if (this.items == null) this.items = new java.util.ArrayList(); this.items.addAll(items); return this; diff --git a/test/transform/resource/after-delombok/BuilderSingularNoAutoWithSetterPrefix.java b/test/transform/resource/after-delombok/BuilderSingularNoAutoWithSetterPrefix.java index a023b82a..857348d3 100644 --- a/test/transform/resource/after-delombok/BuilderSingularNoAutoWithSetterPrefix.java +++ b/test/transform/resource/after-delombok/BuilderSingularNoAutoWithSetterPrefix.java @@ -28,7 +28,9 @@ class BuilderSingularNoAutoWithSetterPrefix { } @java.lang.SuppressWarnings("all") public BuilderSingularNoAutoWithSetterPrefix.BuilderSingularNoAutoWithSetterPrefixBuilder withThings(final java.util.Collection things) { - if (things == null) throw new java.lang.NullPointerException("things cannot be null"); + if (things == null) { + throw new java.lang.NullPointerException("things cannot be null"); + } if (this.things == null) this.things = new java.util.ArrayList(); this.things.addAll(things); return this; @@ -46,7 +48,9 @@ class BuilderSingularNoAutoWithSetterPrefix { } @java.lang.SuppressWarnings("all") public BuilderSingularNoAutoWithSetterPrefix.BuilderSingularNoAutoWithSetterPrefixBuilder withWidgets(final java.util.Collection widgets) { - if (widgets == null) throw new java.lang.NullPointerException("widgets cannot be null"); + if (widgets == null) { + throw new java.lang.NullPointerException("widgets cannot be null"); + } if (this.widgets == null) this.widgets = new java.util.ArrayList(); this.widgets.addAll(widgets); return this; @@ -64,7 +68,9 @@ class BuilderSingularNoAutoWithSetterPrefix { } @java.lang.SuppressWarnings("all") public BuilderSingularNoAutoWithSetterPrefix.BuilderSingularNoAutoWithSetterPrefixBuilder withItems(final java.util.Collection items) { - if (items == null) throw new java.lang.NullPointerException("items cannot be null"); + if (items == null) { + throw new java.lang.NullPointerException("items cannot be null"); + } if (this.items == null) this.items = new java.util.ArrayList(); this.items.addAll(items); return this; diff --git a/test/transform/resource/after-delombok/BuilderSingularNullBehavior1.java b/test/transform/resource/after-delombok/BuilderSingularNullBehavior1.java index 7b4e0a29..55420ac2 100644 --- a/test/transform/resource/after-delombok/BuilderSingularNullBehavior1.java +++ b/test/transform/resource/after-delombok/BuilderSingularNullBehavior1.java @@ -1,17 +1,12 @@ import java.util.List; import java.util.Collection; -import lombok.Singular.NullCollectionBehavior; class BuilderSingularNullBehavior1 { private List names; private List locations; - private List whatevers; - private List doohickeys; @java.lang.SuppressWarnings("all") - BuilderSingularNullBehavior1(final List names, final List locations, final List whatevers, final List doohickeys) { + BuilderSingularNullBehavior1(final List names, final List locations) { this.names = names; this.locations = locations; - this.whatevers = whatevers; - this.doohickeys = doohickeys; } @java.lang.SuppressWarnings("all") public static class BuilderSingularNullBehavior1Builder { @@ -20,10 +15,6 @@ class BuilderSingularNullBehavior1 { @java.lang.SuppressWarnings("all") private java.util.ArrayList locations; @java.lang.SuppressWarnings("all") - private java.util.ArrayList whatevers; - @java.lang.SuppressWarnings("all") - private java.util.ArrayList doohickeys; - @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior1Builder() { } @java.lang.SuppressWarnings("all") @@ -33,8 +24,8 @@ class BuilderSingularNullBehavior1 { return this; } @java.lang.SuppressWarnings("all") - public BuilderSingularNullBehavior1.BuilderSingularNullBehavior1Builder names(final java.util.Collection names) { - if (names == null) throw new java.lang.NullPointerException("names cannot be null"); + public BuilderSingularNullBehavior1.BuilderSingularNullBehavior1Builder names(final java.util.@org.checkerframework.checker.nullness.qual.NonNull Collection names) { + assert names != null : "names cannot be null"; if (this.names == null) this.names = new java.util.ArrayList(); this.names.addAll(names); return this; @@ -51,10 +42,11 @@ class BuilderSingularNullBehavior1 { return this; } @java.lang.SuppressWarnings("all") - public BuilderSingularNullBehavior1.BuilderSingularNullBehavior1Builder locations(final java.util.Collection locations) { - java.util.Objects.requireNonNull(locations, "locations cannot be null"); - if (this.locations == null) this.locations = new java.util.ArrayList(); - this.locations.addAll(locations); + public BuilderSingularNullBehavior1.BuilderSingularNullBehavior1Builder locations(final java.util.@org.checkerframework.checker.nullness.qual.Nullable Collection locations) { + if (locations != null) { + if (this.locations == null) this.locations = new java.util.ArrayList(); + this.locations.addAll(locations); + } return this; } @java.lang.SuppressWarnings("all") @@ -63,43 +55,6 @@ class BuilderSingularNullBehavior1 { return this; } @java.lang.SuppressWarnings("all") - public BuilderSingularNullBehavior1.BuilderSingularNullBehavior1Builder whatever(final String whatever) { - if (this.whatevers == null) this.whatevers = new java.util.ArrayList(); - this.whatevers.add(whatever); - return this; - } - @java.lang.SuppressWarnings("all") - public BuilderSingularNullBehavior1.BuilderSingularNullBehavior1Builder whatevers(final java.util.Collection whatevers) { - com.google.common.base.Preconditions.checkNotNull(whatevers, "whatevers cannot be null"); - if (this.whatevers == null) this.whatevers = new java.util.ArrayList(); - this.whatevers.addAll(whatevers); - return this; - } - @java.lang.SuppressWarnings("all") - public BuilderSingularNullBehavior1.BuilderSingularNullBehavior1Builder clearWhatevers() { - if (this.whatevers != null) this.whatevers.clear(); - return this; - } - @java.lang.SuppressWarnings("all") - public BuilderSingularNullBehavior1.BuilderSingularNullBehavior1Builder doohickey(final String doohickey) { - if (this.doohickeys == null) this.doohickeys = new java.util.ArrayList(); - this.doohickeys.add(doohickey); - return this; - } - @java.lang.SuppressWarnings("all") - public BuilderSingularNullBehavior1.BuilderSingularNullBehavior1Builder doohickeys(final java.util.Collection doohickeys) { - if (doohickeys != null) { - if (this.doohickeys == null) this.doohickeys = new java.util.ArrayList(); - this.doohickeys.addAll(doohickeys); - } - return this; - } - @java.lang.SuppressWarnings("all") - public BuilderSingularNullBehavior1.BuilderSingularNullBehavior1Builder clearDoohickeys() { - if (this.doohickeys != null) this.doohickeys.clear(); - return this; - } - @java.lang.SuppressWarnings("all") public BuilderSingularNullBehavior1 build() { java.util.List names; switch (this.names == null ? 0 : this.names.size()) { @@ -123,38 +78,16 @@ class BuilderSingularNullBehavior1 { default: locations = java.util.Collections.unmodifiableList(new java.util.ArrayList(this.locations)); } - java.util.List whatevers; - switch (this.whatevers == null ? 0 : this.whatevers.size()) { - case 0: - whatevers = java.util.Collections.emptyList(); - break; - case 1: - whatevers = java.util.Collections.singletonList(this.whatevers.get(0)); - break; - default: - whatevers = java.util.Collections.unmodifiableList(new java.util.ArrayList(this.whatevers)); - } - java.util.List doohickeys; - switch (this.doohickeys == null ? 0 : this.doohickeys.size()) { - case 0: - doohickeys = java.util.Collections.emptyList(); - break; - case 1: - doohickeys = java.util.Collections.singletonList(this.doohickeys.get(0)); - break; - default: - doohickeys = java.util.Collections.unmodifiableList(new java.util.ArrayList(this.doohickeys)); - } - return new BuilderSingularNullBehavior1(names, locations, whatevers, doohickeys); + return new BuilderSingularNullBehavior1(names, locations); } @java.lang.Override @java.lang.SuppressWarnings("all") - public java.lang.String toString() { - return "BuilderSingularNullBehavior1.BuilderSingularNullBehavior1Builder(names=" + this.names + ", locations=" + this.locations + ", whatevers=" + this.whatevers + ", doohickeys=" + this.doohickeys + ")"; + public java.lang.@org.checkerframework.checker.nullness.qual.NonNull String toString() { + return "BuilderSingularNullBehavior1.BuilderSingularNullBehavior1Builder(names=" + this.names + ", locations=" + this.locations + ")"; } } @java.lang.SuppressWarnings("all") public static BuilderSingularNullBehavior1.BuilderSingularNullBehavior1Builder builder() { return new BuilderSingularNullBehavior1.BuilderSingularNullBehavior1Builder(); } -} \ No newline at end of file +} diff --git a/test/transform/resource/after-delombok/BuilderSingularNullBehavior2.java b/test/transform/resource/after-delombok/BuilderSingularNullBehavior2.java index f62ebd10..ba70002b 100644 --- a/test/transform/resource/after-delombok/BuilderSingularNullBehavior2.java +++ b/test/transform/resource/after-delombok/BuilderSingularNullBehavior2.java @@ -1,20 +1,15 @@ import java.util.List; -import lombok.Singular.NullCollectionBehavior; class BuilderSingularNullBehavior2 { private List locations; - private List doohickeys; @java.lang.SuppressWarnings("all") - BuilderSingularNullBehavior2(final List locations, final List doohickeys) { + BuilderSingularNullBehavior2(final List locations) { this.locations = locations; - this.doohickeys = doohickeys; } @java.lang.SuppressWarnings("all") public static class BuilderSingularNullBehavior2Builder { @java.lang.SuppressWarnings("all") private java.util.ArrayList locations; @java.lang.SuppressWarnings("all") - private java.util.ArrayList doohickeys; - @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior2Builder() { } @java.lang.SuppressWarnings("all") @@ -24,7 +19,7 @@ class BuilderSingularNullBehavior2 { return this; } @java.lang.SuppressWarnings("all") - public BuilderSingularNullBehavior2.BuilderSingularNullBehavior2Builder locations(final java.util.@org.checkerframework.checker.nullness.qual.NonNull Collection locations) { + public BuilderSingularNullBehavior2.BuilderSingularNullBehavior2Builder locations(@org.springframework.lang.NonNull final java.util.Collection locations) { java.util.Objects.requireNonNull(locations, "locations cannot be null"); if (this.locations == null) this.locations = new java.util.ArrayList(); this.locations.addAll(locations); @@ -35,29 +30,6 @@ class BuilderSingularNullBehavior2 { if (this.locations != null) this.locations.clear(); return this; } - - @java.lang.SuppressWarnings("all") - public BuilderSingularNullBehavior2.BuilderSingularNullBehavior2Builder doohickey(final String doohickey) { - if (this.doohickeys == null) this.doohickeys = new java.util.ArrayList(); - this.doohickeys.add(doohickey); - return this; - } - - @java.lang.SuppressWarnings("all") - public BuilderSingularNullBehavior2.BuilderSingularNullBehavior2Builder doohickeys(final java.util.@org.checkerframework.checker.nullness.qual.Nullable Collection doohickeys) { - if (doohickeys != null) { - if (this.doohickeys == null) this.doohickeys = new java.util.ArrayList(); - this.doohickeys.addAll(doohickeys); - } - return this; - } - - @java.lang.SuppressWarnings("all") - public BuilderSingularNullBehavior2.BuilderSingularNullBehavior2Builder clearDoohickeys() { - if (this.doohickeys != null) this.doohickeys.clear(); - return this; - } - @java.lang.SuppressWarnings("all") public BuilderSingularNullBehavior2 build() { java.util.List locations; @@ -71,27 +43,15 @@ class BuilderSingularNullBehavior2 { default: locations = java.util.Collections.unmodifiableList(new java.util.ArrayList(this.locations)); } - java.util.List doohickeys; - switch (this.doohickeys == null ? 0 : this.doohickeys.size()) { - case 0: - doohickeys = java.util.Collections.emptyList(); - break; - case 1: - doohickeys = java.util.Collections.singletonList(this.doohickeys.get(0)); - break; - default: - doohickeys = java.util.Collections.unmodifiableList(new java.util.ArrayList(this.doohickeys)); - } - return new BuilderSingularNullBehavior2(locations, doohickeys); + return new BuilderSingularNullBehavior2(locations); } - + @org.springframework.lang.NonNull @java.lang.Override @java.lang.SuppressWarnings("all") - public java.lang.@org.checkerframework.checker.nullness.qual.NonNull String toString() { - return "BuilderSingularNullBehavior2.BuilderSingularNullBehavior2Builder(locations=" + this.locations + ", doohickeys=" + this.doohickeys + ")"; + public java.lang.String toString() { + return "BuilderSingularNullBehavior2.BuilderSingularNullBehavior2Builder(locations=" + this.locations + ")"; } } - @java.lang.SuppressWarnings("all") public static BuilderSingularNullBehavior2.BuilderSingularNullBehavior2Builder builder() { return new BuilderSingularNullBehavior2.BuilderSingularNullBehavior2Builder(); diff --git a/test/transform/resource/after-delombok/BuilderSingularRedirectToGuava.java b/test/transform/resource/after-delombok/BuilderSingularRedirectToGuava.java index 9ee6823e..a718d7cd 100644 --- a/test/transform/resource/after-delombok/BuilderSingularRedirectToGuava.java +++ b/test/transform/resource/after-delombok/BuilderSingularRedirectToGuava.java @@ -30,7 +30,9 @@ class BuilderSingularRedirectToGuava { } @java.lang.SuppressWarnings("all") public BuilderSingularRedirectToGuava.BuilderSingularRedirectToGuavaBuilder dangerMice(final java.lang.Iterable dangerMice) { - if (dangerMice == null) throw new java.lang.NullPointerException("dangerMice cannot be null"); + if (dangerMice == null) { + throw new java.lang.NullPointerException("dangerMice cannot be null"); + } if (this.dangerMice == null) this.dangerMice = com.google.common.collect.ImmutableSet.builder(); this.dangerMice.addAll(dangerMice); return this; @@ -48,7 +50,9 @@ class BuilderSingularRedirectToGuava { } @java.lang.SuppressWarnings("all") public BuilderSingularRedirectToGuava.BuilderSingularRedirectToGuavaBuilder things(final java.util.Map things) { - if (things == null) throw new java.lang.NullPointerException("things cannot be null"); + if (things == null) { + throw new java.lang.NullPointerException("things cannot be null"); + } if (this.things == null) this.things = com.google.common.collect.ImmutableSortedMap.naturalOrder(); this.things.putAll(things); return this; @@ -66,7 +70,9 @@ class BuilderSingularRedirectToGuava { } @java.lang.SuppressWarnings("all") public BuilderSingularRedirectToGuava.BuilderSingularRedirectToGuavaBuilder doohickeys(final java.lang.Iterable> doohickeys) { - if (doohickeys == null) throw new java.lang.NullPointerException("doohickeys cannot be null"); + if (doohickeys == null) { + throw new java.lang.NullPointerException("doohickeys cannot be null"); + } if (this.doohickeys == null) this.doohickeys = com.google.common.collect.ImmutableList.builder(); this.doohickeys.addAll(doohickeys); return this; diff --git a/test/transform/resource/after-delombok/BuilderSingularSets.java b/test/transform/resource/after-delombok/BuilderSingularSets.java index 7b905c8c..25f106e9 100644 --- a/test/transform/resource/after-delombok/BuilderSingularSets.java +++ b/test/transform/resource/after-delombok/BuilderSingularSets.java @@ -34,7 +34,9 @@ class BuilderSingularSets { } @java.lang.SuppressWarnings("all") public BuilderSingularSets.BuilderSingularSetsBuilder dangerMice(final java.util.Collection dangerMice) { - if (dangerMice == null) throw new java.lang.NullPointerException("dangerMice cannot be null"); + if (dangerMice == null) { + throw new java.lang.NullPointerException("dangerMice cannot be null"); + } if (this.dangerMice == null) this.dangerMice = new java.util.ArrayList(); this.dangerMice.addAll(dangerMice); return this; @@ -52,7 +54,9 @@ class BuilderSingularSets { } @java.lang.SuppressWarnings("all") public BuilderSingularSets.BuilderSingularSetsBuilder octopodes(final java.util.Collection octopodes) { - if (octopodes == null) throw new java.lang.NullPointerException("octopodes cannot be null"); + if (octopodes == null) { + throw new java.lang.NullPointerException("octopodes cannot be null"); + } if (this.octopodes == null) this.octopodes = new java.util.ArrayList(); this.octopodes.addAll(octopodes); return this; @@ -70,7 +74,9 @@ class BuilderSingularSets { } @java.lang.SuppressWarnings("all") public BuilderSingularSets.BuilderSingularSetsBuilder rawSet(final java.util.Collection rawSet) { - if (rawSet == null) throw new java.lang.NullPointerException("rawSet cannot be null"); + if (rawSet == null) { + throw new java.lang.NullPointerException("rawSet cannot be null"); + } if (this.rawSet == null) this.rawSet = new java.util.ArrayList(); this.rawSet.addAll(rawSet); return this; @@ -88,7 +94,9 @@ class BuilderSingularSets { } @java.lang.SuppressWarnings("all") public BuilderSingularSets.BuilderSingularSetsBuilder stringSet(final java.util.Collection stringSet) { - if (stringSet == null) throw new java.lang.NullPointerException("stringSet cannot be null"); + if (stringSet == null) { + throw new java.lang.NullPointerException("stringSet cannot be null"); + } if (this.stringSet == null) this.stringSet = new java.util.ArrayList(); this.stringSet.addAll(stringSet); return this; diff --git a/test/transform/resource/after-delombok/BuilderSingularSetsWithSetterPrefix.java b/test/transform/resource/after-delombok/BuilderSingularSetsWithSetterPrefix.java index 4a025624..a3d3c621 100644 --- a/test/transform/resource/after-delombok/BuilderSingularSetsWithSetterPrefix.java +++ b/test/transform/resource/after-delombok/BuilderSingularSetsWithSetterPrefix.java @@ -34,7 +34,9 @@ class BuilderSingularSetsWithSetterPrefix { } @java.lang.SuppressWarnings("all") public BuilderSingularSetsWithSetterPrefix.BuilderSingularSetsWithSetterPrefixBuilder withDangerMice(final java.util.Collection dangerMice) { - if (dangerMice == null) throw new java.lang.NullPointerException("dangerMice cannot be null"); + if (dangerMice == null) { + throw new java.lang.NullPointerException("dangerMice cannot be null"); + } if (this.dangerMice == null) this.dangerMice = new java.util.ArrayList(); this.dangerMice.addAll(dangerMice); return this; @@ -52,7 +54,9 @@ class BuilderSingularSetsWithSetterPrefix { } @java.lang.SuppressWarnings("all") public BuilderSingularSetsWithSetterPrefix.BuilderSingularSetsWithSetterPrefixBuilder withOctopodes(final java.util.Collection octopodes) { - if (octopodes == null) throw new java.lang.NullPointerException("octopodes cannot be null"); + if (octopodes == null) { + throw new java.lang.NullPointerException("octopodes cannot be null"); + } if (this.octopodes == null) this.octopodes = new java.util.ArrayList(); this.octopodes.addAll(octopodes); return this; @@ -70,7 +74,9 @@ class BuilderSingularSetsWithSetterPrefix { } @java.lang.SuppressWarnings("all") public BuilderSingularSetsWithSetterPrefix.BuilderSingularSetsWithSetterPrefixBuilder withRawSet(final java.util.Collection rawSet) { - if (rawSet == null) throw new java.lang.NullPointerException("rawSet cannot be null"); + if (rawSet == null) { + throw new java.lang.NullPointerException("rawSet cannot be null"); + } if (this.rawSet == null) this.rawSet = new java.util.ArrayList(); this.rawSet.addAll(rawSet); return this; @@ -88,7 +94,9 @@ class BuilderSingularSetsWithSetterPrefix { } @java.lang.SuppressWarnings("all") public BuilderSingularSetsWithSetterPrefix.BuilderSingularSetsWithSetterPrefixBuilder withStringSet(final java.util.Collection stringSet) { - if (stringSet == null) throw new java.lang.NullPointerException("stringSet cannot be null"); + if (stringSet == null) { + throw new java.lang.NullPointerException("stringSet cannot be null"); + } if (this.stringSet == null) this.stringSet = new java.util.ArrayList(); this.stringSet.addAll(stringSet); return this; diff --git a/test/transform/resource/after-delombok/BuilderSingularToBuilderWithNull.java b/test/transform/resource/after-delombok/BuilderSingularToBuilderWithNull.java index 9a5ea7b3..fcd57a31 100644 --- a/test/transform/resource/after-delombok/BuilderSingularToBuilderWithNull.java +++ b/test/transform/resource/after-delombok/BuilderSingularToBuilderWithNull.java @@ -22,7 +22,9 @@ class BuilderSingularToBuilderWithNull { } @java.lang.SuppressWarnings("all") public BuilderSingularToBuilderWithNull.BuilderSingularToBuilderWithNullBuilder elems(final java.util.Collection elems) { - if (elems == null) throw new java.lang.NullPointerException("elems cannot be null"); + if (elems == null) { + throw new java.lang.NullPointerException("elems cannot be null"); + } if (this.elems == null) this.elems = new java.util.ArrayList(); this.elems.addAll(elems); return this; diff --git a/test/transform/resource/after-delombok/BuilderSingularToBuilderWithNullWithSetterPrefix.java b/test/transform/resource/after-delombok/BuilderSingularToBuilderWithNullWithSetterPrefix.java index 1860ba60..59bc09c1 100644 --- a/test/transform/resource/after-delombok/BuilderSingularToBuilderWithNullWithSetterPrefix.java +++ b/test/transform/resource/after-delombok/BuilderSingularToBuilderWithNullWithSetterPrefix.java @@ -22,7 +22,9 @@ class BuilderSingularToBuilderWithNullWithSetterPrefix { } @java.lang.SuppressWarnings("all") public BuilderSingularToBuilderWithNullWithSetterPrefix.BuilderSingularToBuilderWithNullWithSetterPrefixBuilder withElems(final java.util.Collection elems) { - if (elems == null) throw new java.lang.NullPointerException("elems cannot be null"); + if (elems == null) { + throw new java.lang.NullPointerException("elems cannot be null"); + } if (this.elems == null) this.elems = new java.util.ArrayList(); this.elems.addAll(elems); return this; diff --git a/test/transform/resource/after-delombok/BuilderSingularWildcardListsWithToBuilder.java b/test/transform/resource/after-delombok/BuilderSingularWildcardListsWithToBuilder.java index 29e53768..59cca1d3 100644 --- a/test/transform/resource/after-delombok/BuilderSingularWildcardListsWithToBuilder.java +++ b/test/transform/resource/after-delombok/BuilderSingularWildcardListsWithToBuilder.java @@ -25,7 +25,9 @@ class BuilderSingularWildcardListsWithToBuilder { } @java.lang.SuppressWarnings("all") public BuilderSingularWildcardListsWithToBuilder.BuilderSingularWildcardListsWithToBuilderBuilder objects(final java.util.Collection objects) { - if (objects == null) throw new java.lang.NullPointerException("objects cannot be null"); + if (objects == null) { + throw new java.lang.NullPointerException("objects cannot be null"); + } if (this.objects == null) this.objects = new java.util.ArrayList(); this.objects.addAll(objects); return this; @@ -43,7 +45,9 @@ class BuilderSingularWildcardListsWithToBuilder { } @java.lang.SuppressWarnings("all") public BuilderSingularWildcardListsWithToBuilder.BuilderSingularWildcardListsWithToBuilderBuilder numbers(final java.util.Collection numbers) { - if (numbers == null) throw new java.lang.NullPointerException("numbers cannot be null"); + if (numbers == null) { + throw new java.lang.NullPointerException("numbers cannot be null"); + } if (this.numbers == null) this.numbers = new java.util.ArrayList(); this.numbers.addAll(numbers); return this; diff --git a/test/transform/resource/after-delombok/BuilderSingularWithPrefixes.java b/test/transform/resource/after-delombok/BuilderSingularWithPrefixes.java index 3aa48f5d..bb6c5bfb 100644 --- a/test/transform/resource/after-delombok/BuilderSingularWithPrefixes.java +++ b/test/transform/resource/after-delombok/BuilderSingularWithPrefixes.java @@ -19,7 +19,9 @@ class BuilderSingularWithPrefixes { } @java.lang.SuppressWarnings("all") public BuilderSingularWithPrefixes.BuilderSingularWithPrefixesBuilder elems(final java.util.Collection elems) { - if (elems == null) throw new java.lang.NullPointerException("elems cannot be null"); + if (elems == null) { + throw new java.lang.NullPointerException("elems cannot be null"); + } if (this.elems == null) this.elems = new java.util.ArrayList(); this.elems.addAll(elems); return this; diff --git a/test/transform/resource/after-delombok/BuilderSingularWithPrefixesWithSetterPrefix.java b/test/transform/resource/after-delombok/BuilderSingularWithPrefixesWithSetterPrefix.java index 513c3fe4..94633cfe 100644 --- a/test/transform/resource/after-delombok/BuilderSingularWithPrefixesWithSetterPrefix.java +++ b/test/transform/resource/after-delombok/BuilderSingularWithPrefixesWithSetterPrefix.java @@ -19,7 +19,9 @@ class BuilderSingularWithPrefixesWithSetterPrefix { } @java.lang.SuppressWarnings("all") public BuilderSingularWithPrefixesWithSetterPrefix.BuilderSingularWithPrefixesWithSetterPrefixBuilder withElems(final java.util.Collection elems) { - if (elems == null) throw new java.lang.NullPointerException("elems cannot be null"); + if (elems == null) { + throw new java.lang.NullPointerException("elems cannot be null"); + } if (this.elems == null) this.elems = new java.util.ArrayList(); this.elems.addAll(elems); return this; diff --git a/test/transform/resource/after-delombok/BuilderWithDeprecated.java b/test/transform/resource/after-delombok/BuilderWithDeprecated.java index 584c8042..b6a09376 100644 --- a/test/transform/resource/after-delombok/BuilderWithDeprecated.java +++ b/test/transform/resource/after-delombok/BuilderWithDeprecated.java @@ -56,7 +56,9 @@ public class BuilderWithDeprecated { @java.lang.Deprecated @java.lang.SuppressWarnings("all") public BuilderWithDeprecated.BuilderWithDeprecatedBuilder strings(final java.util.Collection strings) { - if (strings == null) throw new java.lang.NullPointerException("strings cannot be null"); + if (strings == null) { + throw new java.lang.NullPointerException("strings cannot be null"); + } if (this.strings == null) this.strings = new java.util.ArrayList(); this.strings.addAll(strings); return this; @@ -77,7 +79,9 @@ public class BuilderWithDeprecated { @java.lang.Deprecated @java.lang.SuppressWarnings("all") public BuilderWithDeprecated.BuilderWithDeprecatedBuilder numbers(final java.lang.Iterable numbers) { - if (numbers == null) throw new java.lang.NullPointerException("numbers cannot be null"); + if (numbers == null) { + throw new java.lang.NullPointerException("numbers cannot be null"); + } if (this.numbers == null) this.numbers = com.google.common.collect.ImmutableList.builder(); this.numbers.addAll(numbers); return this; diff --git a/test/transform/resource/after-delombok/BuilderWithToBuilder.java b/test/transform/resource/after-delombok/BuilderWithToBuilder.java index 20043861..d98d09f6 100644 --- a/test/transform/resource/after-delombok/BuilderWithToBuilder.java +++ b/test/transform/resource/after-delombok/BuilderWithToBuilder.java @@ -50,7 +50,9 @@ class BuilderWithToBuilder { } @java.lang.SuppressWarnings("all") public BuilderWithToBuilder.BuilderWithToBuilderBuilder bars(final java.util.Collection bars) { - if (bars == null) throw new java.lang.NullPointerException("bars cannot be null"); + if (bars == null) { + throw new java.lang.NullPointerException("bars cannot be null"); + } if (this.bars == null) this.bars = new java.util.ArrayList(); this.bars.addAll(bars); return this; diff --git a/test/transform/resource/after-delombok/CheckerFrameworkBuilder.java b/test/transform/resource/after-delombok/CheckerFrameworkBuilder.java index fad0cf2b..ace3adad 100644 --- a/test/transform/resource/after-delombok/CheckerFrameworkBuilder.java +++ b/test/transform/resource/after-delombok/CheckerFrameworkBuilder.java @@ -62,7 +62,9 @@ class CheckerFrameworkBuilder { @org.checkerframework.checker.builder.qual.ReturnsReceiver @java.lang.SuppressWarnings("all") public CheckerFrameworkBuilder.CheckerFrameworkBuilderBuilder names(final java.util.Collection names) { - if (names == null) throw new java.lang.NullPointerException("names cannot be null"); + if (names == null) { + throw new java.lang.NullPointerException("names cannot be null"); + } if (this.names == null) this.names = new java.util.ArrayList(); this.names.addAll(names); return this; diff --git a/test/transform/resource/after-delombok/CheckerFrameworkSuperBuilder.java b/test/transform/resource/after-delombok/CheckerFrameworkSuperBuilder.java index f2cde1c6..b6e0ff3c 100644 --- a/test/transform/resource/after-delombok/CheckerFrameworkSuperBuilder.java +++ b/test/transform/resource/after-delombok/CheckerFrameworkSuperBuilder.java @@ -58,7 +58,9 @@ class CheckerFrameworkSuperBuilder { @org.checkerframework.checker.builder.qual.ReturnsReceiver @java.lang.SuppressWarnings("all") public B names(final java.util.Collection names) { - if (names == null) throw new java.lang.NullPointerException("names cannot be null"); + if (names == null) { + throw new java.lang.NullPointerException("names cannot be null"); + } if (this.names == null) this.names = new java.util.ArrayList(); this.names.addAll(names); return self(); diff --git a/test/transform/resource/after-delombok/SuperBuilderBasic.java b/test/transform/resource/after-delombok/SuperBuilderBasic.java index 1447e9af..c347e41c 100644 --- a/test/transform/resource/after-delombok/SuperBuilderBasic.java +++ b/test/transform/resource/after-delombok/SuperBuilderBasic.java @@ -26,7 +26,9 @@ public class SuperBuilderBasic { } @java.lang.SuppressWarnings("all") public B items(final java.util.Collection items) { - if (items == null) throw new java.lang.NullPointerException("items cannot be null"); + if (items == null) { + throw new java.lang.NullPointerException("items cannot be null"); + } if (this.items == null) this.items = new java.util.ArrayList(); this.items.addAll(items); return self(); diff --git a/test/transform/resource/after-delombok/SuperBuilderBasicToBuilder.java b/test/transform/resource/after-delombok/SuperBuilderBasicToBuilder.java index 1c0d378d..c0a80f93 100644 --- a/test/transform/resource/after-delombok/SuperBuilderBasicToBuilder.java +++ b/test/transform/resource/after-delombok/SuperBuilderBasicToBuilder.java @@ -69,7 +69,9 @@ public class SuperBuilderBasicToBuilder { } @java.lang.SuppressWarnings("all") public B items(final java.util.Collection items) { - if (items == null) throw new java.lang.NullPointerException("items cannot be null"); + if (items == null) { + throw new java.lang.NullPointerException("items cannot be null"); + } if (this.items == null) this.items = new java.util.ArrayList(); this.items.addAll(items); return self(); diff --git a/test/transform/resource/after-delombok/SuperBuilderSingularAnnotatedTypes.java b/test/transform/resource/after-delombok/SuperBuilderSingularAnnotatedTypes.java index 865af859..f6e0f024 100644 --- a/test/transform/resource/after-delombok/SuperBuilderSingularAnnotatedTypes.java +++ b/test/transform/resource/after-delombok/SuperBuilderSingularAnnotatedTypes.java @@ -32,7 +32,9 @@ class SuperBuilderSingularAnnotatedTypes { } @java.lang.SuppressWarnings("all") public B foos(final java.util.Collection foos) { - if (foos == null) throw new java.lang.NullPointerException("foos cannot be null"); + if (foos == null) { + throw new java.lang.NullPointerException("foos cannot be null"); + } if (this.foos == null) this.foos = new java.util.ArrayList<@MyAnnotation @NonNull String>(); this.foos.addAll(foos); return self(); @@ -60,7 +62,9 @@ class SuperBuilderSingularAnnotatedTypes { } @java.lang.SuppressWarnings("all") public B bars(final java.util.Map bars) { - if (bars == null) throw new java.lang.NullPointerException("bars cannot be null"); + if (bars == null) { + throw new java.lang.NullPointerException("bars cannot be null"); + } if (this.bars$key == null) { this.bars$key = new java.util.ArrayList<@MyAnnotation @NonNull String>(); this.bars$value = new java.util.ArrayList<@MyAnnotation @NonNull Integer>(); diff --git a/test/transform/resource/after-delombok/SuperBuilderWithCustomBuilderMethod.java b/test/transform/resource/after-delombok/SuperBuilderWithCustomBuilderMethod.java index 4300a5ec..cfa39295 100644 --- a/test/transform/resource/after-delombok/SuperBuilderWithCustomBuilderMethod.java +++ b/test/transform/resource/after-delombok/SuperBuilderWithCustomBuilderMethod.java @@ -26,7 +26,9 @@ public class SuperBuilderWithCustomBuilderMethod { } @java.lang.SuppressWarnings("all") public B items(final java.util.Collection items) { - if (items == null) throw new java.lang.NullPointerException("items cannot be null"); + if (items == null) { + throw new java.lang.NullPointerException("items cannot be null"); + } if (this.items == null) this.items = new java.util.ArrayList(); this.items.addAll(items); return self(); diff --git a/test/transform/resource/after-delombok/SuperBuilderWithGenerics.java b/test/transform/resource/after-delombok/SuperBuilderWithGenerics.java index 6b3d2ff0..f5627211 100644 --- a/test/transform/resource/after-delombok/SuperBuilderWithGenerics.java +++ b/test/transform/resource/after-delombok/SuperBuilderWithGenerics.java @@ -26,7 +26,9 @@ public class SuperBuilderWithGenerics { } @java.lang.SuppressWarnings("all") public B items(final java.util.Collection items) { - if (items == null) throw new java.lang.NullPointerException("items cannot be null"); + if (items == null) { + throw new java.lang.NullPointerException("items cannot be null"); + } if (this.items == null) this.items = new java.util.ArrayList(); this.items.addAll(items); return self(); diff --git a/test/transform/resource/after-delombok/SuperBuilderWithGenerics2.java b/test/transform/resource/after-delombok/SuperBuilderWithGenerics2.java index b03cff07..2b4697d5 100644 --- a/test/transform/resource/after-delombok/SuperBuilderWithGenerics2.java +++ b/test/transform/resource/after-delombok/SuperBuilderWithGenerics2.java @@ -26,7 +26,9 @@ public class SuperBuilderWithGenerics2 { } @java.lang.SuppressWarnings("all") public B items(final java.util.Collection items) { - if (items == null) throw new java.lang.NullPointerException("items cannot be null"); + if (items == null) { + throw new java.lang.NullPointerException("items cannot be null"); + } if (this.items == null) this.items = new java.util.ArrayList(); this.items.addAll(items); return self(); diff --git a/test/transform/resource/after-delombok/SuperBuilderWithGenericsAndToBuilder.java b/test/transform/resource/after-delombok/SuperBuilderWithGenericsAndToBuilder.java index 7403ff10..48d51fba 100644 --- a/test/transform/resource/after-delombok/SuperBuilderWithGenericsAndToBuilder.java +++ b/test/transform/resource/after-delombok/SuperBuilderWithGenericsAndToBuilder.java @@ -42,7 +42,9 @@ public class SuperBuilderWithGenericsAndToBuilder { } @java.lang.SuppressWarnings("all") public B items(final java.util.Map items) { - if (items == null) throw new java.lang.NullPointerException("items cannot be null"); + if (items == null) { + throw new java.lang.NullPointerException("items cannot be null"); + } if (this.items$key == null) { this.items$key = new java.util.ArrayList(); this.items$value = new java.util.ArrayList(); diff --git a/test/transform/resource/after-delombok/SuperBuilderWithPrefixes.java b/test/transform/resource/after-delombok/SuperBuilderWithPrefixes.java index 324a1443..9662c4d9 100644 --- a/test/transform/resource/after-delombok/SuperBuilderWithPrefixes.java +++ b/test/transform/resource/after-delombok/SuperBuilderWithPrefixes.java @@ -32,7 +32,9 @@ class SuperBuilderWithPrefixes { } @java.lang.SuppressWarnings("all") public B items(final java.util.Collection items) { - if (items == null) throw new java.lang.NullPointerException("items cannot be null"); + if (items == null) { + throw new java.lang.NullPointerException("items cannot be null"); + } if (this.items == null) this.items = new java.util.ArrayList(); this.items.addAll(items); return self(); diff --git a/test/transform/resource/after-ecj/BuilderDefaultsWarnings.java b/test/transform/resource/after-ecj/BuilderDefaultsWarnings.java index e9ecad90..bc773df3 100644 --- a/test/transform/resource/after-ecj/BuilderDefaultsWarnings.java +++ b/test/transform/resource/after-ecj/BuilderDefaultsWarnings.java @@ -24,7 +24,9 @@ public @Builder class BuilderDefaultsWarnings { } public @java.lang.SuppressWarnings("all") BuilderDefaultsWarnings.BuilderDefaultsWarningsBuilder items(final java.util.Collection items) { if ((items == null)) - throw new java.lang.NullPointerException("items cannot be null"); + { + throw new java.lang.NullPointerException("items cannot be null"); + } if ((this.items == null)) this.items = new java.util.ArrayList(); this.items.addAll(items); diff --git a/test/transform/resource/after-ecj/BuilderSingularAnnotatedTypes.java b/test/transform/resource/after-ecj/BuilderSingularAnnotatedTypes.java index a371de1c..977d081b 100644 --- a/test/transform/resource/after-ecj/BuilderSingularAnnotatedTypes.java +++ b/test/transform/resource/after-ecj/BuilderSingularAnnotatedTypes.java @@ -26,7 +26,9 @@ import lombok.Singular; } public @java.lang.SuppressWarnings("all") BuilderSingularAnnotatedTypes.BuilderSingularAnnotatedTypesBuilder foos(final java.util.Collection foos) { if ((foos == null)) - throw new java.lang.NullPointerException("foos cannot be null"); + { + throw new java.lang.NullPointerException("foos cannot be null"); + } if ((this.foos == null)) this.foos = new java.util.ArrayList<@MyAnnotation @NonNull String>(); this.foos.addAll(foos); @@ -57,7 +59,9 @@ import lombok.Singular; } public @java.lang.SuppressWarnings("all") BuilderSingularAnnotatedTypes.BuilderSingularAnnotatedTypesBuilder bars(final java.util.Map bars) { if ((bars == null)) - throw new java.lang.NullPointerException("bars cannot be null"); + { + throw new java.lang.NullPointerException("bars cannot be null"); + } if ((this.bars$key == null)) { this.bars$key = new java.util.ArrayList<@MyAnnotation @NonNull String>(); diff --git a/test/transform/resource/after-ecj/BuilderSingularAnnotatedTypesWithSetterPrefix.java b/test/transform/resource/after-ecj/BuilderSingularAnnotatedTypesWithSetterPrefix.java index cbb73c2f..96f346d4 100644 --- a/test/transform/resource/after-ecj/BuilderSingularAnnotatedTypesWithSetterPrefix.java +++ b/test/transform/resource/after-ecj/BuilderSingularAnnotatedTypesWithSetterPrefix.java @@ -26,7 +26,9 @@ import lombok.Singular; } public @java.lang.SuppressWarnings("all") BuilderSingularAnnotatedTypesWithSetterPrefix.BuilderSingularAnnotatedTypesWithSetterPrefixBuilder withFoos(final java.util.Collection foos) { if ((foos == null)) - throw new java.lang.NullPointerException("foos cannot be null"); + { + throw new java.lang.NullPointerException("foos cannot be null"); + } if ((this.foos == null)) this.foos = new java.util.ArrayList<@MyAnnotation @NonNull String>(); this.foos.addAll(foos); @@ -57,7 +59,9 @@ import lombok.Singular; } public @java.lang.SuppressWarnings("all") BuilderSingularAnnotatedTypesWithSetterPrefix.BuilderSingularAnnotatedTypesWithSetterPrefixBuilder withBars(final java.util.Map bars) { if ((bars == null)) - throw new java.lang.NullPointerException("bars cannot be null"); + { + throw new java.lang.NullPointerException("bars cannot be null"); + } if ((this.bars$key == null)) { this.bars$key = new java.util.ArrayList<@MyAnnotation @NonNull String>(); diff --git a/test/transform/resource/after-ecj/BuilderSingularGuavaListsSets.java b/test/transform/resource/after-ecj/BuilderSingularGuavaListsSets.java index d0c68234..ce159288 100644 --- a/test/transform/resource/after-ecj/BuilderSingularGuavaListsSets.java +++ b/test/transform/resource/after-ecj/BuilderSingularGuavaListsSets.java @@ -22,7 +22,9 @@ import lombok.Singular; } public @java.lang.SuppressWarnings("all") BuilderSingularGuavaListsSets.BuilderSingularGuavaListsSetsBuilder cards(final java.lang.Iterable cards) { if ((cards == null)) - throw new java.lang.NullPointerException("cards cannot be null"); + { + throw new java.lang.NullPointerException("cards cannot be null"); + } if ((this.cards == null)) this.cards = com.google.common.collect.ImmutableList.builder(); this.cards.addAll(cards); @@ -40,7 +42,9 @@ import lombok.Singular; } public @java.lang.SuppressWarnings("all") BuilderSingularGuavaListsSets.BuilderSingularGuavaListsSetsBuilder frogs(final java.lang.Iterable frogs) { if ((frogs == null)) - throw new java.lang.NullPointerException("frogs cannot be null"); + { + throw new java.lang.NullPointerException("frogs cannot be null"); + } if ((this.frogs == null)) this.frogs = com.google.common.collect.ImmutableList.builder(); this.frogs.addAll(frogs); @@ -58,7 +62,9 @@ import lombok.Singular; } public @java.lang.SuppressWarnings("all") BuilderSingularGuavaListsSets.BuilderSingularGuavaListsSetsBuilder rawSet(final java.lang.Iterable rawSet) { if ((rawSet == null)) - throw new java.lang.NullPointerException("rawSet cannot be null"); + { + throw new java.lang.NullPointerException("rawSet cannot be null"); + } if ((this.rawSet == null)) this.rawSet = com.google.common.collect.ImmutableSet.builder(); this.rawSet.addAll(rawSet); @@ -76,7 +82,9 @@ import lombok.Singular; } public @java.lang.SuppressWarnings("all") BuilderSingularGuavaListsSets.BuilderSingularGuavaListsSetsBuilder passes(final java.lang.Iterable passes) { if ((passes == null)) - throw new java.lang.NullPointerException("passes cannot be null"); + { + throw new java.lang.NullPointerException("passes cannot be null"); + } if ((this.passes == null)) this.passes = com.google.common.collect.ImmutableSortedSet.naturalOrder(); this.passes.addAll(passes); @@ -94,7 +102,9 @@ import lombok.Singular; } public @java.lang.SuppressWarnings("all") BuilderSingularGuavaListsSets.BuilderSingularGuavaListsSetsBuilder users(final com.google.common.collect.Table users) { if ((users == null)) - throw new java.lang.NullPointerException("users cannot be null"); + { + throw new java.lang.NullPointerException("users cannot be null"); + } if ((this.users == null)) this.users = com.google.common.collect.ImmutableTable.builder(); this.users.putAll(users); diff --git a/test/transform/resource/after-ecj/BuilderSingularGuavaMaps.java b/test/transform/resource/after-ecj/BuilderSingularGuavaMaps.java index 08c72f98..76e6653b 100644 --- a/test/transform/resource/after-ecj/BuilderSingularGuavaMaps.java +++ b/test/transform/resource/after-ecj/BuilderSingularGuavaMaps.java @@ -18,7 +18,9 @@ import lombok.Singular; } public @java.lang.SuppressWarnings("all") BuilderSingularGuavaMaps.BuilderSingularGuavaMapsBuilder battleaxes(final java.util.Map battleaxes) { if ((battleaxes == null)) - throw new java.lang.NullPointerException("battleaxes cannot be null"); + { + throw new java.lang.NullPointerException("battleaxes cannot be null"); + } if ((this.battleaxes == null)) this.battleaxes = com.google.common.collect.ImmutableMap.builder(); this.battleaxes.putAll(battleaxes); @@ -36,7 +38,9 @@ import lombok.Singular; } public @java.lang.SuppressWarnings("all") BuilderSingularGuavaMaps.BuilderSingularGuavaMapsBuilder vertices(final java.util.Map vertices) { if ((vertices == null)) - throw new java.lang.NullPointerException("vertices cannot be null"); + { + throw new java.lang.NullPointerException("vertices cannot be null"); + } if ((this.vertices == null)) this.vertices = com.google.common.collect.ImmutableSortedMap.naturalOrder(); this.vertices.putAll(vertices); @@ -54,7 +58,9 @@ import lombok.Singular; } public @java.lang.SuppressWarnings("all") BuilderSingularGuavaMaps.BuilderSingularGuavaMapsBuilder rawMap(final java.util.Map rawMap) { if ((rawMap == null)) - throw new java.lang.NullPointerException("rawMap cannot be null"); + { + throw new java.lang.NullPointerException("rawMap cannot be null"); + } if ((this.rawMap == null)) this.rawMap = com.google.common.collect.ImmutableBiMap.builder(); this.rawMap.putAll(rawMap); diff --git a/test/transform/resource/after-ecj/BuilderSingularLists.java b/test/transform/resource/after-ecj/BuilderSingularLists.java index c201a32b..712b5e86 100644 --- a/test/transform/resource/after-ecj/BuilderSingularLists.java +++ b/test/transform/resource/after-ecj/BuilderSingularLists.java @@ -18,7 +18,9 @@ import lombok.Singular; } public @java.lang.SuppressWarnings("all") BuilderSingularLists.BuilderSingularListsBuilder children(final java.util.Collection children) { if ((children == null)) - throw new java.lang.NullPointerException("children cannot be null"); + { + throw new java.lang.NullPointerException("children cannot be null"); + } if ((this.children == null)) this.children = new java.util.ArrayList(); this.children.addAll(children); @@ -37,7 +39,9 @@ import lombok.Singular; } public @java.lang.SuppressWarnings("all") BuilderSingularLists.BuilderSingularListsBuilder scarves(final java.util.Collection scarves) { if ((scarves == null)) - throw new java.lang.NullPointerException("scarves cannot be null"); + { + throw new java.lang.NullPointerException("scarves cannot be null"); + } if ((this.scarves == null)) this.scarves = new java.util.ArrayList(); this.scarves.addAll(scarves); @@ -56,7 +60,9 @@ import lombok.Singular; } public @java.lang.SuppressWarnings("all") BuilderSingularLists.BuilderSingularListsBuilder rawList(final java.util.Collection rawList) { if ((rawList == null)) - throw new java.lang.NullPointerException("rawList cannot be null"); + { + throw new java.lang.NullPointerException("rawList cannot be null"); + } if ((this.rawList == null)) this.rawList = new java.util.ArrayList(); this.rawList.addAll(rawList); diff --git a/test/transform/resource/after-ecj/BuilderSingularMaps.java b/test/transform/resource/after-ecj/BuilderSingularMaps.java index d53e7022..072cf5e7 100644 --- a/test/transform/resource/after-ecj/BuilderSingularMaps.java +++ b/test/transform/resource/after-ecj/BuilderSingularMaps.java @@ -26,7 +26,9 @@ import lombok.Singular; } public @java.lang.SuppressWarnings("all") BuilderSingularMaps.BuilderSingularMapsBuilder women(final java.util.Map women) { if ((women == null)) - throw new java.lang.NullPointerException("women cannot be null"); + { + throw new java.lang.NullPointerException("women cannot be null"); + } if ((this.women$key == null)) { this.women$key = new java.util.ArrayList(); @@ -59,7 +61,9 @@ import lombok.Singular; } public @java.lang.SuppressWarnings("all") BuilderSingularMaps.BuilderSingularMapsBuilder men(final java.util.Map men) { if ((men == null)) - throw new java.lang.NullPointerException("men cannot be null"); + { + throw new java.lang.NullPointerException("men cannot be null"); + } if ((this.men$key == null)) { this.men$key = new java.util.ArrayList(); @@ -92,7 +96,9 @@ import lombok.Singular; } public @java.lang.SuppressWarnings("all") BuilderSingularMaps.BuilderSingularMapsBuilder rawMap(final java.util.Map rawMap) { if ((rawMap == null)) - throw new java.lang.NullPointerException("rawMap cannot be null"); + { + throw new java.lang.NullPointerException("rawMap cannot be null"); + } if ((this.rawMap$key == null)) { this.rawMap$key = new java.util.ArrayList(); @@ -125,7 +131,9 @@ import lombok.Singular; } public @java.lang.SuppressWarnings("all") BuilderSingularMaps.BuilderSingularMapsBuilder stringMap(final java.util.Map stringMap) { if ((stringMap == null)) - throw new java.lang.NullPointerException("stringMap cannot be null"); + { + throw new java.lang.NullPointerException("stringMap cannot be null"); + } if ((this.stringMap$key == null)) { this.stringMap$key = new java.util.ArrayList(); diff --git a/test/transform/resource/after-ecj/BuilderSingularMapsWithSetterPrefix.java b/test/transform/resource/after-ecj/BuilderSingularMapsWithSetterPrefix.java index 0bddd22c..dfa495bf 100644 --- a/test/transform/resource/after-ecj/BuilderSingularMapsWithSetterPrefix.java +++ b/test/transform/resource/after-ecj/BuilderSingularMapsWithSetterPrefix.java @@ -25,19 +25,20 @@ import lombok.Singular; return this; } public @java.lang.SuppressWarnings("all") BuilderSingularMapsWithSetterPrefix.BuilderSingularMapsWithSetterPrefixBuilder withWomen(final java.util.Map women) { - if ((women != null)) + if ((women == null)) { - if ((this.women$key == null)) - { - this.women$key = new java.util.ArrayList(); - this.women$value = new java.util.ArrayList(); - } - for (java.util.Map.Entry $lombokEntry : women.entrySet()) - { - this.women$key.add($lombokEntry.getKey()); - this.women$value.add($lombokEntry.getValue()); - } + throw new java.lang.NullPointerException("women cannot be null"); + } + if ((this.women$key == null)) + { + this.women$key = new java.util.ArrayList(); + this.women$value = new java.util.ArrayList(); } + for (java.util.Map.Entry $lombokEntry : women.entrySet()) + { + this.women$key.add($lombokEntry.getKey()); + this.women$value.add($lombokEntry.getValue()); + } return this; } public @java.lang.SuppressWarnings("all") BuilderSingularMapsWithSetterPrefix.BuilderSingularMapsWithSetterPrefixBuilder clearWomen() { @@ -59,19 +60,20 @@ import lombok.Singular; return this; } public @java.lang.SuppressWarnings("all") BuilderSingularMapsWithSetterPrefix.BuilderSingularMapsWithSetterPrefixBuilder withMen(final java.util.Map men) { - if ((men != null)) + if ((men == null)) { - if ((this.men$key == null)) - { - this.men$key = new java.util.ArrayList(); - this.men$value = new java.util.ArrayList(); - } - for (java.util.Map.Entry $lombokEntry : men.entrySet()) - { - this.men$key.add($lombokEntry.getKey()); - this.men$value.add($lombokEntry.getValue()); - } + throw new java.lang.NullPointerException("men cannot be null"); } + if ((this.men$key == null)) + { + this.men$key = new java.util.ArrayList(); + this.men$value = new java.util.ArrayList(); + } + for (java.util.Map.Entry $lombokEntry : men.entrySet()) + { + this.men$key.add($lombokEntry.getKey()); + this.men$value.add($lombokEntry.getValue()); + } return this; } public @java.lang.SuppressWarnings("all") BuilderSingularMapsWithSetterPrefix.BuilderSingularMapsWithSetterPrefixBuilder clearMen() { @@ -127,19 +129,20 @@ import lombok.Singular; return this; } public @java.lang.SuppressWarnings("all") BuilderSingularMapsWithSetterPrefix.BuilderSingularMapsWithSetterPrefixBuilder withStringMap(final java.util.Map stringMap) { - if ((stringMap != null)) + if ((stringMap == null)) { - if ((this.stringMap$key == null)) - { - this.stringMap$key = new java.util.ArrayList(); - this.stringMap$value = new java.util.ArrayList(); - } - for (java.util.Map.Entry $lombokEntry : stringMap.entrySet()) - { - this.stringMap$key.add($lombokEntry.getKey()); - this.stringMap$value.add($lombokEntry.getValue()); - } + throw new java.lang.NullPointerException("stringMap cannot be null"); + } + if ((this.stringMap$key == null)) + { + this.stringMap$key = new java.util.ArrayList(); + this.stringMap$value = new java.util.ArrayList(); } + for (java.util.Map.Entry $lombokEntry : stringMap.entrySet()) + { + this.stringMap$key.add($lombokEntry.getKey()); + this.stringMap$value.add($lombokEntry.getValue()); + } return this; } public @java.lang.SuppressWarnings("all") BuilderSingularMapsWithSetterPrefix.BuilderSingularMapsWithSetterPrefixBuilder clearStringMap() { @@ -206,7 +209,7 @@ import lombok.Singular; } private @Singular Map women; private @Singular SortedMap men; - private @SuppressWarnings("all") @Singular("rawMap") Map rawMap; + private @SuppressWarnings("all") @Singular(value = "rawMap",ignoreNullCollections = true) Map rawMap; private @Singular("stringMap") Map stringMap; @java.lang.SuppressWarnings("all") BuilderSingularMapsWithSetterPrefix(final Map women, final SortedMap men, final Map rawMap, final Map stringMap) { super(); diff --git a/test/transform/resource/after-ecj/BuilderSingularNoAuto.java b/test/transform/resource/after-ecj/BuilderSingularNoAuto.java index 47b413b3..80870c34 100644 --- a/test/transform/resource/after-ecj/BuilderSingularNoAuto.java +++ b/test/transform/resource/after-ecj/BuilderSingularNoAuto.java @@ -16,7 +16,9 @@ import lombok.Singular; } public @java.lang.SuppressWarnings("all") BuilderSingularNoAuto.BuilderSingularNoAutoBuilder things(final java.util.Collection things) { if ((things == null)) - throw new java.lang.NullPointerException("things cannot be null"); + { + throw new java.lang.NullPointerException("things cannot be null"); + } if ((this.things == null)) this.things = new java.util.ArrayList(); this.things.addAll(things); @@ -35,7 +37,9 @@ import lombok.Singular; } public @java.lang.SuppressWarnings("all") BuilderSingularNoAuto.BuilderSingularNoAutoBuilder widgets(final java.util.Collection widgets) { if ((widgets == null)) - throw new java.lang.NullPointerException("widgets cannot be null"); + { + throw new java.lang.NullPointerException("widgets cannot be null"); + } if ((this.widgets == null)) this.widgets = new java.util.ArrayList(); this.widgets.addAll(widgets); @@ -54,7 +58,9 @@ import lombok.Singular; } public @java.lang.SuppressWarnings("all") BuilderSingularNoAuto.BuilderSingularNoAutoBuilder items(final java.util.Collection items) { if ((items == null)) - throw new java.lang.NullPointerException("items cannot be null"); + { + throw new java.lang.NullPointerException("items cannot be null"); + } if ((this.items == null)) this.items = new java.util.ArrayList(); this.items.addAll(items); diff --git a/test/transform/resource/after-ecj/BuilderSingularNoAutoWithSetterPrefix.java b/test/transform/resource/after-ecj/BuilderSingularNoAutoWithSetterPrefix.java index 85cfda71..a3a02841 100644 --- a/test/transform/resource/after-ecj/BuilderSingularNoAutoWithSetterPrefix.java +++ b/test/transform/resource/after-ecj/BuilderSingularNoAutoWithSetterPrefix.java @@ -16,7 +16,9 @@ import lombok.Singular; } public @java.lang.SuppressWarnings("all") BuilderSingularNoAutoWithSetterPrefix.BuilderSingularNoAutoWithSetterPrefixBuilder withThings(final java.util.Collection things) { if ((things == null)) - throw new java.lang.NullPointerException("things cannot be null"); + { + throw new java.lang.NullPointerException("things cannot be null"); + } if ((this.things == null)) this.things = new java.util.ArrayList(); this.things.addAll(things); @@ -35,7 +37,9 @@ import lombok.Singular; } public @java.lang.SuppressWarnings("all") BuilderSingularNoAutoWithSetterPrefix.BuilderSingularNoAutoWithSetterPrefixBuilder withWidgets(final java.util.Collection widgets) { if ((widgets == null)) - throw new java.lang.NullPointerException("widgets cannot be null"); + { + throw new java.lang.NullPointerException("widgets cannot be null"); + } if ((this.widgets == null)) this.widgets = new java.util.ArrayList(); this.widgets.addAll(widgets); @@ -54,7 +58,9 @@ import lombok.Singular; } public @java.lang.SuppressWarnings("all") BuilderSingularNoAutoWithSetterPrefix.BuilderSingularNoAutoWithSetterPrefixBuilder withItems(final java.util.Collection items) { if ((items == null)) - throw new java.lang.NullPointerException("items cannot be null"); + { + throw new java.lang.NullPointerException("items cannot be null"); + } if ((this.items == null)) this.items = new java.util.ArrayList(); this.items.addAll(items); diff --git a/test/transform/resource/after-ecj/BuilderSingularNullBehavior1.java b/test/transform/resource/after-ecj/BuilderSingularNullBehavior1.java index 7ef52eb8..a0725f8a 100644 --- a/test/transform/resource/after-ecj/BuilderSingularNullBehavior1.java +++ b/test/transform/resource/after-ecj/BuilderSingularNullBehavior1.java @@ -1,13 +1,10 @@ import java.util.List; import java.util.Collection; import lombok.Singular; -import lombok.Singular.NullCollectionBehavior; @lombok.Builder class BuilderSingularNullBehavior1 { public static @java.lang.SuppressWarnings("all") class BuilderSingularNullBehavior1Builder { private @java.lang.SuppressWarnings("all") java.util.ArrayList names; private @java.lang.SuppressWarnings("all") java.util.ArrayList locations; - private @java.lang.SuppressWarnings("all") java.util.ArrayList whatevers; - private @java.lang.SuppressWarnings("all") java.util.ArrayList doohickeys; @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior1Builder() { super(); } @@ -17,9 +14,8 @@ import lombok.Singular.NullCollectionBehavior; this.names.add(name); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior1.BuilderSingularNullBehavior1Builder names(final java.util.Collection names) { - if ((names == null)) - throw new java.lang.NullPointerException("names cannot be null"); + public @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior1.BuilderSingularNullBehavior1Builder names(final java.util. @org.checkerframework.checker.nullness.qual.NonNull Collection names) { + assert (names != null): "names cannot be null"; if ((this.names == null)) this.names = new java.util.ArrayList(); this.names.addAll(names); @@ -36,11 +32,13 @@ import lombok.Singular.NullCollectionBehavior; this.locations.add(location); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior1.BuilderSingularNullBehavior1Builder locations(final java.util.Collection locations) { - java.util.Objects.requireNonNull(locations, "locations cannot be null"); - if ((this.locations == null)) - this.locations = new java.util.ArrayList(); - this.locations.addAll(locations); + public @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior1.BuilderSingularNullBehavior1Builder locations(final java.util. @org.checkerframework.checker.nullness.qual.Nullable Collection locations) { + if ((locations != null)) + { + if ((this.locations == null)) + this.locations = new java.util.ArrayList(); + this.locations.addAll(locations); + } return this; } public @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior1.BuilderSingularNullBehavior1Builder clearLocations() { @@ -48,44 +46,6 @@ import lombok.Singular.NullCollectionBehavior; this.locations.clear(); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior1.BuilderSingularNullBehavior1Builder whatever(final String whatever) { - if ((this.whatevers == null)) - this.whatevers = new java.util.ArrayList(); - this.whatevers.add(whatever); - return this; - } - public @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior1.BuilderSingularNullBehavior1Builder whatevers(final java.util.Collection whatevers) { - com.google.common.base.Preconditions.checkNotNull(whatevers, "whatevers cannot be null"); - if ((this.whatevers == null)) - this.whatevers = new java.util.ArrayList(); - this.whatevers.addAll(whatevers); - return this; - } - public @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior1.BuilderSingularNullBehavior1Builder clearWhatevers() { - if ((this.whatevers != null)) - this.whatevers.clear(); - return this; - } - public @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior1.BuilderSingularNullBehavior1Builder doohickey(final String doohickey) { - if ((this.doohickeys == null)) - this.doohickeys = new java.util.ArrayList(); - this.doohickeys.add(doohickey); - return this; - } - public @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior1.BuilderSingularNullBehavior1Builder doohickeys(final java.util.Collection doohickeys) { - if ((doohickeys != null)) - { - if ((this.doohickeys == null)) - this.doohickeys = new java.util.ArrayList(); - this.doohickeys.addAll(doohickeys); - } - return this; - } - public @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior1.BuilderSingularNullBehavior1Builder clearDoohickeys() { - if ((this.doohickeys != null)) - this.doohickeys.clear(); - return this; - } public @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior1 build() { java.util.List names; switch (((this.names == null) ? 0 : this.names.size())) { @@ -109,44 +69,18 @@ import lombok.Singular.NullCollectionBehavior; default : locations = java.util.Collections.unmodifiableList(new java.util.ArrayList(this.locations)); } - java.util.List whatevers; - switch (((this.whatevers == null) ? 0 : this.whatevers.size())) { - case 0 : - whatevers = java.util.Collections.emptyList(); - break; - case 1 : - whatevers = java.util.Collections.singletonList(this.whatevers.get(0)); - break; - default : - whatevers = java.util.Collections.unmodifiableList(new java.util.ArrayList(this.whatevers)); - } - java.util.List doohickeys; - switch (((this.doohickeys == null) ? 0 : this.doohickeys.size())) { - case 0 : - doohickeys = java.util.Collections.emptyList(); - break; - case 1 : - doohickeys = java.util.Collections.singletonList(this.doohickeys.get(0)); - break; - default : - doohickeys = java.util.Collections.unmodifiableList(new java.util.ArrayList(this.doohickeys)); - } - return new BuilderSingularNullBehavior1(names, locations, whatevers, doohickeys); + return new BuilderSingularNullBehavior1(names, locations); } - public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { - return (((((((("BuilderSingularNullBehavior1.BuilderSingularNullBehavior1Builder(names=" + this.names) + ", locations=") + this.locations) + ", whatevers=") + this.whatevers) + ", doohickeys=") + this.doohickeys) + ")"); + public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.@org.checkerframework.checker.nullness.qual.NonNull String toString() { + return (((("BuilderSingularNullBehavior1.BuilderSingularNullBehavior1Builder(names=" + this.names) + ", locations=") + this.locations) + ")"); } } private @Singular List names; - private @Singular(nullBehavior = Singular.NullCollectionBehavior.JDK) List locations; - private @Singular(nullBehavior = NullCollectionBehavior.GUAVA) List whatevers; - private @Singular(nullBehavior = lombok.Singular.NullCollectionBehavior.IGNORE) List doohickeys; - @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior1(final List names, final List locations, final List whatevers, final List doohickeys) { + private @Singular(ignoreNullCollections = true) List locations; + @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior1(final List names, final List locations) { super(); this.names = names; this.locations = locations; - this.whatevers = whatevers; - this.doohickeys = doohickeys; } public static @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior1.BuilderSingularNullBehavior1Builder builder() { return new BuilderSingularNullBehavior1.BuilderSingularNullBehavior1Builder(); diff --git a/test/transform/resource/after-ecj/BuilderSingularNullBehavior2.java b/test/transform/resource/after-ecj/BuilderSingularNullBehavior2.java index 308a5174..85f9fb21 100644 --- a/test/transform/resource/after-ecj/BuilderSingularNullBehavior2.java +++ b/test/transform/resource/after-ecj/BuilderSingularNullBehavior2.java @@ -1,10 +1,8 @@ import java.util.List; import lombok.Singular; -import lombok.Singular.NullCollectionBehavior; @lombok.Builder class BuilderSingularNullBehavior2 { public static @java.lang.SuppressWarnings("all") class BuilderSingularNullBehavior2Builder { private @java.lang.SuppressWarnings("all") java.util.ArrayList locations; - private @java.lang.SuppressWarnings("all") java.util.ArrayList doohickeys; @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior2Builder() { super(); } @@ -14,7 +12,7 @@ import lombok.Singular.NullCollectionBehavior; this.locations.add(location); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior2.BuilderSingularNullBehavior2Builder locations(final java.util. @org.checkerframework.checker.nullness.qual.NonNull Collection locations) { + public @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior2.BuilderSingularNullBehavior2Builder locations(final @org.springframework.lang.NonNull java.util.Collection locations) { java.util.Objects.requireNonNull(locations, "locations cannot be null"); if ((this.locations == null)) this.locations = new java.util.ArrayList(); @@ -26,26 +24,6 @@ import lombok.Singular.NullCollectionBehavior; this.locations.clear(); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior2.BuilderSingularNullBehavior2Builder doohickey(final String doohickey) { - if ((this.doohickeys == null)) - this.doohickeys = new java.util.ArrayList(); - this.doohickeys.add(doohickey); - return this; - } - public @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior2.BuilderSingularNullBehavior2Builder doohickeys(final java.util. @org.checkerframework.checker.nullness.qual.Nullable Collection doohickeys) { - if ((doohickeys != null)) - { - if ((this.doohickeys == null)) - this.doohickeys = new java.util.ArrayList(); - this.doohickeys.addAll(doohickeys); - } - return this; - } - public @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior2.BuilderSingularNullBehavior2Builder clearDoohickeys() { - if ((this.doohickeys != null)) - this.doohickeys.clear(); - return this; - } public @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior2 build() { java.util.List locations; switch (((this.locations == null) ? 0 : this.locations.size())) { @@ -58,31 +36,18 @@ import lombok.Singular.NullCollectionBehavior; default : locations = java.util.Collections.unmodifiableList(new java.util.ArrayList(this.locations)); } - java.util.List doohickeys; - switch (((this.doohickeys == null) ? 0 : this.doohickeys.size())) { - case 0 : - doohickeys = java.util.Collections.emptyList(); - break; - case 1 : - doohickeys = java.util.Collections.singletonList(this.doohickeys.get(0)); - break; - default : - doohickeys = java.util.Collections.unmodifiableList(new java.util.ArrayList(this.doohickeys)); - } - return new BuilderSingularNullBehavior2(locations, doohickeys); + return new BuilderSingularNullBehavior2(locations); } - public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.@org.checkerframework.checker.nullness.qual.NonNull String toString() { - return (((("BuilderSingularNullBehavior2.BuilderSingularNullBehavior2Builder(locations=" + this.locations) + ", doohickeys=") + this.doohickeys) + ")"); + public @java.lang.Override @org.springframework.lang.NonNull @java.lang.SuppressWarnings("all") java.lang.String toString() { + return (("BuilderSingularNullBehavior2.BuilderSingularNullBehavior2Builder(locations=" + this.locations) + ")"); } } - private @Singular(nullBehavior = Singular.NullCollectionBehavior.JDK) List locations; - private @Singular(nullBehavior = lombok.Singular.NullCollectionBehavior.IGNORE) List doohickeys; - @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior2(final List locations, final List doohickeys) { + private @Singular List locations; + @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior2(final List locations) { super(); this.locations = locations; - this.doohickeys = doohickeys; } public static @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/BuilderSingularRedirectToGuava.java b/test/transform/resource/after-ecj/BuilderSingularRedirectToGuava.java index 867bf7fa..73f24f97 100644 --- a/test/transform/resource/after-ecj/BuilderSingularRedirectToGuava.java +++ b/test/transform/resource/after-ecj/BuilderSingularRedirectToGuava.java @@ -18,7 +18,9 @@ import lombok.Singular; } public @java.lang.SuppressWarnings("all") BuilderSingularRedirectToGuava.BuilderSingularRedirectToGuavaBuilder dangerMice(final java.lang.Iterable dangerMice) { if ((dangerMice == null)) - throw new java.lang.NullPointerException("dangerMice cannot be null"); + { + throw new java.lang.NullPointerException("dangerMice cannot be null"); + } if ((this.dangerMice == null)) this.dangerMice = com.google.common.collect.ImmutableSet.builder(); this.dangerMice.addAll(dangerMice); @@ -36,7 +38,9 @@ import lombok.Singular; } public @java.lang.SuppressWarnings("all") BuilderSingularRedirectToGuava.BuilderSingularRedirectToGuavaBuilder things(final java.util.Map things) { if ((things == null)) - throw new java.lang.NullPointerException("things cannot be null"); + { + throw new java.lang.NullPointerException("things cannot be null"); + } if ((this.things == null)) this.things = com.google.common.collect.ImmutableSortedMap.naturalOrder(); this.things.putAll(things); @@ -54,7 +58,9 @@ import lombok.Singular; } public @java.lang.SuppressWarnings("all") BuilderSingularRedirectToGuava.BuilderSingularRedirectToGuavaBuilder doohickeys(final java.lang.Iterable> doohickeys) { if ((doohickeys == null)) - throw new java.lang.NullPointerException("doohickeys cannot be null"); + { + throw new java.lang.NullPointerException("doohickeys cannot be null"); + } if ((this.doohickeys == null)) this.doohickeys = com.google.common.collect.ImmutableList.builder(); this.doohickeys.addAll(doohickeys); diff --git a/test/transform/resource/after-ecj/BuilderSingularSets.java b/test/transform/resource/after-ecj/BuilderSingularSets.java index 6cfa5203..8e1f4484 100644 --- a/test/transform/resource/after-ecj/BuilderSingularSets.java +++ b/test/transform/resource/after-ecj/BuilderSingularSets.java @@ -18,7 +18,9 @@ import lombok.Singular; } public @java.lang.SuppressWarnings("all") BuilderSingularSets.BuilderSingularSetsBuilder dangerMice(final java.util.Collection dangerMice) { if ((dangerMice == null)) - throw new java.lang.NullPointerException("dangerMice cannot be null"); + { + throw new java.lang.NullPointerException("dangerMice cannot be null"); + } if ((this.dangerMice == null)) this.dangerMice = new java.util.ArrayList(); this.dangerMice.addAll(dangerMice); @@ -37,7 +39,9 @@ import lombok.Singular; } public @java.lang.SuppressWarnings("all") BuilderSingularSets.BuilderSingularSetsBuilder octopodes(final java.util.Collection octopodes) { if ((octopodes == null)) - throw new java.lang.NullPointerException("octopodes cannot be null"); + { + throw new java.lang.NullPointerException("octopodes cannot be null"); + } if ((this.octopodes == null)) this.octopodes = new java.util.ArrayList(); this.octopodes.addAll(octopodes); @@ -56,7 +60,9 @@ import lombok.Singular; } public @java.lang.SuppressWarnings("all") BuilderSingularSets.BuilderSingularSetsBuilder rawSet(final java.util.Collection rawSet) { if ((rawSet == null)) - throw new java.lang.NullPointerException("rawSet cannot be null"); + { + throw new java.lang.NullPointerException("rawSet cannot be null"); + } if ((this.rawSet == null)) this.rawSet = new java.util.ArrayList(); this.rawSet.addAll(rawSet); @@ -75,7 +81,9 @@ import lombok.Singular; } public @java.lang.SuppressWarnings("all") BuilderSingularSets.BuilderSingularSetsBuilder stringSet(final java.util.Collection stringSet) { if ((stringSet == null)) - throw new java.lang.NullPointerException("stringSet cannot be null"); + { + throw new java.lang.NullPointerException("stringSet cannot be null"); + } if ((this.stringSet == null)) this.stringSet = new java.util.ArrayList(); this.stringSet.addAll(stringSet); diff --git a/test/transform/resource/after-ecj/BuilderSingularSetsWithSetterPrefix.java b/test/transform/resource/after-ecj/BuilderSingularSetsWithSetterPrefix.java index cdc0390c..0dc91851 100644 --- a/test/transform/resource/after-ecj/BuilderSingularSetsWithSetterPrefix.java +++ b/test/transform/resource/after-ecj/BuilderSingularSetsWithSetterPrefix.java @@ -18,7 +18,9 @@ import lombok.Singular; } public @java.lang.SuppressWarnings("all") BuilderSingularSetsWithSetterPrefix.BuilderSingularSetsWithSetterPrefixBuilder withDangerMice(final java.util.Collection dangerMice) { if ((dangerMice == null)) - throw new java.lang.NullPointerException("dangerMice cannot be null"); + { + throw new java.lang.NullPointerException("dangerMice cannot be null"); + } if ((this.dangerMice == null)) this.dangerMice = new java.util.ArrayList(); this.dangerMice.addAll(dangerMice); @@ -37,7 +39,9 @@ import lombok.Singular; } public @java.lang.SuppressWarnings("all") BuilderSingularSetsWithSetterPrefix.BuilderSingularSetsWithSetterPrefixBuilder withOctopodes(final java.util.Collection octopodes) { if ((octopodes == null)) - throw new java.lang.NullPointerException("octopodes cannot be null"); + { + throw new java.lang.NullPointerException("octopodes cannot be null"); + } if ((this.octopodes == null)) this.octopodes = new java.util.ArrayList(); this.octopodes.addAll(octopodes); @@ -56,7 +60,9 @@ import lombok.Singular; } public @java.lang.SuppressWarnings("all") BuilderSingularSetsWithSetterPrefix.BuilderSingularSetsWithSetterPrefixBuilder withRawSet(final java.util.Collection rawSet) { if ((rawSet == null)) - throw new java.lang.NullPointerException("rawSet cannot be null"); + { + throw new java.lang.NullPointerException("rawSet cannot be null"); + } if ((this.rawSet == null)) this.rawSet = new java.util.ArrayList(); this.rawSet.addAll(rawSet); @@ -75,7 +81,9 @@ import lombok.Singular; } public @java.lang.SuppressWarnings("all") BuilderSingularSetsWithSetterPrefix.BuilderSingularSetsWithSetterPrefixBuilder withStringSet(final java.util.Collection stringSet) { if ((stringSet == null)) - throw new java.lang.NullPointerException("stringSet cannot be null"); + { + throw new java.lang.NullPointerException("stringSet cannot be null"); + } if ((this.stringSet == null)) this.stringSet = new java.util.ArrayList(); this.stringSet.addAll(stringSet); diff --git a/test/transform/resource/after-ecj/BuilderSingularToBuilderWithNull.java b/test/transform/resource/after-ecj/BuilderSingularToBuilderWithNull.java index c01b5b8f..41ed6dcc 100644 --- a/test/transform/resource/after-ecj/BuilderSingularToBuilderWithNull.java +++ b/test/transform/resource/after-ecj/BuilderSingularToBuilderWithNull.java @@ -13,7 +13,9 @@ import lombok.Singular; } public @java.lang.SuppressWarnings("all") BuilderSingularToBuilderWithNull.BuilderSingularToBuilderWithNullBuilder elems(final java.util.Collection elems) { if ((elems == null)) - throw new java.lang.NullPointerException("elems cannot be null"); + { + throw new java.lang.NullPointerException("elems cannot be null"); + } if ((this.elems == null)) this.elems = new java.util.ArrayList(); this.elems.addAll(elems); diff --git a/test/transform/resource/after-ecj/BuilderSingularToBuilderWithNullWithSetterPrefix.java b/test/transform/resource/after-ecj/BuilderSingularToBuilderWithNullWithSetterPrefix.java index 092f0b55..6940cc08 100644 --- a/test/transform/resource/after-ecj/BuilderSingularToBuilderWithNullWithSetterPrefix.java +++ b/test/transform/resource/after-ecj/BuilderSingularToBuilderWithNullWithSetterPrefix.java @@ -13,7 +13,9 @@ import lombok.Singular; } public @java.lang.SuppressWarnings("all") BuilderSingularToBuilderWithNullWithSetterPrefix.BuilderSingularToBuilderWithNullWithSetterPrefixBuilder withElems(final java.util.Collection elems) { if ((elems == null)) - throw new java.lang.NullPointerException("elems cannot be null"); + { + throw new java.lang.NullPointerException("elems cannot be null"); + } if ((this.elems == null)) this.elems = new java.util.ArrayList(); this.elems.addAll(elems); diff --git a/test/transform/resource/after-ecj/BuilderSingularWildcardListsWithToBuilder.java b/test/transform/resource/after-ecj/BuilderSingularWildcardListsWithToBuilder.java index 8a00644d..bc5e2a50 100644 --- a/test/transform/resource/after-ecj/BuilderSingularWildcardListsWithToBuilder.java +++ b/test/transform/resource/after-ecj/BuilderSingularWildcardListsWithToBuilder.java @@ -16,7 +16,9 @@ import lombok.Singular; } public @java.lang.SuppressWarnings("all") BuilderSingularWildcardListsWithToBuilder.BuilderSingularWildcardListsWithToBuilderBuilder objects(final java.util.Collection objects) { if ((objects == null)) - throw new java.lang.NullPointerException("objects cannot be null"); + { + throw new java.lang.NullPointerException("objects cannot be null"); + } if ((this.objects == null)) this.objects = new java.util.ArrayList(); this.objects.addAll(objects); @@ -35,7 +37,9 @@ import lombok.Singular; } public @java.lang.SuppressWarnings("all") BuilderSingularWildcardListsWithToBuilder.BuilderSingularWildcardListsWithToBuilderBuilder numbers(final java.util.Collection numbers) { if ((numbers == null)) - throw new java.lang.NullPointerException("numbers cannot be null"); + { + throw new java.lang.NullPointerException("numbers cannot be null"); + } if ((this.numbers == null)) this.numbers = new java.util.ArrayList(); this.numbers.addAll(numbers); diff --git a/test/transform/resource/after-ecj/BuilderSingularWithPrefixes.java b/test/transform/resource/after-ecj/BuilderSingularWithPrefixes.java index b4fa5cbe..4bc79326 100644 --- a/test/transform/resource/after-ecj/BuilderSingularWithPrefixes.java +++ b/test/transform/resource/after-ecj/BuilderSingularWithPrefixes.java @@ -13,7 +13,9 @@ import lombok.Singular; } public @java.lang.SuppressWarnings("all") BuilderSingularWithPrefixes.BuilderSingularWithPrefixesBuilder elems(final java.util.Collection elems) { if ((elems == null)) - throw new java.lang.NullPointerException("elems cannot be null"); + { + throw new java.lang.NullPointerException("elems cannot be null"); + } if ((this.elems == null)) this.elems = new java.util.ArrayList(); this.elems.addAll(elems); diff --git a/test/transform/resource/after-ecj/BuilderSingularWithPrefixesWithSetterPrefix.java b/test/transform/resource/after-ecj/BuilderSingularWithPrefixesWithSetterPrefix.java index f10482d5..f492005b 100644 --- a/test/transform/resource/after-ecj/BuilderSingularWithPrefixesWithSetterPrefix.java +++ b/test/transform/resource/after-ecj/BuilderSingularWithPrefixesWithSetterPrefix.java @@ -13,7 +13,9 @@ import lombok.Singular; } public @java.lang.SuppressWarnings("all") BuilderSingularWithPrefixesWithSetterPrefix.BuilderSingularWithPrefixesWithSetterPrefixBuilder withElems(final java.util.Collection elems) { if ((elems == null)) - throw new java.lang.NullPointerException("elems cannot be null"); + { + throw new java.lang.NullPointerException("elems cannot be null"); + } if ((this.elems == null)) this.elems = new java.util.ArrayList(); this.elems.addAll(elems); diff --git a/test/transform/resource/after-ecj/BuilderWithDeprecated.java b/test/transform/resource/after-ecj/BuilderWithDeprecated.java index 9dcddc49..724a25e6 100644 --- a/test/transform/resource/after-ecj/BuilderWithDeprecated.java +++ b/test/transform/resource/after-ecj/BuilderWithDeprecated.java @@ -26,7 +26,9 @@ public @Builder class BuilderWithDeprecated { } public @java.lang.Deprecated @java.lang.SuppressWarnings("all") BuilderWithDeprecated.BuilderWithDeprecatedBuilder strings(final java.util.Collection strings) { if ((strings == null)) - throw new java.lang.NullPointerException("strings cannot be null"); + { + throw new java.lang.NullPointerException("strings cannot be null"); + } if ((this.strings == null)) this.strings = new java.util.ArrayList(); this.strings.addAll(strings); @@ -45,7 +47,9 @@ public @Builder class BuilderWithDeprecated { } public @java.lang.Deprecated @java.lang.SuppressWarnings("all") BuilderWithDeprecated.BuilderWithDeprecatedBuilder numbers(final java.lang.Iterable numbers) { if ((numbers == null)) - throw new java.lang.NullPointerException("numbers cannot be null"); + { + throw new java.lang.NullPointerException("numbers cannot be null"); + } if ((this.numbers == null)) this.numbers = com.google.common.collect.ImmutableList.builder(); this.numbers.addAll(numbers); diff --git a/test/transform/resource/after-ecj/BuilderWithToBuilder.java b/test/transform/resource/after-ecj/BuilderWithToBuilder.java index ec72bdb8..72fa3721 100644 --- a/test/transform/resource/after-ecj/BuilderWithToBuilder.java +++ b/test/transform/resource/after-ecj/BuilderWithToBuilder.java @@ -29,7 +29,9 @@ import lombok.Builder; } public @java.lang.SuppressWarnings("all") BuilderWithToBuilder.BuilderWithToBuilderBuilder bars(final java.util.Collection bars) { if ((bars == null)) - throw new java.lang.NullPointerException("bars cannot be null"); + { + throw new java.lang.NullPointerException("bars cannot be null"); + } if ((this.bars == null)) this.bars = new java.util.ArrayList(); this.bars.addAll(bars); diff --git a/test/transform/resource/after-ecj/CheckerFrameworkBuilder.java b/test/transform/resource/after-ecj/CheckerFrameworkBuilder.java index d9201e39..3f998df4 100644 --- a/test/transform/resource/after-ecj/CheckerFrameworkBuilder.java +++ b/test/transform/resource/after-ecj/CheckerFrameworkBuilder.java @@ -32,7 +32,9 @@ import lombok.Singular; } public @org.checkerframework.checker.builder.qual.ReturnsReceiver @java.lang.SuppressWarnings("all") CheckerFrameworkBuilder.CheckerFrameworkBuilderBuilder names(final java.util.Collection names) { if ((names == null)) - throw new java.lang.NullPointerException("names cannot be null"); + { + throw new java.lang.NullPointerException("names cannot be null"); + } if ((this.names == null)) this.names = new java.util.ArrayList(); this.names.addAll(names); diff --git a/test/transform/resource/after-ecj/CheckerFrameworkSuperBuilder.java b/test/transform/resource/after-ecj/CheckerFrameworkSuperBuilder.java index 94ec0a0c..163e9d68 100644 --- a/test/transform/resource/after-ecj/CheckerFrameworkSuperBuilder.java +++ b/test/transform/resource/after-ecj/CheckerFrameworkSuperBuilder.java @@ -33,7 +33,9 @@ class CheckerFrameworkSuperBuilder { } public @org.checkerframework.checker.builder.qual.ReturnsReceiver @java.lang.SuppressWarnings("all") B names(final java.util.Collection names) { if ((names == null)) - throw new java.lang.NullPointerException("names cannot be null"); + { + throw new java.lang.NullPointerException("names cannot be null"); + } if ((this.names == null)) this.names = new java.util.ArrayList(); this.names.addAll(names); diff --git a/test/transform/resource/after-ecj/SuperBuilderBasic.java b/test/transform/resource/after-ecj/SuperBuilderBasic.java index 9e686f0f..b47f318d 100644 --- a/test/transform/resource/after-ecj/SuperBuilderBasic.java +++ b/test/transform/resource/after-ecj/SuperBuilderBasic.java @@ -21,7 +21,9 @@ public class SuperBuilderBasic { } public @java.lang.SuppressWarnings("all") B items(final java.util.Collection items) { if ((items == null)) - throw new java.lang.NullPointerException("items cannot be null"); + { + throw new java.lang.NullPointerException("items cannot be null"); + } if ((this.items == null)) this.items = new java.util.ArrayList(); this.items.addAll(items); diff --git a/test/transform/resource/after-ecj/SuperBuilderBasicToBuilder.java b/test/transform/resource/after-ecj/SuperBuilderBasicToBuilder.java index e027c9d2..56703396 100644 --- a/test/transform/resource/after-ecj/SuperBuilderBasicToBuilder.java +++ b/test/transform/resource/after-ecj/SuperBuilderBasicToBuilder.java @@ -47,7 +47,9 @@ public class SuperBuilderBasicToBuilder { } public @java.lang.SuppressWarnings("all") B items(final java.util.Collection items) { if ((items == null)) - throw new java.lang.NullPointerException("items cannot be null"); + { + throw new java.lang.NullPointerException("items cannot be null"); + } if ((this.items == null)) this.items = new java.util.ArrayList(); this.items.addAll(items); diff --git a/test/transform/resource/after-ecj/SuperBuilderSingularAnnotatedTypes.java b/test/transform/resource/after-ecj/SuperBuilderSingularAnnotatedTypes.java index 834d2180..eac26153 100644 --- a/test/transform/resource/after-ecj/SuperBuilderSingularAnnotatedTypes.java +++ b/test/transform/resource/after-ecj/SuperBuilderSingularAnnotatedTypes.java @@ -28,7 +28,9 @@ import lombok.Singular; } public @java.lang.SuppressWarnings("all") B foos(final java.util.Collection foos) { if ((foos == null)) - throw new java.lang.NullPointerException("foos cannot be null"); + { + throw new java.lang.NullPointerException("foos cannot be null"); + } if ((this.foos == null)) this.foos = new java.util.ArrayList<@MyAnnotation @NonNull String>(); this.foos.addAll(foos); @@ -59,7 +61,9 @@ import lombok.Singular; } public @java.lang.SuppressWarnings("all") B bars(final java.util.Map bars) { if ((bars == null)) - throw new java.lang.NullPointerException("bars cannot be null"); + { + throw new java.lang.NullPointerException("bars cannot be null"); + } if ((this.bars$key == null)) { this.bars$key = new java.util.ArrayList<@MyAnnotation @NonNull String>(); diff --git a/test/transform/resource/after-ecj/SuperBuilderWithCustomBuilderMethod.java b/test/transform/resource/after-ecj/SuperBuilderWithCustomBuilderMethod.java index 6605ae1d..25f6f876 100644 --- a/test/transform/resource/after-ecj/SuperBuilderWithCustomBuilderMethod.java +++ b/test/transform/resource/after-ecj/SuperBuilderWithCustomBuilderMethod.java @@ -21,7 +21,9 @@ public class SuperBuilderWithCustomBuilderMethod { } public @java.lang.SuppressWarnings("all") B items(final java.util.Collection items) { if ((items == null)) - throw new java.lang.NullPointerException("items cannot be null"); + { + throw new java.lang.NullPointerException("items cannot be null"); + } if ((this.items == null)) this.items = new java.util.ArrayList(); this.items.addAll(items); diff --git a/test/transform/resource/after-ecj/SuperBuilderWithGenerics.java b/test/transform/resource/after-ecj/SuperBuilderWithGenerics.java index 89ab8821..6bda526e 100644 --- a/test/transform/resource/after-ecj/SuperBuilderWithGenerics.java +++ b/test/transform/resource/after-ecj/SuperBuilderWithGenerics.java @@ -21,7 +21,9 @@ public class SuperBuilderWithGenerics { } public @java.lang.SuppressWarnings("all") B items(final java.util.Collection items) { if ((items == null)) - throw new java.lang.NullPointerException("items cannot be null"); + { + throw new java.lang.NullPointerException("items cannot be null"); + } if ((this.items == null)) this.items = new java.util.ArrayList(); this.items.addAll(items); diff --git a/test/transform/resource/after-ecj/SuperBuilderWithGenerics2.java b/test/transform/resource/after-ecj/SuperBuilderWithGenerics2.java index 2037f7b0..4fac5de9 100644 --- a/test/transform/resource/after-ecj/SuperBuilderWithGenerics2.java +++ b/test/transform/resource/after-ecj/SuperBuilderWithGenerics2.java @@ -21,7 +21,9 @@ public class SuperBuilderWithGenerics2 { } public @java.lang.SuppressWarnings("all") B items(final java.util.Collection items) { if ((items == null)) - throw new java.lang.NullPointerException("items cannot be null"); + { + throw new java.lang.NullPointerException("items cannot be null"); + } if ((this.items == null)) this.items = new java.util.ArrayList(); this.items.addAll(items); diff --git a/test/transform/resource/after-ecj/SuperBuilderWithGenericsAndToBuilder.java b/test/transform/resource/after-ecj/SuperBuilderWithGenericsAndToBuilder.java index 8b26e439..4e55ae38 100644 --- a/test/transform/resource/after-ecj/SuperBuilderWithGenericsAndToBuilder.java +++ b/test/transform/resource/after-ecj/SuperBuilderWithGenericsAndToBuilder.java @@ -34,7 +34,9 @@ public class SuperBuilderWithGenericsAndToBuilder { } public @java.lang.SuppressWarnings("all") B items(final java.util.Map items) { if ((items == null)) - throw new java.lang.NullPointerException("items cannot be null"); + { + throw new java.lang.NullPointerException("items cannot be null"); + } if ((this.items$key == null)) { this.items$key = new java.util.ArrayList(); diff --git a/test/transform/resource/after-ecj/SuperBuilderWithPrefixes.java b/test/transform/resource/after-ecj/SuperBuilderWithPrefixes.java index e3b5baeb..1f972899 100644 --- a/test/transform/resource/after-ecj/SuperBuilderWithPrefixes.java +++ b/test/transform/resource/after-ecj/SuperBuilderWithPrefixes.java @@ -24,7 +24,9 @@ } public @java.lang.SuppressWarnings("all") B items(final java.util.Collection items) { if ((items == null)) - throw new java.lang.NullPointerException("items cannot be null"); + { + throw new java.lang.NullPointerException("items cannot be null"); + } if ((this.items == null)) this.items = new java.util.ArrayList(); this.items.addAll(items); diff --git a/test/transform/resource/before/BuilderSingularMapsWithSetterPrefix.java b/test/transform/resource/before/BuilderSingularMapsWithSetterPrefix.java index 89beb401..87ad7b9f 100644 --- a/test/transform/resource/before/BuilderSingularMapsWithSetterPrefix.java +++ b/test/transform/resource/before/BuilderSingularMapsWithSetterPrefix.java @@ -1,7 +1,6 @@ //FORMAT: javaLangAsFQN = skip //FORMAT: generated = skip //FORMAT: finalParams = skip -//CONF: lombok.singular.nullCollections = ignore import java.util.Map; import java.util.SortedMap; @@ -11,6 +10,6 @@ import lombok.Singular; class BuilderSingularMapsWithSetterPrefix { @Singular private Map women; @Singular private SortedMap men; - @SuppressWarnings("all") @Singular("rawMap") private Map rawMap; + @SuppressWarnings("all") @Singular(value = "rawMap", ignoreNullCollections = true) private Map rawMap; @Singular("stringMap") private Map stringMap; } diff --git a/test/transform/resource/before/BuilderSingularNullBehavior1.java b/test/transform/resource/before/BuilderSingularNullBehavior1.java index 019b6473..bcf473a4 100644 --- a/test/transform/resource/before/BuilderSingularNullBehavior1.java +++ b/test/transform/resource/before/BuilderSingularNullBehavior1.java @@ -1,13 +1,12 @@ +//CONF: lombok.addNullAnnotations = checkerframework +//CONF: lombok.nonNull.exceptionType = assertion import java.util.List; import java.util.Collection; import lombok.Singular; -import lombok.Singular.NullCollectionBehavior; @lombok.Builder class BuilderSingularNullBehavior1 { @Singular private List names; - @Singular(nullBehavior = Singular.NullCollectionBehavior.JDK) private List locations; - @Singular(nullBehavior = NullCollectionBehavior.GUAVA) private List whatevers; - @Singular(nullBehavior = lombok.Singular.NullCollectionBehavior.IGNORE) private List doohickeys; + @Singular(ignoreNullCollections = true) private List locations; } diff --git a/test/transform/resource/before/BuilderSingularNullBehavior2.java b/test/transform/resource/before/BuilderSingularNullBehavior2.java index 720cf5a8..7d1d0e57 100644 --- a/test/transform/resource/before/BuilderSingularNullBehavior2.java +++ b/test/transform/resource/before/BuilderSingularNullBehavior2.java @@ -1,11 +1,10 @@ -//CONF: lombok.addNullAnnotations = checkerframework +//CONF: lombok.addNullAnnotations = spring +//CONF: lombok.nonNull.exceptionType = JDK import java.util.List; import lombok.Singular; -import lombok.Singular.NullCollectionBehavior; @lombok.Builder class BuilderSingularNullBehavior2 { - @Singular(nullBehavior = Singular.NullCollectionBehavior.JDK) private List locations; - @Singular(nullBehavior = lombok.Singular.NullCollectionBehavior.IGNORE) private List doohickeys; + @Singular private List locations; } diff --git a/website/templates/features/Builder.html b/website/templates/features/Builder.html index 9e5b34c8..23977837 100644 --- a/website/templates/features/Builder.html +++ b/website/templates/features/Builder.html @@ -46,7 +46,7 @@ Each listed generated element will be silently skipped if that element already exists (disregarding parameter counts and looking only at names). This includes the builder itself: If that class already exists, lombok will simply start injecting fields and methods inside this already existing class, unless of course the fields / methods to be injected already exist. You may not put any other method (or constructor) generating lombok annotation on a builder class though; for example, you can not put @EqualsAndHashCode on the builder class.

    - @Builder can generate so-called 'singular' methods for collection parameters/fields. These take 1 element instead of an entire list, and add the element to the list. For example: Person.builder().job("Mythbusters").job("Unchained Reaction").build(); would result in the List<String> jobs field to have 2 strings in it. To get this behaviour, the field/parameter needs to be annotated with @Singular. The feature has its own documentation. + @Builder can generate so-called 'singular' methods for collection parameters/fields. These take 1 element instead of an entire list, and add the element to the list. For example: Person.builder().job("Mythbusters").job("Unchained Reaction").build(); would result in the List<String> jobs field to have 2 strings in it. To get this behavior, the field/parameter needs to be annotated with @Singular. The feature has its own documentation.

    Now that the "method" mode is clear, putting a @Builder annotation on a constructor functions similarly; effectively, constructors are just static methods that have a special syntax to invoke them: Their 'return type' is the class they construct, and their type parameters are the same as the type parameters of the class itself.

    @@ -133,11 +133,11 @@ If your identifiers are written in common english, lombok assumes that the name of any collection with @Singular on it is an english plural and will attempt to automatically singularize that name. If this is possible, the add-one method will use this name. For example, if your collection is called statuses, then the add-one method will automatically be called status. You can also specify the singular form of your identifier explictly by passing the singular form as argument to the annotation like so: @Singular("axis") List<Line> axes;.
    If lombok cannot singularize your identifier, or it is ambiguous, lombok will generate an error and force you to explicitly specify the singular name.

    - The snippet below does not show what lombok generates for a @Singular field/parameter because it is rather complicated. You can view a snippet here. + The snippet below does not show what lombok generates for a @Singular field/parameter because it is rather complicated. You can view a snippet here.

    If also using setterPrefix = "with", the generated names are, for example, withName (add 1 name), withNames (add many names), and clearNames (reset all names).

    - Ordinarily, the generated 'plural form' method (which takes in a collection, and adds each element in this collection) will check if a null is passed and throws a NullPointerException with an appropriate message. However, you can configure alternative behaviour. For example, for deserialization classes it can be useful to just do nothing (as if an empty collection was passed) instead: @Singular(nullBehavior = NullCollectionBehavior.IGNORE). If you want to change the kind of nullcheck lombok generates (for example, if you prefer the non-recommended IllegalArgumentException instead, we suggest you configure this in one central place by making a lombok.config entry instead; the intended use for specifying the behavior on the @Singular annotation directly is to explicitly request the IGNORE behaviour. + Ordinarily, the generated 'plural form' method (which takes in a collection, and adds each element in this collection) will check if a null is passed the same way @NonNull does (by default, throws a NullPointerException with an appropriate message). However, you can also tell lombok to ignore such collection (so, add nothing, return immediately): @Singular(ignoreNullCollections = true.

    @@ -181,10 +181,6 @@ public class JacksonExample { lombok.singular.auto = [true | false] (default: true)
    If true (which is the default), lombok automatically tries to singularize your identifier name by assuming that it is a common english plural. If false, you must always explicitly specify the singular name, and lombok will generate an error if you don't (useful if you write your code in a language other than english). -
    - lombok.singular.nullCollections = [NullPointerException | IllegalArgumentException | Guava | JDK | ignore] (default: NullPointerException) -
    - What should lombok do when a generated 'plural form' (for singular properties) method is called with a null argument? Normally, lombok does an explicit null check with an appropriate message, but you can use this configuration to pick another flavour of nullcheck. The ignore option makes lombok treat null as an empty collection: Do nothing. An appropriate nullity annotation will be placed on the generated plural form method's parameter if you configured the flavour of nullity annotations you want via lombok.config key lombok.addNullAnnotations.
    @@ -196,7 +192,7 @@ public class JacksonExample {

    The sorted collections (java.util: SortedSet, NavigableSet, SortedMap, NavigableMap and guava: ImmutableSortedSet, ImmutableSortedMap) require that the type argument of the collection has natural order (implements java.util.Comparable). There is no way to pass an explicit Comparator to use in the builder.

    - An ArrayList is used to store added elements as call methods of a @Singular marked field, if the target collection is from the java.util package, even if the collection is a set or map. Because lombok ensures that generated collections are compacted, a new backing instance of a set or map must be constructed anyway, and storing the data as an ArrayList during the build process is more efficient that storing it as a map or set. This behaviour is not externally visible, an implementation detail of the current implementation of the java.util recipes for @Singular @Builder. + An ArrayList is used to store added elements as call methods of a @Singular marked field, if the target collection is from the java.util package, even if the collection is a set or map. Because lombok ensures that generated collections are compacted, a new backing instance of a set or map must be constructed anyway, and storing the data as an ArrayList during the build process is more efficient that storing it as a map or set. This behavior is not externally visible, an implementation detail of the current implementation of the java.util recipes for @Singular @Builder.

    With toBuilder = true applied to methods, any type parameter of the annotated method itself must also show up in the return type.

    @@ -216,9 +212,9 @@ public class JacksonExample { Due to a peculiar way javac processes static imports, trying to do a non-star static import of the static builder() method won't work. Either use a star static import: `import static TypeThatHasABuilder.*;` or don't statically import the builder method.

    If setting the access level to PROTECTED, all methods generated inside the builder class are actually generated as public; the meaning of the - protected keyword is different inside the inner class, and the precise behaviour that PROTECTED would indicate (access by any source in the same package is allowed, as well as any subclasses from the outer class, marked with @Builder is not possible, and marking the inner members public is as close as we can get. + protected keyword is different inside the inner class, and the precise behavior that PROTECTED would indicate (access by any source in the same package is allowed, as well as any subclasses from the outer class, marked with @Builder is not possible, and marking the inner members public is as close as we can get.

    - If you have configured a nullity annotation flavour via lombok.config key lombok.addNullAnnotations, any plural-form generated builder methods for @Singular marked properties (these plural form methods take a collection of some sort and add all elements) get a nullity annotation on the parameter. You get a non-null one normally, but if you have configured the behaviour on null being passed in as collection to IGNORE, a nullable annotation is generated instead. + If you have configured a nullity annotation flavour via lombok.config key lombok.addNullAnnotations, any plural-form generated builder methods for @Singular marked properties (these plural form methods take a collection of some sort and add all elements) get a nullity annotation on the parameter. You get a non-null one normally, but if you have configured the behavior on null being passed in as collection to IGNORE, a nullable annotation is generated instead.

    -- cgit