From 5f198d71c684c6a2f1eec9ae6026cca5f4fd7c30 Mon Sep 17 00:00:00 2001 From: Caleb Brinkman Date: Wed, 10 Jul 2019 15:03:09 -0500 Subject: Add setterPrefix to Builder annotation --- src/core/lombok/Builder.java | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src') diff --git a/src/core/lombok/Builder.java b/src/core/lombok/Builder.java index dfa5ecb5..d7fe42a1 100644 --- a/src/core/lombok/Builder.java +++ b/src/core/lombok/Builder.java @@ -153,6 +153,16 @@ public @interface Builder { * @return The builder class will be generated with this access modifier. */ AccessLevel access() default lombok.AccessLevel.PUBLIC; + + /** + * Prefix to prepend to set methods in the generated builder class. By default, generated methods to not include a + * prefix. If this value populated, the first letter of the generated method name will be capitalized. + * + * For example, a method normally generated as {@code someField(String someField)} would instead be generated as {@code withSomeField(String someField)} + * + * @return The prefix to prepend to generated method names. + */ + String setterPrefix() default ""; /** * Put on a field (in case of {@code @Builder} on a type) or a parameter (for {@code @Builder} on a constructor or static method) to -- cgit From 88bf742e3e107cc0bbfc3a72c2f456d34ef3079c Mon Sep 17 00:00:00 2001 From: Caleb Brinkman Date: Wed, 10 Jul 2019 17:27:01 -0500 Subject: Implement prefixed setters Related to #1805, this change adds an optional `setterPrefix` parameter to the `Builder` annotation; if this parameter is unspecified or blank the behavior of the `Builder` annotation is unchanged, but if it is present the value specified will be prefixed to the generated methods. For example, using: ``` @Builder(setterPrefix = "include") class Foo { private int someValue; } ``` will result in a generated `Builder` class containing an `includeSomeValue(int someValue)` method instead of the default `someValue(int someValue)`. --- .../lombok/eclipse/handlers/HandleBuilder.java | 44 +++++++++++++++++- src/core/lombok/javac/handlers/HandleBuilder.java | 54 ++++++++++++++++++---- .../resource/after-ecj/BuilderWithPrefix.java | 2 +- 3 files changed, 89 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/core/lombok/eclipse/handlers/HandleBuilder.java b/src/core/lombok/eclipse/handlers/HandleBuilder.java index aa9d2147..aa43e96e 100755 --- a/src/core/lombok/eclipse/handlers/HandleBuilder.java +++ b/src/core/lombok/eclipse/handlers/HandleBuilder.java @@ -31,6 +31,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; +import com.sun.tools.javac.util.Name; import org.eclipse.jdt.internal.compiler.ast.ASTNode; import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration; import org.eclipse.jdt.internal.compiler.ast.AbstractVariableDeclaration; @@ -482,7 +483,7 @@ public class HandleBuilder extends EclipseAnnotationHandler { } for (BuilderFieldData bfd : builderFields) { - makeSetterMethodsForBuilder(builderType, bfd, annotationNode, fluent, chain, accessForInners, bfd.originalFieldNode); + makePrefixedSetterMethodsForBuilder(builderType, bfd, annotationNode, fluent, chain, accessForInners, bfd.originalFieldNode, builderInstance.setterPrefix()); } { @@ -840,7 +841,46 @@ public class HandleBuilder extends EclipseAnnotationHandler { sourceNode, methodAnnsList, annotations != null ? Arrays.asList(copyAnnotations(sourceNode.get(), annotations)) : Collections.emptyList()); injectMethod(builderType, setter); } - + + public void makePrefixedSetterMethodsForBuilder(EclipseNode builderType, BuilderFieldData bfd, EclipseNode sourceNode, boolean fluent, boolean chain, AccessLevel access, EclipseNode originalFieldNode, String prefix) { + boolean deprecate = isFieldDeprecated(bfd.originalFieldNode); + if (bfd.singularData == null || bfd.singularData.getSingularizer() == null) { + makePrefixedSetterMethodForBuilder(builderType, deprecate, bfd.createdFields.get(0), bfd.nameOfSetFlag, sourceNode, fluent, chain, bfd.annotations, access, originalFieldNode, prefix); + } else { + bfd.singularData.getSingularizer().generateMethods(bfd.singularData, deprecate, builderType, fluent, chain, access); + } + } + + private void makePrefixedSetterMethodForBuilder(EclipseNode builderType, boolean deprecate, EclipseNode fieldNode, char[] nameOfSetFlag, EclipseNode sourceNode, boolean fluent, boolean chain, Annotation[] annotations, AccessLevel access, EclipseNode originalFieldNode, String prefix) { + TypeDeclaration td = (TypeDeclaration) builderType.get(); + AbstractMethodDeclaration[] existing = td.methods; + if (existing == null) existing = EMPTY; + int len = existing.length; + FieldDeclaration fd = (FieldDeclaration) fieldNode.get(); + char[] name = fd.name; + + for (int i = 0; i < len; i++) { + if (!(existing[i] instanceof MethodDeclaration)) continue; + char[] existingName = existing[i].selector; + if (Arrays.equals(name, existingName) && !isTolerate(fieldNode, existing[i])) return; + } + + String setterPrefix = prefix.isEmpty() ? "set" : prefix; + String setterName; + if(fluent) { + setterName = prefix.isEmpty() ? fieldNode.getName() : HandlerUtil.buildAccessorName(setterPrefix, fieldNode.getName()); + } else { + setterName = HandlerUtil.buildAccessorName(setterPrefix, fieldNode.getName()); + } + + List methodAnnsList = Collections.emptyList(); + Annotation[] methodAnns = EclipseHandlerUtil.findCopyableToSetterAnnotations(originalFieldNode); + if (methodAnns != null && methodAnns.length > 0) methodAnnsList = Arrays.asList(methodAnns); + MethodDeclaration setter = HandleSetter.createSetter(td, deprecate, fieldNode, setterName, nameOfSetFlag, chain, toEclipseModifier(access), + sourceNode, methodAnnsList, annotations != null ? Arrays.asList(copyAnnotations(sourceNode.get(), annotations)) : Collections.emptyList()); + injectMethod(builderType, setter); + } + public EclipseNode makeBuilderClass(boolean isStatic, EclipseNode tdParent, String builderClassName, TypeParameter[] typeParams, ASTNode source, AccessLevel access) { TypeDeclaration parent = (TypeDeclaration) tdParent.get(); TypeDeclaration builder = new TypeDeclaration(parent.compilationResult); diff --git a/src/core/lombok/javac/handlers/HandleBuilder.java b/src/core/lombok/javac/handlers/HandleBuilder.java index b339c2ca..ab63aa5a 100644 --- a/src/core/lombok/javac/handlers/HandleBuilder.java +++ b/src/core/lombok/javac/handlers/HandleBuilder.java @@ -430,7 +430,7 @@ public class HandleBuilder extends JavacAnnotationHandler { } for (BuilderFieldData bfd : builderFields) { - makeSetterMethodsForBuilder(builderType, bfd, annotationNode, fluent, chain, accessForInners); + makePrefixedSetterMethodsForBuilder(builderType, bfd, annotationNode, fluent, chain, accessForInners, builderInstance.setterPrefix()); } { @@ -745,29 +745,67 @@ public class HandleBuilder extends JavacAnnotationHandler { fieldNode.singularData.getSingularizer().generateMethods(fieldNode.singularData, deprecate, builderType, source.get(), fluent, chain, access); } } - + private void makeSimpleSetterMethodForBuilder(JavacNode builderType, boolean deprecate, JavacNode fieldNode, Name nameOfSetFlag, JavacNode source, boolean fluent, boolean chain, List annosOnParam, JavacNode originalFieldNode, AccessLevel access) { Name fieldName = ((JCVariableDecl) fieldNode.get()).name; - + for (JavacNode child : builderType.down()) { if (child.getKind() != Kind.METHOD) continue; JCMethodDecl methodDecl = (JCMethodDecl) child.get(); Name existingName = methodDecl.name; if (existingName.equals(fieldName) && !isTolerate(fieldNode, methodDecl)) return; } - + String setterName = fluent ? fieldNode.getName() : HandlerUtil.buildAccessorName("set", fieldNode.getName()); - + JavacTreeMaker maker = fieldNode.getTreeMaker(); - + List methodAnns = JavacHandlerUtil.findCopyableToSetterAnnotations(originalFieldNode); JCMethodDecl newMethod = HandleSetter.createSetter(toJavacModifier(access), deprecate, fieldNode, maker, setterName, nameOfSetFlag, chain, source, methodAnns, annosOnParam); recursiveSetGeneratedBy(newMethod, source.get(), builderType.getContext()); copyJavadoc(originalFieldNode, newMethod, CopyJavadoc.SETTER); - + injectMethod(builderType, newMethod); } - + + public void makePrefixedSetterMethodsForBuilder(JavacNode builderType, BuilderFieldData fieldNode, JavacNode source, boolean fluent, boolean chain, AccessLevel access, String prefix) { + boolean deprecate = isFieldDeprecated(fieldNode.originalFieldNode); + if (fieldNode.singularData == null || fieldNode.singularData.getSingularizer() == null) { + makePrefixedSetterMethodForBuilder(builderType, deprecate, fieldNode.createdFields.get(0), fieldNode.nameOfSetFlag, source, fluent, chain, fieldNode.annotations, fieldNode.originalFieldNode, access, prefix); + } else { + // TODO prefixed version + fieldNode.singularData.getSingularizer().generateMethods(fieldNode.singularData, deprecate, builderType, source.get(), fluent, chain, access); + } + } + + private void makePrefixedSetterMethodForBuilder(JavacNode builderType, boolean deprecate, JavacNode fieldNode, Name nameOfSetFlag, JavacNode source, boolean fluent, boolean chain, List annosOnParam, JavacNode originalFieldNode, AccessLevel access, String prefix) { + Name fieldName = ((JCVariableDecl) fieldNode.get()).name; + + for (JavacNode child : builderType.down()) { + if (child.getKind() != Kind.METHOD) continue; + JCMethodDecl methodDecl = (JCMethodDecl) child.get(); + Name existingName = methodDecl.name; + if (existingName.equals(fieldName) && !isTolerate(fieldNode, methodDecl)) return; + } + + String setterPrefix = prefix.isEmpty() ? "set" : prefix; + String setterName; + if(fluent) { + setterName = prefix.isEmpty() ? fieldNode.getName() : HandlerUtil.buildAccessorName(setterPrefix, fieldNode.getName()); + } else { + setterName = HandlerUtil.buildAccessorName(setterPrefix, fieldNode.getName()); + } + + JavacTreeMaker maker = fieldNode.getTreeMaker(); + + List methodAnns = JavacHandlerUtil.findCopyableToSetterAnnotations(originalFieldNode); + JCMethodDecl newMethod = HandleSetter.createSetter(toJavacModifier(access), deprecate, fieldNode, maker, setterName, nameOfSetFlag, chain, source, methodAnns, annosOnParam); + recursiveSetGeneratedBy(newMethod, source.get(), builderType.getContext()); + copyJavadoc(originalFieldNode, newMethod, CopyJavadoc.SETTER); + + injectMethod(builderType, newMethod); + } + public JavacNode makeBuilderClass(boolean isStatic, JavacNode source, JavacNode tdParent, String builderClassName, List typeParams, JCAnnotation ast, AccessLevel access) { JavacTreeMaker maker = tdParent.getTreeMaker(); int modifiers = toJavacModifier(access); diff --git a/test/transform/resource/after-ecj/BuilderWithPrefix.java b/test/transform/resource/after-ecj/BuilderWithPrefix.java index 21a60d0d..98c42fe9 100644 --- a/test/transform/resource/after-ecj/BuilderWithPrefix.java +++ b/test/transform/resource/after-ecj/BuilderWithPrefix.java @@ -13,7 +13,7 @@ import java.util.List; return new BuilderWithPrefix(unprefixed); } public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { - return (((("BuilderWithPrefix.BuilderWithPrefixBuilder(unprefixed=" + this.unprefixed) + ")"); + return (("BuilderWithPrefix.BuilderWithPrefixBuilder(unprefixed=" + this.unprefixed) + ")"); } } private int unprefixed; -- cgit From 2baefe08cedebc9ef8c468b7de353e66b23eded1 Mon Sep 17 00:00:00 2001 From: Caleb Brinkman Date: Wed, 11 Sep 2019 09:20:39 -0500 Subject: Explicitly recommend against prefixes --- src/core/lombok/Builder.java | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src') diff --git a/src/core/lombok/Builder.java b/src/core/lombok/Builder.java index d7fe42a1..fcbe1a09 100644 --- a/src/core/lombok/Builder.java +++ b/src/core/lombok/Builder.java @@ -160,6 +160,9 @@ public @interface Builder { * * For example, a method normally generated as {@code someField(String someField)} would instead be generated as {@code withSomeField(String someField)} * + * Note that using "with" to prefix builder setter methods is strongly discouraged as as "with" normally + * suggests immutable data structures, and builders by definition are mutable objects. + * * @return The prefix to prepend to generated method names. */ String setterPrefix() default ""; -- cgit From cc070254a68331c2593c37359921854c74692661 Mon Sep 17 00:00:00 2001 From: Caleb Brinkman Date: Wed, 11 Sep 2019 11:16:04 -0500 Subject: Remove extraneous import --- src/core/lombok/eclipse/handlers/HandleBuilder.java | 1 - 1 file changed, 1 deletion(-) (limited to 'src') diff --git a/src/core/lombok/eclipse/handlers/HandleBuilder.java b/src/core/lombok/eclipse/handlers/HandleBuilder.java index 375bd164..05686429 100755 --- a/src/core/lombok/eclipse/handlers/HandleBuilder.java +++ b/src/core/lombok/eclipse/handlers/HandleBuilder.java @@ -31,7 +31,6 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; -import com.sun.tools.javac.util.Name; import org.eclipse.jdt.internal.compiler.ast.ASTNode; import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration; import org.eclipse.jdt.internal.compiler.ast.AbstractVariableDeclaration; -- cgit From 5b16b48bbffdd579b26e2a7dc18684efdc32e219 Mon Sep 17 00:00:00 2001 From: Caleb Brinkman Date: Thu, 12 Sep 2019 11:58:10 -0500 Subject: Fix class names in after-ecj --- .../eclipse/handlers/EclipseSingularsRecipes.java | 21 +- .../lombok/eclipse/handlers/HandleBuilder.java | 217 +++++++++++---------- .../EclipseJavaUtilListSetSingularizer.java | 6 +- ...lderSingularAnnotatedTypesWithSetterPrefix.java | 30 +-- ...lderSingularGuavaListsSetsWithSetterPrefix.java | 48 ++--- .../BuilderSingularGuavaMapsWithSetterPrefix.java | 36 ++-- .../BuilderSingularListsWithSetterPrefix.java | 36 ++-- .../BuilderSingularMapsWithSetterPrefix.java | 42 ++-- .../BuilderSingularNoAutoWithSetterPrefix.java | 36 ++-- ...derSingularRedirectToGuavaWithSetterPrefix.java | 36 ++-- .../BuilderSingularSetsWithSetterPrefix.java | 42 ++-- ...rSingularToBuilderWithNullWithSetterPrefix.java | 30 +-- ...WildcardListsWithToBuilderWithSetterPrefix.java | 34 ++-- ...uilderSingularWithPrefixesWithSetterPrefix.java | 24 +-- .../BuilderTypeAnnosWithSetterPrefix.java | 20 +- .../BuilderValueDataWithSetterPrefix.java | 50 ++--- .../BuilderWithAccessorsWithSetterPrefix.java | 26 +-- .../BuilderWithBadNamesWithSetterPrefix.java | 22 +-- .../BuilderWithDeprecatedWithSetterPrefix.java | 34 ++-- ...erWithExistingBuilderClassWithSetterPrefix.java | 24 +-- ...BuilderWithNoBuilderMethodWithSetterPrefix.java | 20 +- .../BuilderWithNonNullWithSetterPrefix.java | 20 +- ...ilderWithRecursiveGenericsWithSetterPrefix.java | 12 +- .../BuilderWithToBuilderWithSetterPrefix.java | 36 ++-- .../BuilderWithTolerateWithSetterPrefix.java | 24 +-- .../before/BuilderSimpleWithSetterPrefix.java | 2 +- 26 files changed, 474 insertions(+), 454 deletions(-) (limited to 'src') diff --git a/src/core/lombok/eclipse/handlers/EclipseSingularsRecipes.java b/src/core/lombok/eclipse/handlers/EclipseSingularsRecipes.java index da0bf471..0f463ae2 100755 --- a/src/core/lombok/eclipse/handlers/EclipseSingularsRecipes.java +++ b/src/core/lombok/eclipse/handlers/EclipseSingularsRecipes.java @@ -120,6 +120,7 @@ public class EclipseSingularsRecipes { private final EclipseNode annotation; private final char[] singularName; private final char[] pluralName; + private final char[] setterPrefix; private final List typeArgs; private final String targetFqn; private final EclipseSingularizer singularizer; @@ -133,8 +134,20 @@ public class EclipseSingularsRecipes { this.targetFqn = targetFqn; this.singularizer = singularizer; this.source = source; + this.setterPrefix = new char[0]; } - + + public SingularData(EclipseNode annotation, char[] singularName, char[] pluralName, List typeArgs, String targetFqn, EclipseSingularizer singularizer, ASTNode source, char[] setterPrefix) { + this.annotation = annotation; + this.singularName = singularName; + this.pluralName = pluralName; + this.typeArgs = typeArgs; + this.targetFqn = targetFqn; + this.singularizer = singularizer; + this.source = source; + this.setterPrefix = setterPrefix; + } + public void setGeneratedByRecursive(ASTNode target) { SetGeneratedByVisitor visitor = new SetGeneratedByVisitor(source); @@ -162,7 +175,11 @@ public class EclipseSingularsRecipes { public char[] getPluralName() { return pluralName; } - + + public char[] getSetterPrefix() { + return setterPrefix; + } + public List getTypeArgs() { return typeArgs; } diff --git a/src/core/lombok/eclipse/handlers/HandleBuilder.java b/src/core/lombok/eclipse/handlers/HandleBuilder.java index 05686429..ec2be523 100755 --- a/src/core/lombok/eclipse/handlers/HandleBuilder.java +++ b/src/core/lombok/eclipse/handlers/HandleBuilder.java @@ -1,16 +1,16 @@ /* * Copyright (C) 2013-2019 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 * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -101,17 +101,17 @@ import lombok.experimental.NonFinal; @HandlerPriority(-1024) //-2^10; to ensure we've picked up @FieldDefault's changes (-2048) but @Value hasn't removed itself yet (-512), so that we can error on presence of it on the builder classes. public class HandleBuilder extends EclipseAnnotationHandler { private HandleConstructor handleConstructor = new HandleConstructor(); - + private static final char[] CLEAN_FIELD_NAME = "$lombokUnclean".toCharArray(); private static final char[] CLEAN_METHOD_NAME = "$lombokClean".toCharArray(); - + private static final boolean toBoolean(Object expr, boolean defaultValue) { if (expr == null) return defaultValue; if (expr instanceof FalseLiteral) return false; if (expr instanceof TrueLiteral) return true; return ((Boolean) expr).booleanValue(); } - + static class BuilderFieldData { Annotation[] annotations; TypeReference type; @@ -124,10 +124,10 @@ public class HandleBuilder extends EclipseAnnotationHandler { ObtainVia obtainVia; EclipseNode obtainViaNode; EclipseNode originalFieldNode; - + List createdFields = new ArrayList(); } - + private static boolean equals(String a, char[] b) { if (a.length() != b.length) return false; for (int i = 0; i < b.length; i++) { @@ -135,7 +135,7 @@ public class HandleBuilder extends EclipseAnnotationHandler { } return true; } - + private static boolean equals(String a, char[][] b) { if (a == null || a.isEmpty()) return b.length == 0; String[] aParts = a.split("\\."); @@ -145,24 +145,24 @@ public class HandleBuilder extends EclipseAnnotationHandler { } return true; } - + private static final char[] DEFAULT_PREFIX = {'$', 'd', 'e', 'f', 'a', 'u', 'l', 't', '$'}; private static final char[] SET_PREFIX = {'$', 's', 'e', 't'}; private static final char[] VALUE_PREFIX = {'$', 'v', 'a', 'l', 'u', 'e'}; - + private static final char[] prefixWith(char[] prefix, char[] name) { char[] out = new char[prefix.length + name.length]; System.arraycopy(prefix, 0, out, 0, prefix.length); System.arraycopy(name, 0, out, prefix.length, name.length); return out; } - + @Override public void handle(AnnotationValues annotation, Annotation ast, EclipseNode annotationNode) { handleFlagUsage(annotationNode, ConfigurationKeys.BUILDER_FLAG_USAGE, "@Builder"); CheckerFrameworkVersion cfv = getCheckerFrameworkVersion(annotationNode); long p = (long) ast.sourceStart << 32 | ast.sourceEnd; - + Builder builderInstance = annotation.getInstance(); AccessLevel accessForOuters = builderInstance.access(); if (accessForOuters == null) accessForOuters = AccessLevel.PUBLIC; @@ -171,22 +171,22 @@ public class HandleBuilder extends EclipseAnnotationHandler { accessForOuters = AccessLevel.PUBLIC; } AccessLevel accessForInners = accessForOuters == AccessLevel.PROTECTED ? AccessLevel.PUBLIC : accessForOuters; - + // These exist just to support the 'old' lombok.experimental.Builder, which had these properties. lombok.Builder no longer has them. boolean fluent = toBoolean(annotation.getActualExpression("fluent"), true); boolean chain = toBoolean(annotation.getActualExpression("chain"), true); - + String builderMethodName = builderInstance.builderMethodName(); String buildMethodName = builderInstance.buildMethodName(); String builderClassName = builderInstance.builderClassName(); String toBuilderMethodName = "toBuilder"; boolean toBuilder = builderInstance.toBuilder(); List typeArgsForToBuilder = null; - + if (builderMethodName == null) builderMethodName = "builder"; if (buildMethodName == null) buildMethodName = "build"; if (builderClassName == null) builderClassName = ""; - + boolean generateBuilderMethod; if (builderMethodName.isEmpty()) { generateBuilderMethod = false; @@ -195,74 +195,74 @@ public class HandleBuilder extends EclipseAnnotationHandler { } else { generateBuilderMethod = true; } - + if (!checkName("buildMethodName", buildMethodName, annotationNode)) return; if (!builderClassName.isEmpty()) { if (!checkName("builderClassName", builderClassName, annotationNode)) return; } - + EclipseNode parent = annotationNode.up(); - + List builderFields = new ArrayList(); TypeReference returnType; TypeParameter[] typeParams; TypeReference[] thrownExceptions; char[] nameOfStaticBuilderMethod; EclipseNode tdParent; - + EclipseNode fillParametersFrom = parent.get() instanceof AbstractMethodDeclaration ? parent : null; boolean addCleaning = false; boolean isStatic = true; - + List nonFinalNonDefaultedFields = null; - + if (builderClassName.isEmpty()) builderClassName = annotationNode.getAst().readConfiguration(ConfigurationKeys.BUILDER_CLASS_NAME); if (builderClassName == null || builderClassName.isEmpty()) builderClassName = "*Builder"; boolean replaceNameInBuilderClassName = builderClassName.contains("*"); - + if (parent.get() instanceof TypeDeclaration) { tdParent = parent; TypeDeclaration td = (TypeDeclaration) tdParent.get(); - + List allFields = new ArrayList(); boolean valuePresent = (hasAnnotation(lombok.Value.class, parent) || hasAnnotation("lombok.experimental.Value", parent)); for (EclipseNode fieldNode : HandleConstructor.findAllFields(tdParent, true)) { FieldDeclaration fd = (FieldDeclaration) fieldNode.get(); EclipseNode isDefault = findAnnotation(Builder.Default.class, fieldNode); boolean isFinal = ((fd.modifiers & ClassFileConstants.AccFinal) != 0) || (valuePresent && !hasAnnotation(NonFinal.class, fieldNode)); - + Annotation[] copyableAnnotations = findCopyableAnnotations(fieldNode); - + BuilderFieldData bfd = new BuilderFieldData(); bfd.rawName = fieldNode.getName().toCharArray(); bfd.name = removePrefixFromField(fieldNode); bfd.builderFieldName = bfd.name; bfd.annotations = copyAnnotations(fd, copyableAnnotations); bfd.type = fd.type; - bfd.singularData = getSingularData(fieldNode, ast); + bfd.singularData = getSingularData(fieldNode, ast, builderInstance.setterPrefix()); bfd.originalFieldNode = fieldNode; - + if (bfd.singularData != null && isDefault != null) { isDefault.addError("@Builder.Default and @Singular cannot be mixed."); isDefault = null; } - + if (fd.initialization == null && isDefault != null) { isDefault.addWarning("@Builder.Default requires an initializing expression (' = something;')."); isDefault = null; } - + if (fd.initialization != null && isDefault == null) { if (isFinal) continue; if (nonFinalNonDefaultedFields == null) nonFinalNonDefaultedFields = new ArrayList(); nonFinalNonDefaultedFields.add(fieldNode); } - + if (isDefault != null) { bfd.nameOfDefaultProvider = prefixWith(DEFAULT_PREFIX, bfd.name); bfd.nameOfSetFlag = prefixWith(bfd.name, SET_PREFIX); bfd.builderFieldName = prefixWith(bfd.name, VALUE_PREFIX); - + MethodDeclaration md = generateDefaultProvider(bfd.nameOfDefaultProvider, td.typeParameters, fieldNode, ast); if (md != null) injectMethod(tdParent, md); } @@ -270,10 +270,10 @@ public class HandleBuilder extends EclipseAnnotationHandler { builderFields.add(bfd); allFields.add(fieldNode); } - + handleConstructor.generateConstructor(tdParent, AccessLevel.PACKAGE, allFields, false, null, SkipIfConstructorExists.I_AM_BUILDER, Collections.emptyList(), annotationNode); - + returnType = namePlusTypeParamsToTypeReference(td.name, td.typeParameters, p); typeParams = td.typeParameters; thrownExceptions = null; @@ -286,7 +286,7 @@ public class HandleBuilder extends EclipseAnnotationHandler { annotationNode.addError("@Builder is not supported on constructors with constructor type parameters."); return; } - + tdParent = parent.up(); TypeDeclaration td = (TypeDeclaration) tdParent.get(); returnType = namePlusTypeParamsToTypeReference(td.name, td.typeParameters, p); @@ -299,7 +299,7 @@ public class HandleBuilder extends EclipseAnnotationHandler { MethodDeclaration md = (MethodDeclaration) parent.get(); tdParent = parent.up(); isStatic = md.isStatic(); - + if (toBuilder) { final String TO_BUILDER_NOT_SUPPORTED = "@Builder(toBuilder=true) is only supported if you return your own type."; char[] token; @@ -308,7 +308,7 @@ public class HandleBuilder extends EclipseAnnotationHandler { annotationNode.addError(TO_BUILDER_NOT_SUPPORTED); return; } - + if (md.returnType instanceof SingleTypeReference) { token = ((SingleTypeReference) md.returnType).token; } else if (md.returnType instanceof QualifiedTypeReference) { @@ -321,17 +321,17 @@ public class HandleBuilder extends EclipseAnnotationHandler { annotationNode.addError(TO_BUILDER_NOT_SUPPORTED); return; } - + if (pkg != null && !equals(parent.getPackageDeclaration(), pkg)) { annotationNode.addError(TO_BUILDER_NOT_SUPPORTED); return; } - + if (tdParent == null || !equals(tdParent.getName(), token)) { annotationNode.addError(TO_BUILDER_NOT_SUPPORTED); return; } - + TypeParameter[] tpOnType = ((TypeDeclaration) tdParent.get()).typeParameters; TypeParameter[] tpOnMethod = md.typeParameters; TypeReference[][] tpOnRet_ = null; @@ -341,7 +341,7 @@ public class HandleBuilder extends EclipseAnnotationHandler { } else if (md.returnType instanceof ParameterizedQualifiedTypeReference) { tpOnRet_ = ((ParameterizedQualifiedTypeReference) md.returnType).typeArguments; } - + if (tpOnRet_ != null) for (int i = 0; i < tpOnRet_.length - 1; i++) { if (tpOnRet_[i] != null && tpOnRet_[i].length > 0) { annotationNode.addError("@Builder(toBuilder=true) is not supported if returning a type with generics applied to an intermediate."); @@ -350,11 +350,11 @@ public class HandleBuilder extends EclipseAnnotationHandler { } TypeReference[] tpOnRet = tpOnRet_ == null ? null : tpOnRet_[tpOnRet_.length - 1]; typeArgsForToBuilder = new ArrayList(); - + // Every typearg on this method needs to be found in the return type, but the reverse is not true. // We also need to 'map' them. - - + + if (tpOnMethod != null) for (TypeParameter onMethod : tpOnMethod) { int pos = -1; if (tpOnRet != null) for (int i = 0; i < tpOnRet.length; i++) { @@ -366,11 +366,11 @@ public class HandleBuilder extends EclipseAnnotationHandler { annotationNode.addError("@Builder(toBuilder=true) requires that each type parameter on the static method is part of the typeargs of the return value. Type parameter " + new String(onMethod.name) + " is not part of the return type."); return; } - + typeArgsForToBuilder.add(tpOnType[pos].name); } } - + returnType = copyType(md.returnType, ast); typeParams = md.typeParameters; thrownExceptions = md.thrownExceptions; @@ -394,41 +394,41 @@ public class HandleBuilder extends EclipseAnnotationHandler { annotationNode.addError("Unexpected kind of return type on annotated method. Specify 'builderClassName' to solve this problem."); return; } - + if (Character.isLowerCase(token[0])) { char[] newToken = new char[token.length]; System.arraycopy(token, 1, newToken, 1, token.length - 1); newToken[0] = Character.toTitleCase(token[0]); token = newToken; } - + builderClassName = builderClassName.replace("*", new String(token)); } } else { annotationNode.addError("@Builder is only supported on types, constructors, and methods."); return; } - + if (fillParametersFrom != null) { for (EclipseNode param : fillParametersFrom.down()) { if (param.getKind() != Kind.ARGUMENT) continue; BuilderFieldData bfd = new BuilderFieldData(); Argument arg = (Argument) param.get(); - + Annotation[] copyableAnnotations = findCopyableAnnotations(param); - + bfd.rawName = arg.name; bfd.name = arg.name; bfd.builderFieldName = bfd.name; bfd.annotations = copyAnnotations(arg, copyableAnnotations); bfd.type = arg.type; - bfd.singularData = getSingularData(param, ast); + bfd.singularData = getSingularData(param, ast, builderInstance.setterPrefix()); bfd.originalFieldNode = param; addObtainVia(bfd, param); builderFields.add(bfd); } } - + EclipseNode builderType = findInnerClass(tdParent, builderClassName); if (builderType == null) { builderType = makeBuilderClass(isStatic, tdParent, builderClassName, typeParams, ast, accessForOuters); @@ -454,7 +454,7 @@ public class HandleBuilder extends EclipseAnnotationHandler { } } } - + for (BuilderFieldData bfd : builderFields) { if (bfd.singularData != null && bfd.singularData.getSingularizer() != null) { if (bfd.singularData.getSingularizer().requiresCleaning()) { @@ -473,7 +473,7 @@ public class HandleBuilder extends EclipseAnnotationHandler { } } } - + generateBuilderFields(builderType, builderFields, ast); if (addCleaning) { FieldDeclaration cleanDecl = new FieldDeclaration(CLEAN_FIELD_NAME, 0, -1); @@ -483,18 +483,18 @@ public class HandleBuilder extends EclipseAnnotationHandler { cleanDecl.traverse(new SetGeneratedByVisitor(ast), (MethodScope) null); injectFieldAndMarkGenerated(builderType, cleanDecl); } - + if (constructorExists(builderType) == MemberExistsResult.NOT_EXISTS) { ConstructorDeclaration cd = HandleConstructor.createConstructor( AccessLevel.PACKAGE, builderType, Collections.emptyList(), false, annotationNode, Collections.emptyList()); if (cd != null) injectMethod(builderType, cd); } - + for (BuilderFieldData bfd : builderFields) { makePrefixedSetterMethodsForBuilder(cfv, builderType, bfd, annotationNode, fluent, chain, accessForInners, bfd.originalFieldNode, builderInstance.setterPrefix()); } - + { MemberExistsResult methodExists = methodExists(buildMethodName, builderType, -1); if (methodExists == MemberExistsResult.EXISTS_BY_LOMBOK) methodExists = methodExists(buildMethodName, builderType, 0); @@ -503,7 +503,7 @@ public class HandleBuilder extends EclipseAnnotationHandler { if (md != null) injectMethod(builderType, md); } } - + if (methodExists("toString", builderType, 0) == MemberExistsResult.NOT_EXISTS) { List> fieldNodes = new ArrayList>(); for (BuilderFieldData bfd : builderFields) { @@ -514,18 +514,18 @@ public class HandleBuilder extends EclipseAnnotationHandler { MethodDeclaration md = HandleToString.createToString(builderType, fieldNodes, true, false, ast, FieldAccess.ALWAYS_FIELD); if (md != null) injectMethod(builderType, md); } - + if (addCleaning) { MethodDeclaration cleanMethod = generateCleanMethod(builderFields, builderType, ast); if (cleanMethod != null) injectMethod(builderType, cleanMethod); } - + if (generateBuilderMethod && methodExists(builderMethodName, tdParent, -1) != MemberExistsResult.NOT_EXISTS) generateBuilderMethod = false; if (generateBuilderMethod) { MethodDeclaration md = generateBuilderMethod(cfv, isStatic, builderMethodName, builderClassName, tdParent, typeParams, ast, accessForOuters); if (md != null) injectMethod(tdParent, md); } - + if (toBuilder) switch (methodExists(toBuilderMethodName, tdParent, 0)) { case EXISTS_BY_USER: annotationNode.addWarning("Not generating toBuilder() as it already exists."); @@ -540,22 +540,22 @@ public class HandleBuilder extends EclipseAnnotationHandler { } } MethodDeclaration md = generateToBuilderMethod(cfv, toBuilderMethodName, builderClassName, tdParent, tps, builderFields, fluent, ast, accessForOuters); - + if (md != null) injectMethod(tdParent, md); } - + if (nonFinalNonDefaultedFields != null && generateBuilderMethod) { for (EclipseNode fieldNode : nonFinalNonDefaultedFields) { fieldNode.addWarning("@Builder will ignore the initializing expression entirely. If you want the initializing expression to serve as default, add @Builder.Default. If it is not supposed to be settable during building, make the field final."); } } } - + private static final char[] BUILDER_TEMP_VAR = {'b', 'u', 'i', 'l', 'd', 'e', 'r'}; private MethodDeclaration generateToBuilderMethod(CheckerFrameworkVersion cfv, String methodName, String builderClassName, EclipseNode type, TypeParameter[] typeParams, List builderFields, boolean fluent, ASTNode source, AccessLevel access) { int pS = source.sourceStart, pE = source.sourceEnd; long p = (long) pS << 32 | pE; - + MethodDeclaration out = new MethodDeclaration(((CompilationUnitDeclaration) type.top().get()).compilationResult); out.selector = methodName.toCharArray(); out.modifiers = toEclipseModifier(access); @@ -563,14 +563,14 @@ public class HandleBuilder extends EclipseAnnotationHandler { out.returnType = namePlusTypeParamsToTypeReference(builderClassName.toCharArray(), typeParams, p); AllocationExpression invoke = new AllocationExpression(); invoke.type = namePlusTypeParamsToTypeReference(builderClassName.toCharArray(), typeParams, p); - + Expression receiver = invoke; List statements = null; for (BuilderFieldData bfd : builderFields) { char[] setterName = fluent ? bfd.name : HandlerUtil.buildAccessorName("set", new String(bfd.name)).toCharArray(); MessageSend ms = new MessageSend(); Expression[] tgt = new Expression[bfd.singularData == null ? 1 : 2]; - + if (bfd.obtainVia == null || !bfd.obtainVia.field().isEmpty()) { char[] fieldName = bfd.obtainVia == null ? bfd.rawName : bfd.obtainVia.field().toCharArray(); for (int i = 0; i < tgt.length; i++) { @@ -599,7 +599,7 @@ public class HandleBuilder extends EclipseAnnotationHandler { tgt[i] = obtainExpr; } } - + ms.selector = setterName; if (bfd.singularData == null) { ms.arguments = tgt; @@ -613,7 +613,7 @@ public class HandleBuilder extends EclipseAnnotationHandler { statements.add(new IfStatement(isNotNull, ms, pS, pE)); } } - + if (statements != null) { out.statements = new Statement[statements.size() + 2]; for (int i = 0; i < statements.size(); i++) out.statements[i + 1] = statements.get(i); @@ -627,7 +627,7 @@ public class HandleBuilder extends EclipseAnnotationHandler { } else { out.statements = new Statement[] {new ReturnStatement(receiver, pS, pE)}; } - + if (cfv.generateUnique()) { out.annotations = new Annotation[] {generateNamedAnnotation(source, CheckerFrameworkVersion.NAME__UNIQUE)}; } @@ -636,16 +636,16 @@ public class HandleBuilder extends EclipseAnnotationHandler { return out; } - + private MethodDeclaration generateCleanMethod(List builderFields, EclipseNode builderType, ASTNode source) { List statements = new ArrayList(); - + for (BuilderFieldData bfd : builderFields) { if (bfd.singularData != null && bfd.singularData.getSingularizer() != null) { bfd.singularData.getSingularizer().appendCleaningCode(bfd.singularData, builderType, statements); } } - + FieldReference thisUnclean = new FieldReference(CLEAN_FIELD_NAME, 0); thisUnclean.receiver = new ThisReference(0, 0); statements.add(new Assignment(thisUnclean, new FalseLiteral(0, 0), 0)); @@ -658,7 +658,7 @@ public class HandleBuilder extends EclipseAnnotationHandler { decl.traverse(new SetGeneratedByVisitor(source), (ClassScope) null); return decl; } - + static Argument[] generateBuildArgs(CheckerFrameworkVersion cfv, EclipseNode type, List builderFields, ASTNode source) { if (!cfv.generateCalledMethods()) return null; @@ -691,7 +691,7 @@ public class HandleBuilder extends EclipseAnnotationHandler { MethodDeclaration out = new MethodDeclaration(((CompilationUnitDeclaration) type.top().get()).compilationResult); out.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG; List statements = new ArrayList(); - + if (addCleaning) { FieldReference thisUnclean = new FieldReference(CLEAN_FIELD_NAME, 0); thisUnclean.receiver = new ThisReference(0, 0); @@ -700,13 +700,13 @@ public class HandleBuilder extends EclipseAnnotationHandler { invokeClean.selector = CLEAN_METHOD_NAME; statements.add(new IfStatement(notClean, invokeClean, 0, 0)); } - + for (BuilderFieldData bfd : builderFields) { if (bfd.singularData != null && bfd.singularData.getSingularizer() != null) { bfd.singularData.getSingularizer().appendBuildCode(bfd.singularData, type, statements, bfd.builderFieldName, "this"); } } - + List args = new ArrayList(); for (BuilderFieldData bfd : builderFields) { if (bfd.nameOfSetFlag != null) { @@ -716,7 +716,7 @@ public class HandleBuilder extends EclipseAnnotationHandler { inv.receiver = new SingleNameReference(((TypeDeclaration) tdParent.get()).name, 0L); inv.selector = bfd.nameOfDefaultProvider; inv.typeArguments = typeParameterNames(((TypeDeclaration) type.get()).typeParameters); - + args.add(new ConditionalExpression( new SingleNameReference(bfd.nameOfSetFlag, 0L), new SingleNameReference(bfd.builderFieldName, 0L), @@ -725,19 +725,19 @@ public class HandleBuilder extends EclipseAnnotationHandler { args.add(new SingleNameReference(bfd.builderFieldName, 0L)); } } - + if (addCleaning) { FieldReference thisUnclean = new FieldReference(CLEAN_FIELD_NAME, 0); thisUnclean.receiver = new ThisReference(0, 0); statements.add(new Assignment(thisUnclean, new TrueLiteral(0, 0), 0)); } - + out.modifiers = toEclipseModifier(access); out.selector = name.toCharArray(); out.thrownExceptions = copyTypes(thrownExceptions); out.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG; out.returnType = returnType; - + if (staticName == null) { AllocationExpression allocationStatement = new AllocationExpression(); allocationStatement.type = copyType(out.returnType); @@ -750,7 +750,7 @@ public class HandleBuilder extends EclipseAnnotationHandler { invoke.receiver = new SingleNameReference(type.up().getName().toCharArray(), 0); else invoke.receiver = new QualifiedThisReference(new SingleTypeReference(type.up().getName().toCharArray(), 0) , 0, 0); - + invoke.typeArguments = typeParameterNames(((TypeDeclaration) type.get()).typeParameters); invoke.arguments = args.isEmpty() ? null : args.toArray(new Expression[0]); if (returnType instanceof SingleTypeReference && Arrays.equals(TypeConstants.VOID, ((SingleTypeReference) returnType).token)) { @@ -767,20 +767,20 @@ public class HandleBuilder extends EclipseAnnotationHandler { out.traverse(new SetGeneratedByVisitor(source), (ClassScope) null); return out; } - + private TypeReference[] typeParameterNames(TypeParameter[] typeParameters) { if (typeParameters == null) return null; - + TypeReference[] trs = new TypeReference[typeParameters.length]; for (int i = 0; i < trs.length; i++) { trs[i] = new SingleTypeReference(typeParameters[i].name, 0); } return trs; } - + public static MethodDeclaration generateDefaultProvider(char[] methodName, TypeParameter[] typeParameters, EclipseNode fieldNode, ASTNode source) { int pS = source.sourceStart, pE = source.sourceEnd; - + MethodDeclaration out = new MethodDeclaration(((CompilationUnitDeclaration) fieldNode.top().get()).compilationResult); out.typeParameters = copyTypeParams(typeParameters, source); out.selector = methodName; @@ -790,15 +790,15 @@ public class HandleBuilder extends EclipseAnnotationHandler { out.returnType = copyType(fd.type, source); out.statements = new Statement[] {new ReturnStatement(fd.initialization, pS, pE)}; fd.initialization = null; - + out.traverse(new SetGeneratedByVisitor(source), ((TypeDeclaration) fieldNode.up().get()).scope); return out; } - + public MethodDeclaration generateBuilderMethod(CheckerFrameworkVersion cfv, boolean isStatic, String builderMethodName, String builderClassName, EclipseNode type, TypeParameter[] typeParams, ASTNode source, AccessLevel access) { int pS = source.sourceStart, pE = source.sourceEnd; long p = (long) pS << 32 | pE; - + MethodDeclaration out = new MethodDeclaration(((CompilationUnitDeclaration) type.top().get()).compilationResult); out.selector = builderMethodName.toCharArray(); out.modifiers = toEclipseModifier(access); @@ -821,13 +821,13 @@ public class HandleBuilder extends EclipseAnnotationHandler { out.traverse(new SetGeneratedByVisitor(source), ((TypeDeclaration) type.get()).scope); return out; } - + public void generateBuilderFields(EclipseNode builderType, List builderFields, ASTNode source) { List existing = new ArrayList(); for (EclipseNode child : builderType.down()) { if (child.getKind() == Kind.FIELD) existing.add(child); } - + for (BuilderFieldData bfd : builderFields) { if (bfd.singularData != null && bfd.singularData.getSingularizer() != null) { bfd.createdFields.addAll(bfd.singularData.getSingularizer().generateFields(bfd.singularData, builderType)); @@ -838,7 +838,7 @@ public class HandleBuilder extends EclipseAnnotationHandler { if (Arrays.equals(n, bfd.builderFieldName)) field = exists; if (bfd.nameOfSetFlag != null && Arrays.equals(n, bfd.nameOfSetFlag)) setFlag = exists; } - + if (field == null) { FieldDeclaration fd = new FieldDeclaration(bfd.builderFieldName, 0, 0); fd.bits |= Eclipse.ECLIPSE_DO_NOT_TOUCH_FLAG; @@ -859,9 +859,9 @@ public class HandleBuilder extends EclipseAnnotationHandler { } } } - + private static final AbstractMethodDeclaration[] EMPTY = {}; - + public void makeSetterMethodsForBuilder(CheckerFrameworkVersion cfv, EclipseNode builderType, BuilderFieldData bfd, EclipseNode sourceNode, boolean fluent, boolean chain, AccessLevel access, EclipseNode originalFieldNode) { boolean deprecate = isFieldDeprecated(bfd.originalFieldNode); if (bfd.singularData == null || bfd.singularData.getSingularizer() == null) { @@ -870,7 +870,7 @@ public class HandleBuilder extends EclipseAnnotationHandler { bfd.singularData.getSingularizer().generateMethods(cfv, bfd.singularData, deprecate, builderType, fluent, chain, access); } } - + private void makeSimpleSetterMethodForBuilder(CheckerFrameworkVersion cfv, EclipseNode builderType, boolean deprecate, EclipseNode fieldNode, char[] paramName, char[] nameOfSetFlag, EclipseNode sourceNode, boolean fluent, boolean chain, Annotation[] annotations, AccessLevel access, EclipseNode originalFieldNode) { TypeDeclaration td = (TypeDeclaration) builderType.get(); AbstractMethodDeclaration[] existing = td.methods; @@ -879,15 +879,15 @@ public class HandleBuilder extends EclipseAnnotationHandler { int len = existing.length; FieldDeclaration fd = (FieldDeclaration) fieldNode.get(); char[] name = fd.name; - + for (int i = 0; i < len; i++) { if (!(existing[i] instanceof MethodDeclaration)) continue; char[] existingName = existing[i].selector; if (Arrays.equals(name, existingName) && !isTolerate(fieldNode, existing[i])) return; } - + String setterName = fluent ? new String(paramName) : HandlerUtil.buildAccessorName("set", new String(paramName)); - + List methodAnnsList = Arrays.asList(EclipseHandlerUtil.findCopyableToSetterAnnotations(originalFieldNode)); Annotation[] methodAnns = EclipseHandlerUtil.findCopyableToSetterAnnotations(originalFieldNode); if (methodAnns != null && methodAnns.length > 0) methodAnnsList = Arrays.asList(methodAnns); @@ -970,7 +970,7 @@ public class HandleBuilder extends EclipseAnnotationHandler { builder.traverse(new SetGeneratedByVisitor(source), (ClassScope) null); return injectType(tdParent, builder); } - + private void addObtainVia(BuilderFieldData bfd, EclipseNode node) { for (EclipseNode child : node.down()) { if (!annotationTypeMatches(ObtainVia.class, child)) continue; @@ -980,14 +980,15 @@ public class HandleBuilder extends EclipseAnnotationHandler { return; } } - + /** * Returns the explicitly requested singular annotation on this node (field * or parameter), or null if there's no {@code @Singular} annotation on it. - * + * * @param node The node (field or method param) to inspect for its name and potential {@code @Singular} annotation. + * @param setterPrefix */ - private SingularData getSingularData(EclipseNode node, ASTNode source) { + private SingularData getSingularData(EclipseNode node, ASTNode source, final String setterPrefix) { for (EclipseNode child : node.down()) { if (!annotationTypeMatches(Singular.class, child)) continue; char[] pluralName = node.getKind() == Kind.FIELD ? removePrefixFromField(node) : ((AbstractVariableDeclaration) node.get()).name; @@ -1006,7 +1007,7 @@ public class HandleBuilder extends EclipseAnnotationHandler { } } char[] singularName = explicitSingular.toCharArray(); - + TypeReference type = ((AbstractVariableDeclaration) node.get()).type; TypeReference[] typeArgs = null; String typeName; @@ -1026,7 +1027,7 @@ public class HandleBuilder extends EclipseAnnotationHandler { } else { typeName = type.toString(); } - + String targetFqn = EclipseSingularsRecipes.get().toQualified(typeName); EclipseSingularizer singularizer = EclipseSingularsRecipes.get().getSingularizer(targetFqn); if (singularizer == null) { @@ -1034,9 +1035,9 @@ public class HandleBuilder extends EclipseAnnotationHandler { return null; } - return new SingularData(child, singularName, pluralName, typeArgs == null ? Collections.emptyList() : Arrays.asList(typeArgs), targetFqn, singularizer, source); + return new SingularData(child, singularName, pluralName, typeArgs == null ? Collections.emptyList() : Arrays.asList(typeArgs), targetFqn, singularizer, source, setterPrefix.toCharArray()); } - + return null; } } diff --git a/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilListSetSingularizer.java b/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilListSetSingularizer.java index 53ea15a6..e3a99008 100755 --- a/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilListSetSingularizer.java +++ b/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilListSetSingularizer.java @@ -150,7 +150,8 @@ abstract class EclipseJavaUtilListSetSingularizer extends EclipseJavaUtilSingula param.annotations = typeUseAnns; md.arguments = new Argument[] {param}; md.returnType = returnType; - md.selector = fluent ? data.getSingularName() : HandlerUtil.buildAccessorName("add", new String(data.getSingularName())).toCharArray(); + char[] prefixedSingularName = data.getSetterPrefix().length == 0 ? data.getSingularName() : HandlerUtil.buildAccessorName(new String(data.getSetterPrefix()), new String(data.getSingularName())).toCharArray(); + md.selector = fluent ? prefixedSingularName : HandlerUtil.buildAccessorName("add", new String(data.getSingularName())).toCharArray(); md.annotations = generateSelfReturnAnnotations(deprecate, cfv, data.getSource()); data.setGeneratedByRecursive(md); @@ -181,7 +182,8 @@ abstract class EclipseJavaUtilListSetSingularizer extends EclipseJavaUtilSingula Argument param = new Argument(data.getPluralName(), 0, paramType, ClassFileConstants.AccFinal); md.arguments = new Argument[] {param}; md.returnType = returnType; - md.selector = fluent ? data.getPluralName() : HandlerUtil.buildAccessorName("addAll", new String(data.getPluralName())).toCharArray(); + char[] prefixedSelector = data.getSetterPrefix().length == 0 ? data.getPluralName() : HandlerUtil.buildAccessorName(new String(data.getSetterPrefix()), new String(data.getPluralName())).toCharArray(); + md.selector = fluent ? prefixedSelector : HandlerUtil.buildAccessorName("addAll", new String(data.getPluralName())).toCharArray(); md.annotations = generateSelfReturnAnnotations(deprecate, cfv, data.getSource()); data.setGeneratedByRecursive(md); diff --git a/test/transform/resource/after-ecj/BuilderSingularAnnotatedTypesWithSetterPrefix.java b/test/transform/resource/after-ecj/BuilderSingularAnnotatedTypesWithSetterPrefix.java index 02369861..c978ff40 100644 --- a/test/transform/resource/after-ecj/BuilderSingularAnnotatedTypesWithSetterPrefix.java +++ b/test/transform/resource/after-ecj/BuilderSingularAnnotatedTypesWithSetterPrefix.java @@ -6,15 +6,15 @@ import lombok.NonNull; import lombok.Singular; @Target(ElementType.TYPE_USE) @interface MyAnnotation { } -@lombok.Builder(setterPrefix = "with") class BuilderSingularAnnotatedTypes { - public static @java.lang.SuppressWarnings("all") class BuilderSingularAnnotatedTypesBuilder { +@lombok.Builder(setterPrefix = "with") class BuilderSingularAnnotatedTypesWithSetterPrefix { + public static @java.lang.SuppressWarnings("all") class BuilderSingularAnnotatedTypesWithSetterPrefixBuilder { private @java.lang.SuppressWarnings("all") java.util.ArrayList<@MyAnnotation @NonNull String> foos; private @java.lang.SuppressWarnings("all") java.util.ArrayList<@MyAnnotation @NonNull String> bars$key; private @java.lang.SuppressWarnings("all") java.util.ArrayList<@MyAnnotation @NonNull Integer> bars$value; - @java.lang.SuppressWarnings("all") BuilderSingularAnnotatedTypesBuilder() { + @java.lang.SuppressWarnings("all") BuilderSingularAnnotatedTypesWithSetterPrefixBuilder() { super(); } - public @java.lang.SuppressWarnings("all") BuilderSingularAnnotatedTypesBuilder withFoo(final @MyAnnotation @NonNull String foo) { + public @java.lang.SuppressWarnings("all") BuilderSingularAnnotatedTypesWithSetterPrefixBuilder withFoo(final @MyAnnotation @NonNull String foo) { if ((foo == null)) { throw new java.lang.NullPointerException("foo is marked non-null but is null"); @@ -24,18 +24,18 @@ import lombok.Singular; this.foos.add(foo); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularAnnotatedTypesBuilder withFoos(final java.util.Collection foos) { + public @java.lang.SuppressWarnings("all") BuilderSingularAnnotatedTypesWithSetterPrefixBuilder withFoos(final java.util.Collection foos) { if ((this.foos == null)) this.foos = new java.util.ArrayList<@MyAnnotation @NonNull String>(); this.foos.addAll(foos); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularAnnotatedTypesBuilder clearFoos() { + public @java.lang.SuppressWarnings("all") BuilderSingularAnnotatedTypesWithSetterPrefixBuilder clearFoos() { if ((this.foos != null)) this.foos.clear(); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularAnnotatedTypesBuilder withBar(final @MyAnnotation @NonNull String barKey, final @MyAnnotation @NonNull Integer barValue) { + public @java.lang.SuppressWarnings("all") BuilderSingularAnnotatedTypesWithSetterPrefixBuilder withBar(final @MyAnnotation @NonNull String barKey, final @MyAnnotation @NonNull Integer barValue) { if ((barKey == null)) { throw new java.lang.NullPointerException("barKey is marked non-null but is null"); @@ -53,7 +53,7 @@ import lombok.Singular; this.bars$value.add(barValue); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularAnnotatedTypesBuilder withBars(final java.util.Map bars) { + public @java.lang.SuppressWarnings("all") BuilderSingularAnnotatedTypesWithSetterPrefixBuilder withBars(final java.util.Map bars) { if ((this.bars$key == null)) { this.bars$key = new java.util.ArrayList<@MyAnnotation @NonNull String>(); @@ -66,7 +66,7 @@ import lombok.Singular; } return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularAnnotatedTypesBuilder clearBars() { + public @java.lang.SuppressWarnings("all") BuilderSingularAnnotatedTypesWithSetterPrefixBuilder clearBars() { if ((this.bars$key != null)) { this.bars$key.clear(); @@ -74,7 +74,7 @@ import lombok.Singular; } return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularAnnotatedTypes build() { + public @java.lang.SuppressWarnings("all") BuilderSingularAnnotatedTypesWithSetterPrefix build() { java.util.Set<@MyAnnotation @NonNull String> foos; switch (((this.foos == null) ? 0 : this.foos.size())) { case 0 : @@ -102,20 +102,20 @@ import lombok.Singular; bars.put(this.bars$key.get($i), this.bars$value.get($i)); bars = java.util.Collections.unmodifiableMap(bars); } - return new BuilderSingularAnnotatedTypes(foos, bars); + return new BuilderSingularAnnotatedTypesWithSetterPrefix(foos, bars); } public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { - return (((((("BuilderSingularAnnotatedTypes.BuilderSingularAnnotatedTypesBuilder(foos=" + this.foos) + ", bars$key=") + this.bars$key) + ", bars$value=") + this.bars$value) + ")"); + return (((((("BuilderSingularAnnotatedTypesWithSetterPrefix.BuilderSingularAnnotatedTypesWithSetterPrefixBuilder(foos=" + this.foos) + ", bars$key=") + this.bars$key) + ", bars$value=") + this.bars$value) + ")"); } } private @Singular Set<@MyAnnotation @NonNull String> foos; private @Singular Map<@MyAnnotation @NonNull String, @MyAnnotation @NonNull Integer> bars; - @java.lang.SuppressWarnings("all") BuilderSingularAnnotatedTypes(final Set<@MyAnnotation @NonNull String> foos, final Map<@MyAnnotation @NonNull String, @MyAnnotation @NonNull Integer> bars) { + @java.lang.SuppressWarnings("all") BuilderSingularAnnotatedTypesWithSetterPrefix(final Set<@MyAnnotation @NonNull String> foos, final Map<@MyAnnotation @NonNull String, @MyAnnotation @NonNull Integer> bars) { super(); this.foos = foos; this.bars = bars; } - public static @java.lang.SuppressWarnings("all") BuilderSingularAnnotatedTypesBuilder builder() { - return new BuilderSingularAnnotatedTypesBuilder(); + public static @java.lang.SuppressWarnings("all") BuilderSingularAnnotatedTypesWithSetterPrefixBuilder builder() { + return new BuilderSingularAnnotatedTypesWithSetterPrefixBuilder(); } } diff --git a/test/transform/resource/after-ecj/BuilderSingularGuavaListsSetsWithSetterPrefix.java b/test/transform/resource/after-ecj/BuilderSingularGuavaListsSetsWithSetterPrefix.java index e9b0205d..ec700874 100644 --- a/test/transform/resource/after-ecj/BuilderSingularGuavaListsSetsWithSetterPrefix.java +++ b/test/transform/resource/after-ecj/BuilderSingularGuavaListsSetsWithSetterPrefix.java @@ -4,106 +4,106 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSortedSet; import com.google.common.collect.ImmutableTable; import lombok.Singular; -@lombok.Builder(setterPrefix = "with") class BuilderSingularGuavaListsSets { - public static @java.lang.SuppressWarnings("all") class BuilderSingularGuavaListsSetsBuilder { +@lombok.Builder(setterPrefix = "with") class BuilderSingularGuavaListsSetsWithSetterPrefix { + public static @java.lang.SuppressWarnings("all") class BuilderSingularGuavaListsSetsWithSetterPrefixBuilder { private @java.lang.SuppressWarnings("all") com.google.common.collect.ImmutableList.Builder cards; private @java.lang.SuppressWarnings("all") com.google.common.collect.ImmutableList.Builder frogs; private @java.lang.SuppressWarnings("all") com.google.common.collect.ImmutableSet.Builder rawSet; private @java.lang.SuppressWarnings("all") com.google.common.collect.ImmutableSortedSet.Builder passes; private @java.lang.SuppressWarnings("all") com.google.common.collect.ImmutableTable.Builder users; - @java.lang.SuppressWarnings("all") BuilderSingularGuavaListsSetsBuilder() { + @java.lang.SuppressWarnings("all") BuilderSingularGuavaListsSetsWithSetterPrefixBuilder() { super(); } - public @java.lang.SuppressWarnings("all") BuilderSingularGuavaListsSetsBuilder withCard(final T card) { + public @java.lang.SuppressWarnings("all") BuilderSingularGuavaListsSetsWithSetterPrefixBuilder withCard(final T card) { if ((this.cards == null)) this.cards = com.google.common.collect.ImmutableList.builder(); this.cards.add(card); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularGuavaListsSetsBuilder withCards(final java.lang.Iterable cards) { + public @java.lang.SuppressWarnings("all") BuilderSingularGuavaListsSetsWithSetterPrefixBuilder withCards(final java.lang.Iterable cards) { if ((this.cards == null)) this.cards = com.google.common.collect.ImmutableList.builder(); this.cards.addAll(cards); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularGuavaListsSetsBuilder clearCards() { + public @java.lang.SuppressWarnings("all") BuilderSingularGuavaListsSetsWithSetterPrefixBuilder clearCards() { this.cards = null; return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularGuavaListsSetsBuilder withFrog(final Number frog) { + public @java.lang.SuppressWarnings("all") BuilderSingularGuavaListsSetsWithSetterPrefixBuilder withFrog(final Number frog) { if ((this.frogs == null)) this.frogs = com.google.common.collect.ImmutableList.builder(); this.frogs.add(frog); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularGuavaListsSetsBuilder withFrogs(final java.lang.Iterable frogs) { + public @java.lang.SuppressWarnings("all") BuilderSingularGuavaListsSetsWithSetterPrefixBuilder withFrogs(final java.lang.Iterable frogs) { if ((this.frogs == null)) this.frogs = com.google.common.collect.ImmutableList.builder(); this.frogs.addAll(frogs); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularGuavaListsSetsBuilder clearFrogs() { + public @java.lang.SuppressWarnings("all") BuilderSingularGuavaListsSetsWithSetterPrefixBuilder clearFrogs() { this.frogs = null; return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularGuavaListsSetsBuilder withRawSet(final java.lang.Object rawSet) { + public @java.lang.SuppressWarnings("all") BuilderSingularGuavaListsSetsWithSetterPrefixBuilder withRawSet(final java.lang.Object rawSet) { if ((this.rawSet == null)) this.rawSet = com.google.common.collect.ImmutableSet.builder(); this.rawSet.add(rawSet); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularGuavaListsSetsBuilder withRawSet(final java.lang.Iterable rawSet) { + public @java.lang.SuppressWarnings("all") BuilderSingularGuavaListsSetsWithSetterPrefixBuilder withRawSet(final java.lang.Iterable rawSet) { if ((this.rawSet == null)) this.rawSet = com.google.common.collect.ImmutableSet.builder(); this.rawSet.addAll(rawSet); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularGuavaListsSetsBuilder clearRawSet() { + public @java.lang.SuppressWarnings("all") BuilderSingularGuavaListsSetsWithSetterPrefixBuilder clearRawSet() { this.rawSet = null; return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularGuavaListsSetsBuilder withPass(final String pass) { + public @java.lang.SuppressWarnings("all") BuilderSingularGuavaListsSetsWithSetterPrefixBuilder withPass(final String pass) { if ((this.passes == null)) this.passes = com.google.common.collect.ImmutableSortedSet.naturalOrder(); this.passes.add(pass); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularGuavaListsSetsBuilder withPasses(final java.lang.Iterable passes) { + public @java.lang.SuppressWarnings("all") BuilderSingularGuavaListsSetsWithSetterPrefixBuilder withPasses(final java.lang.Iterable passes) { if ((this.passes == null)) this.passes = com.google.common.collect.ImmutableSortedSet.naturalOrder(); this.passes.addAll(passes); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularGuavaListsSetsBuilder clearPasses() { + public @java.lang.SuppressWarnings("all") BuilderSingularGuavaListsSetsWithSetterPrefixBuilder clearPasses() { this.passes = null; return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularGuavaListsSetsBuilder withUser(final Number rowKey, final Number columnKey, final String value) { + public @java.lang.SuppressWarnings("all") BuilderSingularGuavaListsSetsWithSetterPrefixBuilder withUser(final Number rowKey, final Number columnKey, final String value) { if ((this.users == null)) this.users = com.google.common.collect.ImmutableTable.builder(); this.users.put(rowKey, columnKey, value); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularGuavaListsSetsBuilder withUsers(final com.google.common.collect.Table users) { + public @java.lang.SuppressWarnings("all") BuilderSingularGuavaListsSetsWithSetterPrefixBuilder withUsers(final com.google.common.collect.Table users) { if ((this.users == null)) this.users = com.google.common.collect.ImmutableTable.builder(); this.users.putAll(users); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularGuavaListsSetsBuilder clearUsers() { + public @java.lang.SuppressWarnings("all") BuilderSingularGuavaListsSetsWithSetterPrefixBuilder clearUsers() { this.users = null; return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularGuavaListsSets build() { + public @java.lang.SuppressWarnings("all") BuilderSingularGuavaListsSetsWithSetterPrefix build() { com.google.common.collect.ImmutableList cards = ((this.cards == null) ? com.google.common.collect.ImmutableList.of() : this.cards.build()); com.google.common.collect.ImmutableCollection frogs = ((this.frogs == null) ? com.google.common.collect.ImmutableList.of() : this.frogs.build()); com.google.common.collect.ImmutableSet rawSet = ((this.rawSet == null) ? com.google.common.collect.ImmutableSet.of() : this.rawSet.build()); com.google.common.collect.ImmutableSortedSet passes = ((this.passes == null) ? com.google.common.collect.ImmutableSortedSet.of() : this.passes.build()); com.google.common.collect.ImmutableTable users = ((this.users == null) ? com.google.common.collect.ImmutableTable.of() : this.users.build()); - return new BuilderSingularGuavaListsSets(cards, frogs, rawSet, passes, users); + return new BuilderSingularGuavaListsSetsWithSetterPrefix(cards, frogs, rawSet, passes, users); } public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { - return (((((((((("BuilderSingularGuavaListsSets.BuilderSingularGuavaListsSetsBuilder(cards=" + this.cards) + ", frogs=") + this.frogs) + ", rawSet=") + this.rawSet) + ", passes=") + this.passes) + ", users=") + this.users) + ")"); + return (((((((((("BuilderSingularGuavaListsSetsWithSetterPrefix.BuilderSingularGuavaListsSetsWithSetterPrefixBuilder(cards=" + this.cards) + ", frogs=") + this.frogs) + ", rawSet=") + this.rawSet) + ", passes=") + this.passes) + ", users=") + this.users) + ")"); } } private @Singular ImmutableList cards; @@ -111,7 +111,7 @@ import lombok.Singular; private @SuppressWarnings("all") @Singular("rawSet") ImmutableSet rawSet; private @Singular ImmutableSortedSet passes; private @Singular ImmutableTable users; - @java.lang.SuppressWarnings("all") BuilderSingularGuavaListsSets(final ImmutableList cards, final ImmutableCollection frogs, final ImmutableSet rawSet, final ImmutableSortedSet passes, final ImmutableTable users) { + @java.lang.SuppressWarnings("all") BuilderSingularGuavaListsSetsWithSetterPrefix(final ImmutableList cards, final ImmutableCollection frogs, final ImmutableSet rawSet, final ImmutableSortedSet passes, final ImmutableTable users) { super(); this.cards = cards; this.frogs = frogs; @@ -119,7 +119,7 @@ import lombok.Singular; this.passes = passes; this.users = users; } - public static @java.lang.SuppressWarnings("all") BuilderSingularGuavaListsSetsBuilder builder() { - return new BuilderSingularGuavaListsSetsBuilder(); + public static @java.lang.SuppressWarnings("all") BuilderSingularGuavaListsSetsWithSetterPrefixBuilder builder() { + return new BuilderSingularGuavaListsSetsWithSetterPrefixBuilder(); } } diff --git a/test/transform/resource/after-ecj/BuilderSingularGuavaMapsWithSetterPrefix.java b/test/transform/resource/after-ecj/BuilderSingularGuavaMapsWithSetterPrefix.java index fe1f0036..0f58f7a4 100644 --- a/test/transform/resource/after-ecj/BuilderSingularGuavaMapsWithSetterPrefix.java +++ b/test/transform/resource/after-ecj/BuilderSingularGuavaMapsWithSetterPrefix.java @@ -2,82 +2,82 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableBiMap; import com.google.common.collect.ImmutableSortedMap; import lombok.Singular; -@lombok.Builder(setterPrefix = "with") class BuilderSingularGuavaMaps { - public static @java.lang.SuppressWarnings("all") class BuilderSingularGuavaMapsBuilder { +@lombok.Builder(setterPrefix = "with") class BuilderSingularGuavaMapsWithSetterPrefix { + public static @java.lang.SuppressWarnings("all") class BuilderSingularGuavaMapsWithSetterPrefixBuilder { private @java.lang.SuppressWarnings("all") com.google.common.collect.ImmutableMap.Builder battleaxes; private @java.lang.SuppressWarnings("all") com.google.common.collect.ImmutableSortedMap.Builder vertices; private @java.lang.SuppressWarnings("all") com.google.common.collect.ImmutableBiMap.Builder rawMap; - @java.lang.SuppressWarnings("all") BuilderSingularGuavaMapsBuilder() { + @java.lang.SuppressWarnings("all") BuilderSingularGuavaMapsWithSetterPrefixBuilder() { super(); } - public @java.lang.SuppressWarnings("all") BuilderSingularGuavaMapsBuilder withBattleaxe(final K key, final V value) { + public @java.lang.SuppressWarnings("all") BuilderSingularGuavaMapsWithSetterPrefixBuilder withBattleaxe(final K key, final V value) { if ((this.battleaxes == null)) this.battleaxes = com.google.common.collect.ImmutableMap.builder(); this.battleaxes.put(key, value); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularGuavaMapsBuilder withBattleaxes(final java.util.Map battleaxes) { + public @java.lang.SuppressWarnings("all") BuilderSingularGuavaMapsWithSetterPrefixBuilder withBattleaxes(final java.util.Map battleaxes) { if ((this.battleaxes == null)) this.battleaxes = com.google.common.collect.ImmutableMap.builder(); this.battleaxes.putAll(battleaxes); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularGuavaMapsBuilder clearBattleaxes() { + public @java.lang.SuppressWarnings("all") BuilderSingularGuavaMapsWithSetterPrefixBuilder clearBattleaxes() { this.battleaxes = null; return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularGuavaMapsBuilder withVertex(final Integer key, final V value) { + public @java.lang.SuppressWarnings("all") BuilderSingularGuavaMapsWithSetterPrefixBuilder withVertex(final Integer key, final V value) { if ((this.vertices == null)) this.vertices = com.google.common.collect.ImmutableSortedMap.naturalOrder(); this.vertices.put(key, value); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularGuavaMapsBuilder withVertices(final java.util.Map vertices) { + public @java.lang.SuppressWarnings("all") BuilderSingularGuavaMapsWithSetterPrefixBuilder withVertices(final java.util.Map vertices) { if ((this.vertices == null)) this.vertices = com.google.common.collect.ImmutableSortedMap.naturalOrder(); this.vertices.putAll(vertices); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularGuavaMapsBuilder clearVertices() { + public @java.lang.SuppressWarnings("all") BuilderSingularGuavaMapsWithSetterPrefixBuilder clearVertices() { this.vertices = null; return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularGuavaMapsBuilder withRawMap(final java.lang.Object key, final java.lang.Object value) { + public @java.lang.SuppressWarnings("all") BuilderSingularGuavaMapsWithSetterPrefixBuilder withRawMap(final java.lang.Object key, final java.lang.Object value) { if ((this.rawMap == null)) this.rawMap = com.google.common.collect.ImmutableBiMap.builder(); this.rawMap.put(key, value); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularGuavaMapsBuilder withRawMap(final java.util.Map rawMap) { + public @java.lang.SuppressWarnings("all") BuilderSingularGuavaMapsWithSetterPrefixBuilder withRawMap(final java.util.Map rawMap) { if ((this.rawMap == null)) this.rawMap = com.google.common.collect.ImmutableBiMap.builder(); this.rawMap.putAll(rawMap); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularGuavaMapsBuilder clearRawMap() { + public @java.lang.SuppressWarnings("all") BuilderSingularGuavaMapsWithSetterPrefixBuilder clearRawMap() { this.rawMap = null; return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularGuavaMaps build() { + public @java.lang.SuppressWarnings("all") BuilderSingularGuavaMapsWithSetterPrefix build() { com.google.common.collect.ImmutableMap battleaxes = ((this.battleaxes == null) ? com.google.common.collect.ImmutableMap.of() : this.battleaxes.build()); com.google.common.collect.ImmutableSortedMap vertices = ((this.vertices == null) ? com.google.common.collect.ImmutableSortedMap.of() : this.vertices.build()); com.google.common.collect.ImmutableBiMap rawMap = ((this.rawMap == null) ? com.google.common.collect.ImmutableBiMap.of() : this.rawMap.build()); - return new BuilderSingularGuavaMaps(battleaxes, vertices, rawMap); + return new BuilderSingularGuavaMapsWithSetterPrefix(battleaxes, vertices, rawMap); } public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { - return (((((("BuilderSingularGuavaMaps.BuilderSingularGuavaMapsBuilder(battleaxes=" + this.battleaxes) + ", vertices=") + this.vertices) + ", rawMap=") + this.rawMap) + ")"); + return (((((("BuilderSingularGuavaMapsWithSetterPrefix.BuilderSingularGuavaMapsWithSetterPrefixBuilder(battleaxes=" + this.battleaxes) + ", vertices=") + this.vertices) + ", rawMap=") + this.rawMap) + ")"); } } private @Singular ImmutableMap battleaxes; private @Singular ImmutableSortedMap vertices; private @SuppressWarnings("all") @Singular("rawMap") ImmutableBiMap rawMap; - @java.lang.SuppressWarnings("all") BuilderSingularGuavaMaps(final ImmutableMap battleaxes, final ImmutableSortedMap vertices, final ImmutableBiMap rawMap) { + @java.lang.SuppressWarnings("all") BuilderSingularGuavaMapsWithSetterPrefix(final ImmutableMap battleaxes, final ImmutableSortedMap vertices, final ImmutableBiMap rawMap) { super(); this.battleaxes = battleaxes; this.vertices = vertices; this.rawMap = rawMap; } - public static @java.lang.SuppressWarnings("all") BuilderSingularGuavaMapsBuilder builder() { - return new BuilderSingularGuavaMapsBuilder(); + public static @java.lang.SuppressWarnings("all") BuilderSingularGuavaMapsWithSetterPrefixBuilder builder() { + return new BuilderSingularGuavaMapsWithSetterPrefixBuilder(); } } diff --git a/test/transform/resource/after-ecj/BuilderSingularListsWithSetterPrefix.java b/test/transform/resource/after-ecj/BuilderSingularListsWithSetterPrefix.java index 110cc2c3..ab90cb48 100644 --- a/test/transform/resource/after-ecj/BuilderSingularListsWithSetterPrefix.java +++ b/test/transform/resource/after-ecj/BuilderSingularListsWithSetterPrefix.java @@ -2,66 +2,66 @@ import java.util.List; import java.util.Collection; import lombok.Singular; -@lombok.Builder(setterPrefix = "with") class BuilderSingularLists { - public static @java.lang.SuppressWarnings("all") class BuilderSingularListsBuilder { +@lombok.Builder(setterPrefix = "with") class BuilderSingularListsWithSetterPrefix { + public static @java.lang.SuppressWarnings("all") class BuilderSingularListsWithSetterPrefixBuilder { private @java.lang.SuppressWarnings("all") java.util.ArrayList children; private @java.lang.SuppressWarnings("all") java.util.ArrayList scarves; private @java.lang.SuppressWarnings("all") java.util.ArrayList rawList; - @java.lang.SuppressWarnings("all") BuilderSingularListsBuilder() { + @java.lang.SuppressWarnings("all") BuilderSingularListsWithSetterPrefixBuilder() { super(); } - public @java.lang.SuppressWarnings("all") BuilderSingularListsBuilder withChild(final T child) { + public @java.lang.SuppressWarnings("all") BuilderSingularListsWithSetterPrefixBuilder withChild(final T child) { if ((this.children == null)) this.children = new java.util.ArrayList(); this.children.add(child); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularListsBuilder withChildren(final java.util.Collection children) { + public @java.lang.SuppressWarnings("all") BuilderSingularListsWithSetterPrefixBuilder withChildren(final java.util.Collection children) { if ((this.children == null)) this.children = new java.util.ArrayList(); this.children.addAll(children); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularListsBuilder clearChildren() { + public @java.lang.SuppressWarnings("all") BuilderSingularListsWithSetterPrefixBuilder clearChildren() { if ((this.children != null)) this.children.clear(); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularListsBuilder withScarf(final Number scarf) { + public @java.lang.SuppressWarnings("all") BuilderSingularListsWithSetterPrefixBuilder withScarf(final Number scarf) { if ((this.scarves == null)) this.scarves = new java.util.ArrayList(); this.scarves.add(scarf); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularListsBuilder withScarves(final java.util.Collection scarves) { + public @java.lang.SuppressWarnings("all") BuilderSingularListsWithSetterPrefixBuilder withScarves(final java.util.Collection scarves) { if ((this.scarves == null)) this.scarves = new java.util.ArrayList(); this.scarves.addAll(scarves); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularListsBuilder clearScarves() { + public @java.lang.SuppressWarnings("all") BuilderSingularListsWithSetterPrefixBuilder clearScarves() { if ((this.scarves != null)) this.scarves.clear(); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularListsBuilder withRawList(final java.lang.Object rawList) { + public @java.lang.SuppressWarnings("all") BuilderSingularListsWithSetterPrefixBuilder withRawList(final java.lang.Object rawList) { if ((this.rawList == null)) this.rawList = new java.util.ArrayList(); this.rawList.add(rawList); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularListsBuilder withRawList(final java.util.Collection rawList) { + public @java.lang.SuppressWarnings("all") BuilderSingularListsWithSetterPrefixBuilder withRawList(final java.util.Collection rawList) { if ((this.rawList == null)) this.rawList = new java.util.ArrayList(); this.rawList.addAll(rawList); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularListsBuilder clearRawList() { + public @java.lang.SuppressWarnings("all") BuilderSingularListsWithSetterPrefixBuilder clearRawList() { if ((this.rawList != null)) this.rawList.clear(); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularLists build() { + public @java.lang.SuppressWarnings("all") BuilderSingularListsWithSetterPrefix build() { java.util.List children; switch (((this.children == null) ? 0 : this.children.size())) { case 0 : @@ -95,22 +95,22 @@ import lombok.Singular; default : rawList = java.util.Collections.unmodifiableList(new java.util.ArrayList(this.rawList)); } - return new BuilderSingularLists(children, scarves, rawList); + return new BuilderSingularListsWithSetterPrefix(children, scarves, rawList); } public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { - return (((((("BuilderSingularLists.BuilderSingularListsBuilder(children=" + this.children) + ", scarves=") + this.scarves) + ", rawList=") + this.rawList) + ")"); + return (((((("BuilderSingularListsWithSetterPrefix.BuilderSingularListsWithSetterPrefixBuilder(children=" + this.children) + ", scarves=") + this.scarves) + ", rawList=") + this.rawList) + ")"); } } private @Singular List children; private @Singular Collection scarves; private @SuppressWarnings("all") @Singular("rawList") List rawList; - @java.lang.SuppressWarnings("all") BuilderSingularLists(final List children, final Collection scarves, final List rawList) { + @java.lang.SuppressWarnings("all") BuilderSingularListsWithSetterPrefix(final List children, final Collection scarves, final List rawList) { super(); this.children = children; this.scarves = scarves; this.rawList = rawList; } - public static @java.lang.SuppressWarnings("all") BuilderSingularListsBuilder builder() { - return new BuilderSingularListsBuilder(); + public static @java.lang.SuppressWarnings("all") BuilderSingularListsWithSetterPrefixBuilder builder() { + return new BuilderSingularListsWithSetterPrefixBuilder(); } } diff --git a/test/transform/resource/after-ecj/BuilderSingularMapsWithSetterPrefix.java b/test/transform/resource/after-ecj/BuilderSingularMapsWithSetterPrefix.java index 9193ccf9..7848b154 100644 --- a/test/transform/resource/after-ecj/BuilderSingularMapsWithSetterPrefix.java +++ b/test/transform/resource/after-ecj/BuilderSingularMapsWithSetterPrefix.java @@ -1,8 +1,8 @@ import java.util.Map; import java.util.SortedMap; import lombok.Singular; -@lombok.Builder(setterPrefix = "with") class BuilderSingularMaps { - public static @java.lang.SuppressWarnings("all") class BuilderSingularMapsBuilder { +@lombok.Builder(setterPrefix = "with") class BuilderSingularMapsWithSetterPrefix { + public static @java.lang.SuppressWarnings("all") class BuilderSingularMapsWithSetterPrefixBuilder { private @java.lang.SuppressWarnings("all") java.util.ArrayList women$key; private @java.lang.SuppressWarnings("all") java.util.ArrayList women$value; private @java.lang.SuppressWarnings("all") java.util.ArrayList men$key; @@ -11,10 +11,10 @@ import lombok.Singular; private @java.lang.SuppressWarnings("all") java.util.ArrayList rawMap$value; private @java.lang.SuppressWarnings("all") java.util.ArrayList stringMap$key; private @java.lang.SuppressWarnings("all") java.util.ArrayList stringMap$value; - @java.lang.SuppressWarnings("all") BuilderSingularMapsBuilder() { + @java.lang.SuppressWarnings("all") BuilderSingularMapsWithSetterPrefixBuilder() { super(); } - public @java.lang.SuppressWarnings("all") BuilderSingularMapsBuilder withWoman(final K womanKey, final V womanValue) { + public @java.lang.SuppressWarnings("all") BuilderSingularMapsWithSetterPrefixBuilder withWoman(final K womanKey, final V womanValue) { if ((this.women$key == null)) { this.women$key = new java.util.ArrayList(); @@ -24,7 +24,7 @@ import lombok.Singular; this.women$value.add(womanValue); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularMapsBuilder withWomen(final java.util.Map women) { + public @java.lang.SuppressWarnings("all") BuilderSingularMapsWithSetterPrefixBuilder withWomen(final java.util.Map women) { if ((this.women$key == null)) { this.women$key = new java.util.ArrayList(); @@ -37,7 +37,7 @@ import lombok.Singular; } return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularMapsBuilder clearWomen() { + public @java.lang.SuppressWarnings("all") BuilderSingularMapsWithSetterPrefixBuilder clearWomen() { if ((this.women$key != null)) { this.women$key.clear(); @@ -45,7 +45,7 @@ import lombok.Singular; } return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularMapsBuilder withMan(final K manKey, final Number manValue) { + public @java.lang.SuppressWarnings("all") BuilderSingularMapsWithSetterPrefixBuilder withMan(final K manKey, final Number manValue) { if ((this.men$key == null)) { this.men$key = new java.util.ArrayList(); @@ -55,7 +55,7 @@ import lombok.Singular; this.men$value.add(manValue); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularMapsBuilder withMen(final java.util.Map men) { + public @java.lang.SuppressWarnings("all") BuilderSingularMapsWithSetterPrefixBuilder withMen(final java.util.Map men) { if ((this.men$key == null)) { this.men$key = new java.util.ArrayList(); @@ -68,7 +68,7 @@ import lombok.Singular; } return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularMapsBuilder clearMen() { + public @java.lang.SuppressWarnings("all") BuilderSingularMapsWithSetterPrefixBuilder clearMen() { if ((this.men$key != null)) { this.men$key.clear(); @@ -76,7 +76,7 @@ import lombok.Singular; } return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularMapsBuilder withRawMap(final java.lang.Object rawMapKey, final java.lang.Object rawMapValue) { + public @java.lang.SuppressWarnings("all") BuilderSingularMapsWithSetterPrefixBuilder withRawMap(final java.lang.Object rawMapKey, final java.lang.Object rawMapValue) { if ((this.rawMap$key == null)) { this.rawMap$key = new java.util.ArrayList(); @@ -86,7 +86,7 @@ import lombok.Singular; this.rawMap$value.add(rawMapValue); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularMapsBuilder withRawMap(final java.util.Map rawMap) { + public @java.lang.SuppressWarnings("all") BuilderSingularMapsWithSetterPrefixBuilder withRawMap(final java.util.Map rawMap) { if ((this.rawMap$key == null)) { this.rawMap$key = new java.util.ArrayList(); @@ -99,7 +99,7 @@ import lombok.Singular; } return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularMapsBuilder clearRawMap() { + public @java.lang.SuppressWarnings("all") BuilderSingularMapsWithSetterPrefixBuilder clearRawMap() { if ((this.rawMap$key != null)) { this.rawMap$key.clear(); @@ -107,7 +107,7 @@ import lombok.Singular; } return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularMapsBuilder withStringMap(final String stringMapKey, final V stringMapValue) { + public @java.lang.SuppressWarnings("all") BuilderSingularMapsWithSetterPrefixBuilder withStringMap(final String stringMapKey, final V stringMapValue) { if ((this.stringMap$key == null)) { this.stringMap$key = new java.util.ArrayList(); @@ -117,7 +117,7 @@ import lombok.Singular; this.stringMap$value.add(stringMapValue); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularMapsBuilder withStringMap(final java.util.Map stringMap) { + public @java.lang.SuppressWarnings("all") BuilderSingularMapsWithSetterPrefixBuilder withStringMap(final java.util.Map stringMap) { if ((this.stringMap$key == null)) { this.stringMap$key = new java.util.ArrayList(); @@ -130,7 +130,7 @@ import lombok.Singular; } return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularMapsBuilder clearStringMap() { + public @java.lang.SuppressWarnings("all") BuilderSingularMapsWithSetterPrefixBuilder clearStringMap() { if ((this.stringMap$key != null)) { this.stringMap$key.clear(); @@ -138,7 +138,7 @@ import lombok.Singular; } return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularMaps build() { + public @java.lang.SuppressWarnings("all") BuilderSingularMapsWithSetterPrefix build() { java.util.Map women; switch (((this.women$key == null) ? 0 : this.women$key.size())) { case 0 : @@ -186,24 +186,24 @@ import lombok.Singular; stringMap.put(this.stringMap$key.get($i), this.stringMap$value.get($i)); stringMap = java.util.Collections.unmodifiableMap(stringMap); } - return new BuilderSingularMaps(women, men, rawMap, stringMap); + return new BuilderSingularMapsWithSetterPrefix(women, men, rawMap, stringMap); } public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { - return (((((((((((((((("BuilderSingularMaps.BuilderSingularMapsBuilder(women$key=" + this.women$key) + ", women$value=") + this.women$value) + ", men$key=") + this.men$key) + ", men$value=") + this.men$value) + ", rawMap$key=") + this.rawMap$key) + ", rawMap$value=") + this.rawMap$value) + ", stringMap$key=") + this.stringMap$key) + ", stringMap$value=") + this.stringMap$value) + ")"); + return (((((((((((((((("BuilderSingularMapsWithSetterPrefix.BuilderSingularMapsWithSetterPrefixBuilder(women$key=" + this.women$key) + ", women$value=") + this.women$value) + ", men$key=") + this.men$key) + ", men$value=") + this.men$value) + ", rawMap$key=") + this.rawMap$key) + ", rawMap$value=") + this.rawMap$value) + ", stringMap$key=") + this.stringMap$key) + ", stringMap$value=") + this.stringMap$value) + ")"); } } private @Singular Map women; private @Singular SortedMap men; private @SuppressWarnings("all") @Singular("rawMap") Map rawMap; private @Singular("stringMap") Map stringMap; - @java.lang.SuppressWarnings("all") BuilderSingularMaps(final Map women, final SortedMap men, final Map rawMap, final Map stringMap) { + @java.lang.SuppressWarnings("all") BuilderSingularMapsWithSetterPrefix(final Map women, final SortedMap men, final Map rawMap, final Map stringMap) { super(); this.women = women; this.men = men; this.rawMap = rawMap; this.stringMap = stringMap; } - public static @java.lang.SuppressWarnings("all") BuilderSingularMapsBuilder builder() { - return new BuilderSingularMapsBuilder(); + public static @java.lang.SuppressWarnings("all") BuilderSingularMapsWithSetterPrefixBuilder builder() { + return new BuilderSingularMapsWithSetterPrefixBuilder(); } } diff --git a/test/transform/resource/after-ecj/BuilderSingularNoAutoWithSetterPrefix.java b/test/transform/resource/after-ecj/BuilderSingularNoAutoWithSetterPrefix.java index a7754a99..f24b1640 100644 --- a/test/transform/resource/after-ecj/BuilderSingularNoAutoWithSetterPrefix.java +++ b/test/transform/resource/after-ecj/BuilderSingularNoAutoWithSetterPrefix.java @@ -1,65 +1,65 @@ import java.util.List; import lombok.Singular; -@lombok.Builder(setterPrefix = "with") class BuilderSingularNoAuto { - public static @java.lang.SuppressWarnings("all") class BuilderSingularNoAutoBuilder { +@lombok.Builder(setterPrefix = "with") class BuilderSingularNoAutoWithSetterPrefix { + public static @java.lang.SuppressWarnings("all") class BuilderSingularNoAutoWithSetterPrefixBuilder { private @java.lang.SuppressWarnings("all") java.util.ArrayList things; private @java.lang.SuppressWarnings("all") java.util.ArrayList widgets; private @java.lang.SuppressWarnings("all") java.util.ArrayList items; - @java.lang.SuppressWarnings("all") BuilderSingularNoAutoBuilder() { + @java.lang.SuppressWarnings("all") BuilderSingularNoAutoWithSetterPrefixBuilder() { super(); } - public @java.lang.SuppressWarnings("all") BuilderSingularNoAutoBuilder withThings(final String things) { + public @java.lang.SuppressWarnings("all") BuilderSingularNoAutoWithSetterPrefixBuilder withThings(final String things) { if ((this.things == null)) this.things = new java.util.ArrayList(); this.things.add(things); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularNoAutoBuilder withThings(final java.util.Collection things) { + public @java.lang.SuppressWarnings("all") BuilderSingularNoAutoWithSetterPrefixBuilder withThings(final java.util.Collection things) { if ((this.things == null)) this.things = new java.util.ArrayList(); this.things.addAll(things); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularNoAutoBuilder clearThings() { + public @java.lang.SuppressWarnings("all") BuilderSingularNoAutoWithSetterPrefixBuilder clearThings() { if ((this.things != null)) this.things.clear(); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularNoAutoBuilder withWidget(final String widget) { + public @java.lang.SuppressWarnings("all") BuilderSingularNoAutoWithSetterPrefixBuilder withWidget(final String widget) { if ((this.widgets == null)) this.widgets = new java.util.ArrayList(); this.widgets.add(widget); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularNoAutoBuilder withWidgets(final java.util.Collection widgets) { + public @java.lang.SuppressWarnings("all") BuilderSingularNoAutoWithSetterPrefixBuilder withWidgets(final java.util.Collection widgets) { if ((this.widgets == null)) this.widgets = new java.util.ArrayList(); this.widgets.addAll(widgets); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularNoAutoBuilder clearWidgets() { + public @java.lang.SuppressWarnings("all") BuilderSingularNoAutoWithSetterPrefixBuilder clearWidgets() { if ((this.widgets != null)) this.widgets.clear(); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularNoAutoBuilder withItems(final String items) { + public @java.lang.SuppressWarnings("all") BuilderSingularNoAutoWithSetterPrefixBuilder withItems(final String items) { if ((this.items == null)) this.items = new java.util.ArrayList(); this.items.add(items); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularNoAutoBuilder withItems(final java.util.Collection items) { + public @java.lang.SuppressWarnings("all") BuilderSingularNoAutoWithSetterPrefixBuilder withItems(final java.util.Collection items) { if ((this.items == null)) this.items = new java.util.ArrayList(); this.items.addAll(items); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularNoAutoBuilder clearItems() { + public @java.lang.SuppressWarnings("all") BuilderSingularNoAutoWithSetterPrefixBuilder clearItems() { if ((this.items != null)) this.items.clear(); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularNoAuto build() { + public @java.lang.SuppressWarnings("all") BuilderSingularNoAutoWithSetterPrefix build() { java.util.List things; switch (((this.things == null) ? 0 : this.things.size())) { case 0 : @@ -93,22 +93,22 @@ import lombok.Singular; default : items = java.util.Collections.unmodifiableList(new java.util.ArrayList(this.items)); } - return new BuilderSingularNoAuto(things, widgets, items); + return new BuilderSingularNoAutoWithSetterPrefix(things, widgets, items); } public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { - return (((((("BuilderSingularNoAuto.BuilderSingularNoAutoBuilder(things=" + this.things) + ", widgets=") + this.widgets) + ", items=") + this.items) + ")"); + return (((((("BuilderSingularNoAutoWithSetterPrefix.BuilderSingularNoAutoWithSetterPrefixBuilder(things=" + this.things) + ", widgets=") + this.widgets) + ", items=") + this.items) + ")"); } } private @Singular List things; private @Singular("widget") List widgets; private @Singular List items; - @java.lang.SuppressWarnings("all") BuilderSingularNoAuto(final List things, final List widgets, final List items) { + @java.lang.SuppressWarnings("all") BuilderSingularNoAutoWithSetterPrefix(final List things, final List widgets, final List items) { super(); this.things = things; this.widgets = widgets; this.items = items; } - public static @java.lang.SuppressWarnings("all") BuilderSingularNoAutoBuilder builder() { - return new BuilderSingularNoAutoBuilder(); + public static @java.lang.SuppressWarnings("all") BuilderSingularNoAutoWithSetterPrefixBuilder builder() { + return new BuilderSingularNoAutoWithSetterPrefixBuilder(); } } diff --git a/test/transform/resource/after-ecj/BuilderSingularRedirectToGuavaWithSetterPrefix.java b/test/transform/resource/after-ecj/BuilderSingularRedirectToGuavaWithSetterPrefix.java index 6f12f986..c6e163cb 100644 --- a/test/transform/resource/after-ecj/BuilderSingularRedirectToGuavaWithSetterPrefix.java +++ b/test/transform/resource/after-ecj/BuilderSingularRedirectToGuavaWithSetterPrefix.java @@ -2,82 +2,82 @@ import java.util.Set; import java.util.NavigableMap; import java.util.Collection; import lombok.Singular; -@lombok.Builder(setterPrefix = "with") class BuilderSingularRedirectToGuava { - public static @java.lang.SuppressWarnings("all") class BuilderSingularRedirectToGuavaBuilder { +@lombok.Builder(setterPrefix = "with") class BuilderSingularRedirectToGuavaWithSetterPrefix { + public static @java.lang.SuppressWarnings("all") class BuilderSingularRedirectToGuavaWithSetterPrefixBuilder { private @java.lang.SuppressWarnings("all") com.google.common.collect.ImmutableSet.Builder dangerMice; private @java.lang.SuppressWarnings("all") com.google.common.collect.ImmutableSortedMap.Builder things; private @java.lang.SuppressWarnings("all") com.google.common.collect.ImmutableList.Builder> doohickeys; - @java.lang.SuppressWarnings("all") BuilderSingularRedirectToGuavaBuilder() { + @java.lang.SuppressWarnings("all") BuilderSingularRedirectToGuavaWithSetterPrefixBuilder() { super(); } - public @java.lang.SuppressWarnings("all") BuilderSingularRedirectToGuavaBuilder withDangerMouse(final String dangerMouse) { + public @java.lang.SuppressWarnings("all") BuilderSingularRedirectToGuavaWithSetterPrefixBuilder withDangerMouse(final String dangerMouse) { if ((this.dangerMice == null)) this.dangerMice = com.google.common.collect.ImmutableSet.builder(); this.dangerMice.add(dangerMouse); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularRedirectToGuavaBuilder withDangerMice(final java.lang.Iterable dangerMice) { + public @java.lang.SuppressWarnings("all") BuilderSingularRedirectToGuavaWithSetterPrefixBuilder withDangerMice(final java.lang.Iterable dangerMice) { if ((this.dangerMice == null)) this.dangerMice = com.google.common.collect.ImmutableSet.builder(); this.dangerMice.addAll(dangerMice); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularRedirectToGuavaBuilder clearDangerMice() { + public @java.lang.SuppressWarnings("all") BuilderSingularRedirectToGuavaWithSetterPrefixBuilder clearDangerMice() { this.dangerMice = null; return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularRedirectToGuavaBuilder withThing(final Integer key, final Number value) { + public @java.lang.SuppressWarnings("all") BuilderSingularRedirectToGuavaWithSetterPrefixBuilder withThing(final Integer key, final Number value) { if ((this.things == null)) this.things = com.google.common.collect.ImmutableSortedMap.naturalOrder(); this.things.put(key, value); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularRedirectToGuavaBuilder withThings(final java.util.Map things) { + public @java.lang.SuppressWarnings("all") BuilderSingularRedirectToGuavaWithSetterPrefixBuilder withThings(final java.util.Map things) { if ((this.things == null)) this.things = com.google.common.collect.ImmutableSortedMap.naturalOrder(); this.things.putAll(things); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularRedirectToGuavaBuilder clearThings() { + public @java.lang.SuppressWarnings("all") BuilderSingularRedirectToGuavaWithSetterPrefixBuilder clearThings() { this.things = null; return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularRedirectToGuavaBuilder withDoohickey(final Class doohickey) { + public @java.lang.SuppressWarnings("all") BuilderSingularRedirectToGuavaWithSetterPrefixBuilder withDoohickey(final Class doohickey) { if ((this.doohickeys == null)) this.doohickeys = com.google.common.collect.ImmutableList.builder(); this.doohickeys.add(doohickey); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularRedirectToGuavaBuilder withDoohickeys(final java.lang.Iterable> doohickeys) { + public @java.lang.SuppressWarnings("all") BuilderSingularRedirectToGuavaWithSetterPrefixBuilder withDoohickeys(final java.lang.Iterable> doohickeys) { if ((this.doohickeys == null)) this.doohickeys = com.google.common.collect.ImmutableList.builder(); this.doohickeys.addAll(doohickeys); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularRedirectToGuavaBuilder clearDoohickeys() { + public @java.lang.SuppressWarnings("all") BuilderSingularRedirectToGuavaWithSetterPrefixBuilder clearDoohickeys() { this.doohickeys = null; return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularRedirectToGuava build() { + public @java.lang.SuppressWarnings("all") BuilderSingularRedirectToGuavaWithSetterPrefix build() { java.util.Set dangerMice = ((this.dangerMice == null) ? com.google.common.collect.ImmutableSet.of() : this.dangerMice.build()); java.util.NavigableMap things = ((this.things == null) ? com.google.common.collect.ImmutableSortedMap.of() : this.things.build()); java.util.Collection> doohickeys = ((this.doohickeys == null) ? com.google.common.collect.ImmutableList.>of() : this.doohickeys.build()); - return new BuilderSingularRedirectToGuava(dangerMice, things, doohickeys); + return new BuilderSingularRedirectToGuavaWithSetterPrefix(dangerMice, things, doohickeys); } public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { - return (((((("BuilderSingularRedirectToGuava.BuilderSingularRedirectToGuavaBuilder(dangerMice=" + this.dangerMice) + ", things=") + this.things) + ", doohickeys=") + this.doohickeys) + ")"); + return (((((("BuilderSingularRedirectToGuavaWithSetterPrefix.BuilderSingularRedirectToGuavaWithSetterPrefixBuilder(dangerMice=" + this.dangerMice) + ", things=") + this.things) + ", doohickeys=") + this.doohickeys) + ")"); } } private @Singular Set dangerMice; private @Singular NavigableMap things; private @Singular Collection> doohickeys; - @java.lang.SuppressWarnings("all") BuilderSingularRedirectToGuava(final Set dangerMice, final NavigableMap things, final Collection> doohickeys) { + @java.lang.SuppressWarnings("all") BuilderSingularRedirectToGuavaWithSetterPrefix(final Set dangerMice, final NavigableMap things, final Collection> doohickeys) { super(); this.dangerMice = dangerMice; this.things = things; this.doohickeys = doohickeys; } - public static @java.lang.SuppressWarnings("all") BuilderSingularRedirectToGuavaBuilder builder() { - return new BuilderSingularRedirectToGuavaBuilder(); + public static @java.lang.SuppressWarnings("all") BuilderSingularRedirectToGuavaWithSetterPrefixBuilder builder() { + return new BuilderSingularRedirectToGuavaWithSetterPrefixBuilder(); } } diff --git a/test/transform/resource/after-ecj/BuilderSingularSetsWithSetterPrefix.java b/test/transform/resource/after-ecj/BuilderSingularSetsWithSetterPrefix.java index 1bf552c5..cb5041a7 100644 --- a/test/transform/resource/after-ecj/BuilderSingularSetsWithSetterPrefix.java +++ b/test/transform/resource/after-ecj/BuilderSingularSetsWithSetterPrefix.java @@ -1,84 +1,84 @@ import java.util.Set; import java.util.SortedSet; import lombok.Singular; -@lombok.Builder(setterPrefix = "with") class BuilderSingularSets { - public static @java.lang.SuppressWarnings("all") class BuilderSingularSetsBuilder { +@lombok.Builder(setterPrefix = "with") class BuilderSingularSetsWithSetterPrefix { + public static @java.lang.SuppressWarnings("all") class BuilderSingularSetsWithSetterPrefixBuilder { private @java.lang.SuppressWarnings("all") java.util.ArrayList dangerMice; private @java.lang.SuppressWarnings("all") java.util.ArrayList octopodes; private @java.lang.SuppressWarnings("all") java.util.ArrayList rawSet; private @java.lang.SuppressWarnings("all") java.util.ArrayList stringSet; - @java.lang.SuppressWarnings("all") BuilderSingularSetsBuilder() { + @java.lang.SuppressWarnings("all") BuilderSingularSetsWithSetterPrefixBuilder() { super(); } - public @java.lang.SuppressWarnings("all") BuilderSingularSetsBuilder dangerMouse(final T dangerMouse) { + public @java.lang.SuppressWarnings("all") BuilderSingularSetsWithSetterPrefixBuilder dangerMouse(final T dangerMouse) { if ((this.dangerMice == null)) this.dangerMice = new java.util.ArrayList(); this.dangerMice.add(dangerMouse); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularSetsBuilder dangerMice(final java.util.Collection dangerMice) { + public @java.lang.SuppressWarnings("all") BuilderSingularSetsWithSetterPrefixBuilder dangerMice(final java.util.Collection dangerMice) { if ((this.dangerMice == null)) this.dangerMice = new java.util.ArrayList(); this.dangerMice.addAll(dangerMice); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularSetsBuilder clearDangerMice() { + public @java.lang.SuppressWarnings("all") BuilderSingularSetsWithSetterPrefixBuilder clearDangerMice() { if ((this.dangerMice != null)) this.dangerMice.clear(); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularSetsBuilder octopus(final Number octopus) { + public @java.lang.SuppressWarnings("all") BuilderSingularSetsWithSetterPrefixBuilder octopus(final Number octopus) { if ((this.octopodes == null)) this.octopodes = new java.util.ArrayList(); this.octopodes.add(octopus); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularSetsBuilder octopodes(final java.util.Collection octopodes) { + public @java.lang.SuppressWarnings("all") BuilderSingularSetsWithSetterPrefixBuilder octopodes(final java.util.Collection octopodes) { if ((this.octopodes == null)) this.octopodes = new java.util.ArrayList(); this.octopodes.addAll(octopodes); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularSetsBuilder clearOctopodes() { + public @java.lang.SuppressWarnings("all") BuilderSingularSetsWithSetterPrefixBuilder clearOctopodes() { if ((this.octopodes != null)) this.octopodes.clear(); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularSetsBuilder rawSet(final java.lang.Object rawSet) { + public @java.lang.SuppressWarnings("all") BuilderSingularSetsWithSetterPrefixBuilder rawSet(final java.lang.Object rawSet) { if ((this.rawSet == null)) this.rawSet = new java.util.ArrayList(); this.rawSet.add(rawSet); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularSetsBuilder rawSet(final java.util.Collection rawSet) { + public @java.lang.SuppressWarnings("all") BuilderSingularSetsWithSetterPrefixBuilder rawSet(final java.util.Collection rawSet) { if ((this.rawSet == null)) this.rawSet = new java.util.ArrayList(); this.rawSet.addAll(rawSet); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularSetsBuilder clearRawSet() { + public @java.lang.SuppressWarnings("all") BuilderSingularSetsWithSetterPrefixBuilder clearRawSet() { if ((this.rawSet != null)) this.rawSet.clear(); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularSetsBuilder stringSet(final String stringSet) { + public @java.lang.SuppressWarnings("all") BuilderSingularSetsWithSetterPrefixBuilder stringSet(final String stringSet) { if ((this.stringSet == null)) this.stringSet = new java.util.ArrayList(); this.stringSet.add(stringSet); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularSetsBuilder stringSet(final java.util.Collection stringSet) { + public @java.lang.SuppressWarnings("all") BuilderSingularSetsWithSetterPrefixBuilder stringSet(final java.util.Collection stringSet) { if ((this.stringSet == null)) this.stringSet = new java.util.ArrayList(); this.stringSet.addAll(stringSet); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularSetsBuilder clearStringSet() { + public @java.lang.SuppressWarnings("all") BuilderSingularSetsWithSetterPrefixBuilder clearStringSet() { if ((this.stringSet != null)) this.stringSet.clear(); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularSets build() { + public @java.lang.SuppressWarnings("all") BuilderSingularSetsWithSetterPrefix build() { java.util.Set dangerMice; switch (((this.dangerMice == null) ? 0 : this.dangerMice.size())) { case 0 : @@ -122,24 +122,24 @@ import lombok.Singular; stringSet.addAll(this.stringSet); stringSet = java.util.Collections.unmodifiableSet(stringSet); } - return new BuilderSingularSets(dangerMice, octopodes, rawSet, stringSet); + return new BuilderSingularSetsWithSetterPrefix(dangerMice, octopodes, rawSet, stringSet); } public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { - return (((((((("BuilderSingularSets.BuilderSingularSetsBuilder(dangerMice=" + this.dangerMice) + ", octopodes=") + this.octopodes) + ", rawSet=") + this.rawSet) + ", stringSet=") + this.stringSet) + ")"); + return (((((((("BuilderSingularSetsWithSetterPrefix.BuilderSingularSetsWithSetterPrefixBuilder(dangerMice=" + this.dangerMice) + ", octopodes=") + this.octopodes) + ", rawSet=") + this.rawSet) + ", stringSet=") + this.stringSet) + ")"); } } private @Singular Set dangerMice; private @Singular SortedSet octopodes; private @SuppressWarnings("all") @Singular("rawSet") Set rawSet; private @Singular("stringSet") Set stringSet; - @java.lang.SuppressWarnings("all") BuilderSingularSets(final Set dangerMice, final SortedSet octopodes, final Set rawSet, final Set stringSet) { + @java.lang.SuppressWarnings("all") BuilderSingularSetsWithSetterPrefix(final Set dangerMice, final SortedSet octopodes, final Set rawSet, final Set stringSet) { super(); this.dangerMice = dangerMice; this.octopodes = octopodes; this.rawSet = rawSet; this.stringSet = stringSet; } - public static @java.lang.SuppressWarnings("all") BuilderSingularSetsBuilder builder() { - return new BuilderSingularSetsBuilder(); + public static @java.lang.SuppressWarnings("all") BuilderSingularSetsWithSetterPrefixBuilder builder() { + return new BuilderSingularSetsWithSetterPrefixBuilder(); } } diff --git a/test/transform/resource/after-ecj/BuilderSingularToBuilderWithNullWithSetterPrefix.java b/test/transform/resource/after-ecj/BuilderSingularToBuilderWithNullWithSetterPrefix.java index 086e0701..03f8adf9 100644 --- a/test/transform/resource/after-ecj/BuilderSingularToBuilderWithNullWithSetterPrefix.java +++ b/test/transform/resource/after-ecj/BuilderSingularToBuilderWithNullWithSetterPrefix.java @@ -1,28 +1,28 @@ import lombok.Singular; -@lombok.Builder(toBuilder = true, setterPrefix = "with") class BuilderSingularToBuilderWithNull { - public static @java.lang.SuppressWarnings("all") class BuilderSingularToBuilderWithNullBuilder { +@lombok.Builder(toBuilder = true, setterPrefix = "with") class BuilderSingularToBuilderWithNullWithSetterPrefix { + public static @java.lang.SuppressWarnings("all") class BuilderSingularToBuilderWithNullWithSetterPrefixBuilder { private @java.lang.SuppressWarnings("all") java.util.ArrayList elems; - @java.lang.SuppressWarnings("all") BuilderSingularToBuilderWithNullBuilder() { + @java.lang.SuppressWarnings("all") BuilderSingularToBuilderWithNullWithSetterPrefixBuilder() { super(); } - public @java.lang.SuppressWarnings("all") BuilderSingularToBuilderWithNullBuilder withElem(final String elem) { + public @java.lang.SuppressWarnings("all") BuilderSingularToBuilderWithNullWithSetterPrefixBuilder withElem(final String elem) { if ((this.elems == null)) this.elems = new java.util.ArrayList(); this.elems.add(elem); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularToBuilderWithNullBuilder withElems(final java.util.Collection elems) { + public @java.lang.SuppressWarnings("all") BuilderSingularToBuilderWithNullWithSetterPrefixBuilder withElems(final java.util.Collection elems) { if ((this.elems == null)) this.elems = new java.util.ArrayList(); this.elems.addAll(elems); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularToBuilderWithNullBuilder clearElems() { + public @java.lang.SuppressWarnings("all") BuilderSingularToBuilderWithNullWithSetterPrefixBuilder clearElems() { if ((this.elems != null)) this.elems.clear(); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularToBuilderWithNull build() { + public @java.lang.SuppressWarnings("all") BuilderSingularToBuilderWithNullWithSetterPrefix build() { java.util.List elems; switch (((this.elems == null) ? 0 : this.elems.size())) { case 0 : @@ -34,25 +34,25 @@ import lombok.Singular; default : elems = java.util.Collections.unmodifiableList(new java.util.ArrayList(this.elems)); } - return new BuilderSingularToBuilderWithNull(elems); + return new BuilderSingularToBuilderWithNullWithSetterPrefix(elems); } public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { - return (("BuilderSingularToBuilderWithNull.BuilderSingularToBuilderWithNullBuilder(elems=" + this.elems) + ")"); + return (("BuilderSingularToBuilderWithNullWithSetterPrefix.BuilderSingularToBuilderWithNullWithSetterPrefixBuilder(elems=" + this.elems) + ")"); } } private @Singular java.util.List elems; public static void test() { - new BuilderSingularToBuilderWithNull(null).toBuilder(); + new BuilderSingularToBuilderWithNullWithSetterPrefix(null).toBuilder(); } - @java.lang.SuppressWarnings("all") BuilderSingularToBuilderWithNull(final java.util.List elems) { + @java.lang.SuppressWarnings("all") BuilderSingularToBuilderWithNullWithSetterPrefix(final java.util.List elems) { super(); this.elems = elems; } - public static @java.lang.SuppressWarnings("all") BuilderSingularToBuilderWithNullBuilder builder() { - return new BuilderSingularToBuilderWithNullBuilder(); + public static @java.lang.SuppressWarnings("all") BuilderSingularToBuilderWithNullWithSetterPrefixBuilder builder() { + return new BuilderSingularToBuilderWithNullWithSetterPrefixBuilder(); } - public @java.lang.SuppressWarnings("all") BuilderSingularToBuilderWithNullBuilder toBuilder() { - final BuilderSingularToBuilderWithNullBuilder builder = new BuilderSingularToBuilderWithNullBuilder(); + public @java.lang.SuppressWarnings("all") BuilderSingularToBuilderWithNullWithSetterPrefixBuilder toBuilder() { + final BuilderSingularToBuilderWithNullWithSetterPrefixBuilder builder = new BuilderSingularToBuilderWithNullWithSetterPrefixBuilder(); if ((this.elems != null)) builder.elems(this.elems); return builder; diff --git a/test/transform/resource/after-ecj/BuilderSingularWildcardListsWithToBuilderWithSetterPrefix.java b/test/transform/resource/after-ecj/BuilderSingularWildcardListsWithToBuilderWithSetterPrefix.java index 635b6a79..358e6910 100644 --- a/test/transform/resource/after-ecj/BuilderSingularWildcardListsWithToBuilderWithSetterPrefix.java +++ b/test/transform/resource/after-ecj/BuilderSingularWildcardListsWithToBuilderWithSetterPrefix.java @@ -1,48 +1,48 @@ import java.util.List; import java.util.Collection; import lombok.Singular; -@lombok.Builder(toBuilder = true, setterPrefix = "with") class BuilderSingularWildcardListsWithToBuilder { - public static @java.lang.SuppressWarnings("all") class BuilderSingularWildcardListsWithToBuilderBuilder { +@lombok.Builder(toBuilder = true, setterPrefix = "with") class BuilderSingularWildcardListsWithToBuilderWithSetterPrefix { + public static @java.lang.SuppressWarnings("all") class BuilderSingularWildcardListsWithToBuilderWithSetterPrefixBuilder { private @java.lang.SuppressWarnings("all") java.util.ArrayList objects; private @java.lang.SuppressWarnings("all") java.util.ArrayList numbers; - @java.lang.SuppressWarnings("all") BuilderSingularWildcardListsWithToBuilderBuilder() { + @java.lang.SuppressWarnings("all") BuilderSingularWildcardListsWithToBuilderWithSetterPrefixBuilder() { super(); } - public @java.lang.SuppressWarnings("all") BuilderSingularWildcardListsWithToBuilderBuilder withObject(final java.lang.Object object) { + public @java.lang.SuppressWarnings("all") BuilderSingularWildcardListsWithToBuilderWithSetterPrefixBuilder withObject(final java.lang.Object object) { if ((this.objects == null)) this.objects = new java.util.ArrayList(); this.objects.add(object); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularWildcardListsWithToBuilderBuilder withObjects(final java.util.Collection objects) { + public @java.lang.SuppressWarnings("all") BuilderSingularWildcardListsWithToBuilderWithSetterPrefixBuilder withObjects(final java.util.Collection objects) { if ((this.objects == null)) this.objects = new java.util.ArrayList(); this.objects.addAll(objects); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularWildcardListsWithToBuilderBuilder clearObjects() { + public @java.lang.SuppressWarnings("all") BuilderSingularWildcardListsWithToBuilderWithSetterPrefixBuilder clearObjects() { if ((this.objects != null)) this.objects.clear(); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularWildcardListsWithToBuilderBuilder withNumber(final Number number) { + public @java.lang.SuppressWarnings("all") BuilderSingularWildcardListsWithToBuilderWithSetterPrefixBuilder withNumber(final Number number) { if ((this.numbers == null)) this.numbers = new java.util.ArrayList(); this.numbers.add(number); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularWildcardListsWithToBuilderBuilder withNumbers(final java.util.Collection numbers) { + public @java.lang.SuppressWarnings("all") BuilderSingularWildcardListsWithToBuilderWithSetterPrefixBuilder withNumbers(final java.util.Collection numbers) { if ((this.numbers == null)) this.numbers = new java.util.ArrayList(); this.numbers.addAll(numbers); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularWildcardListsWithToBuilderBuilder clearNumbers() { + public @java.lang.SuppressWarnings("all") BuilderSingularWildcardListsWithToBuilderWithSetterPrefixBuilder clearNumbers() { if ((this.numbers != null)) this.numbers.clear(); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularWildcardListsWithToBuilder build() { + public @java.lang.SuppressWarnings("all") BuilderSingularWildcardListsWithToBuilderWithSetterPrefix build() { java.util.List objects; switch (((this.objects == null) ? 0 : this.objects.size())) { case 0 : @@ -65,24 +65,24 @@ import lombok.Singular; default : numbers = java.util.Collections.unmodifiableList(new java.util.ArrayList(this.numbers)); } - return new BuilderSingularWildcardListsWithToBuilder(objects, numbers); + return new BuilderSingularWildcardListsWithToBuilderWithSetterPrefix(objects, numbers); } public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { - return (((("BuilderSingularWildcardListsWithToBuilder.BuilderSingularWildcardListsWithToBuilderBuilder(objects=" + this.objects) + ", numbers=") + this.numbers) + ")"); + return (((("BuilderSingularWildcardListsWithToBuilderWithSetterPrefix.BuilderSingularWildcardListsWithToBuilderWithSetterPrefixBuilder(objects=" + this.objects) + ", numbers=") + this.numbers) + ")"); } } private @Singular List objects; private @Singular Collection numbers; - @java.lang.SuppressWarnings("all") BuilderSingularWildcardListsWithToBuilder(final List objects, final Collection numbers) { + @java.lang.SuppressWarnings("all") BuilderSingularWildcardListsWithToBuilderWithSetterPrefix(final List objects, final Collection numbers) { super(); this.objects = objects; this.numbers = numbers; } - public static @java.lang.SuppressWarnings("all") BuilderSingularWildcardListsWithToBuilderBuilder builder() { - return new BuilderSingularWildcardListsWithToBuilderBuilder(); + public static @java.lang.SuppressWarnings("all") BuilderSingularWildcardListsWithToBuilderWithSetterPrefixBuilder builder() { + return new BuilderSingularWildcardListsWithToBuilderWithSetterPrefixBuilder(); } - public @java.lang.SuppressWarnings("all") BuilderSingularWildcardListsWithToBuilderBuilder toBuilder() { - final BuilderSingularWildcardListsWithToBuilderBuilder builder = new BuilderSingularWildcardListsWithToBuilderBuilder(); + public @java.lang.SuppressWarnings("all") BuilderSingularWildcardListsWithToBuilderWithSetterPrefixBuilder toBuilder() { + final BuilderSingularWildcardListsWithToBuilderWithSetterPrefixBuilder builder = new BuilderSingularWildcardListsWithToBuilderWithSetterPrefixBuilder(); if ((this.objects != null)) builder.objects(this.objects); if ((this.numbers != null)) diff --git a/test/transform/resource/after-ecj/BuilderSingularWithPrefixesWithSetterPrefix.java b/test/transform/resource/after-ecj/BuilderSingularWithPrefixesWithSetterPrefix.java index d9cea692..88f64f34 100644 --- a/test/transform/resource/after-ecj/BuilderSingularWithPrefixesWithSetterPrefix.java +++ b/test/transform/resource/after-ecj/BuilderSingularWithPrefixesWithSetterPrefix.java @@ -1,28 +1,28 @@ import lombok.Singular; -@lombok.Builder(setterPrefix = "with") @lombok.experimental.Accessors(prefix = "_") class BuilderSingularWithPrefixes { - public static @java.lang.SuppressWarnings("all") class BuilderSingularWithPrefixesBuilder { +@lombok.Builder(setterPrefix = "with") @lombok.experimental.Accessors(prefix = "_") class BuilderSingularWithPrefixesWithSetterPrefixes { + public static @java.lang.SuppressWarnings("all") class BuilderSingularWithPrefixesWithSetterPrefixesBuilder { private @java.lang.SuppressWarnings("all") java.util.ArrayList elems; - @java.lang.SuppressWarnings("all") BuilderSingularWithPrefixesBuilder() { + @java.lang.SuppressWarnings("all") BuilderSingularWithPrefixesWithSetterPrefixesBuilder() { super(); } - public @java.lang.SuppressWarnings("all") BuilderSingularWithPrefixesBuilder withElem(final String elem) { + public @java.lang.SuppressWarnings("all") BuilderSingularWithPrefixesWithSetterPrefixesBuilder withElem(final String elem) { if ((this.elems == null)) this.elems = new java.util.ArrayList(); this.elems.add(elem); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularWithPrefixesBuilder withElems(final java.util.Collection elems) { + public @java.lang.SuppressWarnings("all") BuilderSingularWithPrefixesWithSetterPrefixesBuilder withElems(final java.util.Collection elems) { if ((this.elems == null)) this.elems = new java.util.ArrayList(); this.elems.addAll(elems); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularWithPrefixesBuilder clearElems() { + public @java.lang.SuppressWarnings("all") BuilderSingularWithPrefixesWithSetterPrefixesBuilder clearElems() { if ((this.elems != null)) this.elems.clear(); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularWithPrefixes build() { + public @java.lang.SuppressWarnings("all") BuilderSingularWithPrefixesWithSetterPrefixes build() { java.util.List elems; switch (((this.elems == null) ? 0 : this.elems.size())) { case 0 : @@ -34,18 +34,18 @@ import lombok.Singular; default : elems = java.util.Collections.unmodifiableList(new java.util.ArrayList(this.elems)); } - return new BuilderSingularWithPrefixes(elems); + return new BuilderSingularWithPrefixesWithSetterPrefixes(elems); } public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { - return (("BuilderSingularWithPrefixes.BuilderSingularWithPrefixesBuilder(elems=" + this.elems) + ")"); + return (("BuilderSingularWithPrefixesWithSetterPrefixes.BuilderSingularWithPrefixesWithSetterPrefixesBuilder(elems=" + this.elems) + ")"); } } private @Singular java.util.List _elems; - @java.lang.SuppressWarnings("all") BuilderSingularWithPrefixes(final java.util.List elems) { + @java.lang.SuppressWarnings("all") BuilderSingularWithPrefixesWithSetterPrefixes(final java.util.List elems) { super(); this._elems = elems; } - public static @java.lang.SuppressWarnings("all") BuilderSingularWithPrefixesBuilder builder() { - return new BuilderSingularWithPrefixesBuilder(); + public static @java.lang.SuppressWarnings("all") BuilderSingularWithPrefixesWithSetterPrefixesBuilder builder() { + return new BuilderSingularWithPrefixesWithSetterPrefixesBuilder(); } } diff --git a/test/transform/resource/after-ecj/BuilderTypeAnnosWithSetterPrefix.java b/test/transform/resource/after-ecj/BuilderTypeAnnosWithSetterPrefix.java index ed62dc85..db44aa12 100644 --- a/test/transform/resource/after-ecj/BuilderTypeAnnosWithSetterPrefix.java +++ b/test/transform/resource/after-ecj/BuilderTypeAnnosWithSetterPrefix.java @@ -5,29 +5,29 @@ import java.util.List; } @Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER}) @interface TB { } -@lombok.Builder(setterPrefix = "with") class BuilderTypeAnnos { - public static @java.lang.SuppressWarnings("all") class BuilderTypeAnnosBuilder { +@lombok.Builder(setterPrefix = "with") class BuilderTypeAnnosWithSetterPrefix { + public static @java.lang.SuppressWarnings("all") class BuilderTypeAnnosWithSetterPrefixBuilder { private @java.lang.SuppressWarnings("all") List foo; - @java.lang.SuppressWarnings("all") BuilderTypeAnnosBuilder() { + @java.lang.SuppressWarnings("all") BuilderTypeAnnosWithSetterPrefixBuilder() { super(); } - public @java.lang.SuppressWarnings("all") BuilderTypeAnnosBuilder withFoo(final @TA List foo) { + public @java.lang.SuppressWarnings("all") BuilderTypeAnnosWithSetterPrefixBuilder withFoo(final @TA List foo) { this.foo = foo; return this; } - public @java.lang.SuppressWarnings("all") BuilderTypeAnnos build() { - return new BuilderTypeAnnos(foo); + public @java.lang.SuppressWarnings("all") BuilderTypeAnnosWithSetterPrefix build() { + return new BuilderTypeAnnosWithSetterPrefix(foo); } public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { - return (("BuilderTypeAnnos.BuilderTypeAnnosBuilder(foo=" + this.foo) + ")"); + return (("BuilderTypeAnnosWithSetterPrefix.BuilderTypeAnnosWithSetterPrefixBuilder(foo=" + this.foo) + ")"); } } private @TA @TB List foo; - @java.lang.SuppressWarnings("all") BuilderTypeAnnos(final @TA List foo) { + @java.lang.SuppressWarnings("all") BuilderTypeAnnosWithSetterPrefix(final @TA List foo) { super(); this.foo = foo; } - public static @java.lang.SuppressWarnings("all") BuilderTypeAnnosBuilder builder() { - return new BuilderTypeAnnosBuilder(); + public static @java.lang.SuppressWarnings("all") BuilderTypeAnnosWithSetterPrefixBuilder builder() { + return new BuilderTypeAnnosWithSetterPrefixBuilder(); } } diff --git a/test/transform/resource/after-ecj/BuilderValueDataWithSetterPrefix.java b/test/transform/resource/after-ecj/BuilderValueDataWithSetterPrefix.java index ffecad46..679591a4 100644 --- a/test/transform/resource/after-ecj/BuilderValueDataWithSetterPrefix.java +++ b/test/transform/resource/after-ecj/BuilderValueDataWithSetterPrefix.java @@ -1,22 +1,22 @@ import java.util.List; -final @lombok.Builder(setterPrefix = "with") @lombok.Value class BuilderAndValue { - public static @java.lang.SuppressWarnings("all") class BuilderAndValueBuilder { - @java.lang.SuppressWarnings("all") BuilderAndValueBuilder() { +final @lombok.Builder(setterPrefix = "with") @lombok.Value class BuilderAndValueWithSetterPrefix { + public static @java.lang.SuppressWarnings("all") class BuilderAndValueWithSetterPrefixBuilder { + @java.lang.SuppressWarnings("all") BuilderAndValueWithSetterPrefixBuilder() { super(); } - public @java.lang.SuppressWarnings("all") BuilderAndValue build() { - return new BuilderAndValue(); + public @java.lang.SuppressWarnings("all") BuilderAndValueWithSetterPrefix build() { + return new BuilderAndValueWithSetterPrefix(); } public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { - return "BuilderAndValue.BuilderAndValueBuilder()"; + return "BuilderAndValueWithSetterPrefix.BuilderAndValueWithSetterPrefixBuilder()"; } } private final int zero = 0; - @java.lang.SuppressWarnings("all") BuilderAndValue() { + @java.lang.SuppressWarnings("all") BuilderAndValueWithSetterPrefix() { super(); } - public static @java.lang.SuppressWarnings("all") BuilderAndValueBuilder builder() { - return new BuilderAndValueBuilder(); + public static @java.lang.SuppressWarnings("all") BuilderAndValueWithSetterPrefixBuilder builder() { + return new BuilderAndValueWithSetterPrefixBuilder(); } public @java.lang.SuppressWarnings("all") int getZero() { return this.zero; @@ -24,9 +24,9 @@ final @lombok.Builder(setterPrefix = "with") @lombok.Value class BuilderAndValue public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) { if ((o == this)) return true; - if ((! (o instanceof BuilderAndValue))) + if ((! (o instanceof BuilderAndValueWithSetterPrefix))) return false; - final BuilderAndValue other = (BuilderAndValue) o; + final BuilderAndValueWithSetterPrefix other = (BuilderAndValueWithSetterPrefix) o; if ((this.getZero() != other.getZero())) return false; return true; @@ -38,27 +38,27 @@ final @lombok.Builder(setterPrefix = "with") @lombok.Value class BuilderAndValue return result; } public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { - return (("BuilderAndValue(zero=" + this.getZero()) + ")"); + return (("BuilderAndValueWithSetterPrefix(zero=" + this.getZero()) + ")"); } } -@lombok.Builder @lombok.Data class BuilderAndData { - public static @java.lang.SuppressWarnings("all") class BuilderAndDataBuilder { - @java.lang.SuppressWarnings("all") BuilderAndDataBuilder() { +@lombok.Builder @lombok.Data class BuilderAndDataWithSetterPrefix { + public static @java.lang.SuppressWarnings("all") class BuilderAndDataWithSetterPrefixBuilder { + @java.lang.SuppressWarnings("all") BuilderAndDataWithSetterPrefixBuilder() { super(); } - public @java.lang.SuppressWarnings("all") BuilderAndData build() { - return new BuilderAndData(); + public @java.lang.SuppressWarnings("all") BuilderAndDataWithSetterPrefix build() { + return new BuilderAndDataWithSetterPrefix(); } public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { - return "BuilderAndData.BuilderAndDataBuilder()"; + return "BuilderAndDataWithSetterPrefix.BuilderAndDataWithSetterPrefixBuilder()"; } } private final int zero = 0; - @java.lang.SuppressWarnings("all") BuilderAndData() { + @java.lang.SuppressWarnings("all") BuilderAndDataWithSetterPrefix() { super(); } - public static @java.lang.SuppressWarnings("all") BuilderAndDataBuilder builder() { - return new BuilderAndDataBuilder(); + public static @java.lang.SuppressWarnings("all") BuilderAndDataWithSetterPrefixBuilder builder() { + return new BuilderAndDataWithSetterPrefixBuilder(); } public @java.lang.SuppressWarnings("all") int getZero() { return this.zero; @@ -66,9 +66,9 @@ final @lombok.Builder(setterPrefix = "with") @lombok.Value class BuilderAndValue public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) { if ((o == this)) return true; - if ((! (o instanceof BuilderAndData))) + if ((! (o instanceof BuilderAndDataWithSetterPrefix))) return false; - final BuilderAndData other = (BuilderAndData) o; + final BuilderAndDataWithSetterPrefix other = (BuilderAndDataWithSetterPrefix) o; if ((! other.canEqual((java.lang.Object) this))) return false; if ((this.getZero() != other.getZero())) @@ -76,7 +76,7 @@ final @lombok.Builder(setterPrefix = "with") @lombok.Value class BuilderAndValue return true; } protected @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) { - return (other instanceof BuilderAndData); + return (other instanceof BuilderAndDataWithSetterPrefix); } public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { final int PRIME = 59; @@ -85,6 +85,6 @@ final @lombok.Builder(setterPrefix = "with") @lombok.Value class BuilderAndValue return result; } public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { - return (("BuilderAndData(zero=" + this.getZero()) + ")"); + return (("BuilderAndDataWithSetterPrefix(zero=" + this.getZero()) + ")"); } } diff --git a/test/transform/resource/after-ecj/BuilderWithAccessorsWithSetterPrefix.java b/test/transform/resource/after-ecj/BuilderWithAccessorsWithSetterPrefix.java index 388e813d..5894a4a2 100644 --- a/test/transform/resource/after-ecj/BuilderWithAccessorsWithSetterPrefix.java +++ b/test/transform/resource/after-ecj/BuilderWithAccessorsWithSetterPrefix.java @@ -1,47 +1,47 @@ -@lombok.Builder(setterPrefix = "with") @lombok.experimental.Accessors(prefix = {"p", "_"}) class BuilderWithAccessors { - public static @java.lang.SuppressWarnings("all") class BuilderWithAccessorsBuilder { +@lombok.Builder(setterPrefix = "with") @lombok.experimental.Accessors(prefix = {"p", "_"}) class BuilderWithAccessorsWithSetterPrefix { + public static @java.lang.SuppressWarnings("all") class BuilderWithAccessorsWithSetterPrefixBuilder { private @java.lang.SuppressWarnings("all") int plower; private @java.lang.SuppressWarnings("all") int upper; private @java.lang.SuppressWarnings("all") int foo; private @java.lang.SuppressWarnings("all") int _bar; - @java.lang.SuppressWarnings("all") BuilderWithAccessorsBuilder() { + @java.lang.SuppressWarnings("all") BuilderWithAccessorsWithSetterPrefixBuilder() { super(); } - public @java.lang.SuppressWarnings("all") BuilderWithAccessorsBuilder withPlower(final int plower) { + public @java.lang.SuppressWarnings("all") BuilderWithAccessorsWithSetterPrefixBuilder withPlower(final int plower) { this.plower = plower; return this; } - public @java.lang.SuppressWarnings("all") BuilderWithAccessorsBuilder withUpper(final int upper) { + public @java.lang.SuppressWarnings("all") BuilderWithAccessorsWithSetterPrefixBuilder withUpper(final int upper) { this.upper = upper; return this; } - public @java.lang.SuppressWarnings("all") BuilderWithAccessorsBuilder withFoo(final int foo) { + public @java.lang.SuppressWarnings("all") BuilderWithAccessorsWithSetterPrefixBuilder withFoo(final int foo) { this.foo = foo; return this; } - public @java.lang.SuppressWarnings("all") BuilderWithAccessorsBuilder with_Bar(final int _bar) { + public @java.lang.SuppressWarnings("all") BuilderWithAccessorsWithSetterPrefixBuilder with_Bar(final int _bar) { this._bar = _bar; return this; } - public @java.lang.SuppressWarnings("all") BuilderWithAccessors build() { - return new BuilderWithAccessors(plower, upper, foo, _bar); + public @java.lang.SuppressWarnings("all") BuilderWithAccessorsWithSetterPrefix build() { + return new BuilderWithAccessorsWithSetterPrefix(plower, upper, foo, _bar); } public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { - return (((((((("BuilderWithAccessors.BuilderWithAccessorsBuilder(plower=" + this.plower) + ", upper=") + this.upper) + ", foo=") + this.foo) + ", _bar=") + this._bar) + ")"); + return (((((((("BuilderWithAccessorsWithSetterPrefix.BuilderWithAccessorsWithSetterPrefixBuilder(plower=" + this.plower) + ", upper=") + this.upper) + ", foo=") + this.foo) + ", _bar=") + this._bar) + ")"); } } private final int plower; private final int pUpper; private int _foo; private int __bar; - @java.lang.SuppressWarnings("all") BuilderWithAccessors(final int plower, final int upper, final int foo, final int _bar) { + @java.lang.SuppressWarnings("all") BuilderWithAccessorsWithSetterPrefix(final int plower, final int upper, final int foo, final int _bar) { super(); this.plower = plower; this.pUpper = upper; this._foo = foo; this.__bar = _bar; } - public static @java.lang.SuppressWarnings("all") BuilderWithAccessorsBuilder builder() { - return new BuilderWithAccessorsBuilder(); + public static @java.lang.SuppressWarnings("all") BuilderWithAccessorsWithSetterPrefixBuilder builder() { + return new BuilderWithAccessorsWithSetterPrefixBuilder(); } } diff --git a/test/transform/resource/after-ecj/BuilderWithBadNamesWithSetterPrefix.java b/test/transform/resource/after-ecj/BuilderWithBadNamesWithSetterPrefix.java index 465517f7..248c77ad 100644 --- a/test/transform/resource/after-ecj/BuilderWithBadNamesWithSetterPrefix.java +++ b/test/transform/resource/after-ecj/BuilderWithBadNamesWithSetterPrefix.java @@ -1,33 +1,33 @@ -public @lombok.Builder(setterPrefix = "with") class BuilderWithBadNames { - public static @java.lang.SuppressWarnings("all") class BuilderWithBadNamesBuilder { +public @lombok.Builder(setterPrefix = "with") class BuilderWithBadNamesWithSetterPrefix { + public static @java.lang.SuppressWarnings("all") class BuilderWithBadNamesWithSetterPrefixBuilder { private @java.lang.SuppressWarnings("all") String build; private @java.lang.SuppressWarnings("all") String toString; - @java.lang.SuppressWarnings("all") BuilderWithBadNamesBuilder() { + @java.lang.SuppressWarnings("all") BuilderWithBadNamesWithSetterPrefixBuilder() { super(); } - public @java.lang.SuppressWarnings("all") BuilderWithBadNamesBuilder withBuild(final String build) { + public @java.lang.SuppressWarnings("all") BuilderWithBadNamesWithSetterPrefixBuilder withBuild(final String build) { this.build = build; return this; } - public @java.lang.SuppressWarnings("all") BuilderWithBadNamesBuilder withToString(final String toString) { + public @java.lang.SuppressWarnings("all") BuilderWithBadNamesWithSetterPrefixBuilder withToString(final String toString) { this.toString = toString; return this; } - public @java.lang.SuppressWarnings("all") BuilderWithBadNames build() { - return new BuilderWithBadNames(build, toString); + public @java.lang.SuppressWarnings("all") BuilderWithBadNamesWithSetterPrefix build() { + return new BuilderWithBadNamesWithSetterPrefix(build, toString); } public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { - return (((("BuilderWithBadNames.BuilderWithBadNamesBuilder(build=" + this.build) + ", toString=") + this.toString) + ")"); + return (((("BuilderWithBadNamesWithSetterPrefix.BuilderWithBadNamesWithSetterPrefixBuilder(build=" + this.build) + ", toString=") + this.toString) + ")"); } } String build; String toString; - @java.lang.SuppressWarnings("all") BuilderWithBadNames(final String build, final String toString) { + @java.lang.SuppressWarnings("all") BuilderWithBadNamesWithSetterPrefix(final String build, final String toString) { super(); this.build = build; this.toString = toString; } - public static @java.lang.SuppressWarnings("all") BuilderWithBadNamesBuilder builder() { - return new BuilderWithBadNamesBuilder(); + public static @java.lang.SuppressWarnings("all") BuilderWithBadNamesWithSetterPrefixBuilder builder() { + return new BuilderWithBadNamesWithSetterPrefixBuilder(); } } diff --git a/test/transform/resource/after-ecj/BuilderWithDeprecatedWithSetterPrefix.java b/test/transform/resource/after-ecj/BuilderWithDeprecatedWithSetterPrefix.java index 0d8e023f..83fa2e4e 100644 --- a/test/transform/resource/after-ecj/BuilderWithDeprecatedWithSetterPrefix.java +++ b/test/transform/resource/after-ecj/BuilderWithDeprecatedWithSetterPrefix.java @@ -1,57 +1,57 @@ import com.google.common.collect.ImmutableList; import lombok.Builder; import lombok.Singular; -public @Builder(setterPrefix = "with") class BuilderWithDeprecated { - public static @java.lang.SuppressWarnings("all") class BuilderWithDeprecatedBuilder { +public @Builder(setterPrefix = "with") class BuilderWithDeprecatedWithSetterPrefix { + public static @java.lang.SuppressWarnings("all") class BuilderWithDeprecatedWithSetterPrefixBuilder { private @java.lang.SuppressWarnings("all") String dep1; private @java.lang.SuppressWarnings("all") int dep2; private @java.lang.SuppressWarnings("all") java.util.ArrayList strings; private @java.lang.SuppressWarnings("all") com.google.common.collect.ImmutableList.Builder numbers; - @java.lang.SuppressWarnings("all") BuilderWithDeprecatedBuilder() { + @java.lang.SuppressWarnings("all") BuilderWithDeprecatedWithSetterPrefixBuilder() { super(); } - public @java.lang.Deprecated @java.lang.SuppressWarnings("all") BuilderWithDeprecatedBuilder withDep1(final String dep1) { + public @java.lang.Deprecated @java.lang.SuppressWarnings("all") BuilderWithDeprecatedWithSetterPrefixBuilder withDep1(final String dep1) { this.dep1 = dep1; return this; } - public @java.lang.Deprecated @java.lang.SuppressWarnings("all") BuilderWithDeprecatedBuilder withDep2(final int dep2) { + public @java.lang.Deprecated @java.lang.SuppressWarnings("all") BuilderWithDeprecatedWithSetterPrefixBuilder withDep2(final int dep2) { this.dep2 = dep2; return this; } - public @java.lang.Deprecated @java.lang.SuppressWarnings("all") BuilderWithDeprecatedBuilder withString(final String string) { + public @java.lang.Deprecated @java.lang.SuppressWarnings("all") BuilderWithDeprecatedWithSetterPrefixBuilder withString(final String string) { if ((this.strings == null)) this.strings = new java.util.ArrayList(); this.strings.add(string); return this; } - public @java.lang.Deprecated @java.lang.SuppressWarnings("all") BuilderWithDeprecatedBuilder withStrings(final java.util.Collection strings) { + public @java.lang.Deprecated @java.lang.SuppressWarnings("all") BuilderWithDeprecatedWithSetterPrefixBuilder withStrings(final java.util.Collection strings) { if ((this.strings == null)) this.strings = new java.util.ArrayList(); this.strings.addAll(strings); return this; } - public @java.lang.Deprecated @java.lang.SuppressWarnings("all") BuilderWithDeprecatedBuilder clearStrings() { + public @java.lang.Deprecated @java.lang.SuppressWarnings("all") BuilderWithDeprecatedWithSetterPrefixBuilder clearStrings() { if ((this.strings != null)) this.strings.clear(); return this; } - public @java.lang.Deprecated @java.lang.SuppressWarnings("all") BuilderWithDeprecatedBuilder withNumber(final Integer number) { + public @java.lang.Deprecated @java.lang.SuppressWarnings("all") BuilderWithDeprecatedWithSetterPrefixBuilder withNumber(final Integer number) { if ((this.numbers == null)) this.numbers = com.google.common.collect.ImmutableList.builder(); this.numbers.add(number); return this; } - public @java.lang.Deprecated @java.lang.SuppressWarnings("all") BuilderWithDeprecatedBuilder withNumbers(final java.lang.Iterable numbers) { + public @java.lang.Deprecated @java.lang.SuppressWarnings("all") BuilderWithDeprecatedWithSetterPrefixBuilder withNumbers(final java.lang.Iterable numbers) { if ((this.numbers == null)) this.numbers = com.google.common.collect.ImmutableList.builder(); this.numbers.addAll(numbers); return this; } - public @java.lang.Deprecated @java.lang.SuppressWarnings("all") BuilderWithDeprecatedBuilder clearNumbers() { + public @java.lang.Deprecated @java.lang.SuppressWarnings("all") BuilderWithDeprecatedWithSetterPrefixBuilder clearNumbers() { this.numbers = null; return this; } - public @java.lang.SuppressWarnings("all") BuilderWithDeprecated build() { + public @java.lang.SuppressWarnings("all") BuilderWithDeprecatedWithSetterPrefix build() { java.util.List strings; switch (((this.strings == null) ? 0 : this.strings.size())) { case 0 : @@ -64,24 +64,24 @@ public @Builder(setterPrefix = "with") class BuilderWithDeprecated { strings = java.util.Collections.unmodifiableList(new java.util.ArrayList(this.strings)); } com.google.common.collect.ImmutableList numbers = ((this.numbers == null) ? com.google.common.collect.ImmutableList.of() : this.numbers.build()); - return new BuilderWithDeprecated(dep1, dep2, strings, numbers); + return new BuilderWithDeprecatedWithSetterPrefix(dep1, dep2, strings, numbers); } public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { - return (((((((("BuilderWithDeprecated.BuilderWithDeprecatedBuilder(dep1=" + this.dep1) + ", dep2=") + this.dep2) + ", strings=") + this.strings) + ", numbers=") + this.numbers) + ")"); + return (((((((("BuilderWithDeprecatedWithSetterPrefix.BuilderWithDeprecatedWithSetterPrefixBuilder(dep1=" + this.dep1) + ", dep2=") + this.dep2) + ", strings=") + this.strings) + ", numbers=") + this.numbers) + ")"); } } String dep1; @Deprecated int dep2; @Singular @Deprecated java.util.List strings; @Singular @Deprecated ImmutableList numbers; - @java.lang.SuppressWarnings("all") BuilderWithDeprecated(final String dep1, final int dep2, final java.util.List strings, final ImmutableList numbers) { + @java.lang.SuppressWarnings("all") BuilderWithDeprecatedWithSetterPrefix(final String dep1, final int dep2, final java.util.List strings, final ImmutableList numbers) { super(); this.dep1 = dep1; this.dep2 = dep2; this.strings = strings; this.numbers = numbers; } - public static @java.lang.SuppressWarnings("all") BuilderWithDeprecatedBuilder builder() { - return new BuilderWithDeprecatedBuilder(); + public static @java.lang.SuppressWarnings("all") BuilderWithDeprecatedWithSetterPrefixBuilder builder() { + return new BuilderWithDeprecatedWithSetterPrefixBuilder(); } } diff --git a/test/transform/resource/after-ecj/BuilderWithExistingBuilderClassWithSetterPrefix.java b/test/transform/resource/after-ecj/BuilderWithExistingBuilderClassWithSetterPrefix.java index 220a8a63..8da2f012 100644 --- a/test/transform/resource/after-ecj/BuilderWithExistingBuilderClassWithSetterPrefix.java +++ b/test/transform/resource/after-ecj/BuilderWithExistingBuilderClassWithSetterPrefix.java @@ -1,36 +1,36 @@ import lombok.Builder; -class BuilderWithExistingBuilderClass { - public static class BuilderWithExistingBuilderClassBuilder { +class BuilderWithExistingBuilderClassWithSetterPrefix { + public static class BuilderWithExistingBuilderClassWithSetterPrefixBuilder { private @java.lang.SuppressWarnings("all") boolean arg2; private @java.lang.SuppressWarnings("all") String arg3; private Z arg1; public void withArg2(boolean arg) { } - @java.lang.SuppressWarnings("all") BuilderWithExistingBuilderClassBuilder() { + @java.lang.SuppressWarnings("all") BuilderWithExistingBuilderClassWithSetterPrefixBuilder() { super(); } - public @java.lang.SuppressWarnings("all") BuilderWithExistingBuilderClassBuilder withArg1(final Z arg1) { + public @java.lang.SuppressWarnings("all") BuilderWithExistingBuilderClassWithSetterPrefixBuilder withArg1(final Z arg1) { this.arg1 = arg1; return this; } - public @java.lang.SuppressWarnings("all") BuilderWithExistingBuilderClassBuilder withArg3(final String arg3) { + public @java.lang.SuppressWarnings("all") BuilderWithExistingBuilderClassWithSetterPrefixBuilder withArg3(final String arg3) { this.arg3 = arg3; return this; } - public @java.lang.SuppressWarnings("all") BuilderWithExistingBuilderClass build() { - return BuilderWithExistingBuilderClass.staticMethod(arg1, arg2, arg3); + public @java.lang.SuppressWarnings("all") BuilderWithExistingBuilderClassWithSetterPrefix build() { + return BuilderWithExistingBuilderClassWithSetterPrefix.staticMethod(arg1, arg2, arg3); } public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { - return (((((("BuilderWithExistingBuilderClass.BuilderWithExistingBuilderClassBuilder(arg1=" + this.arg1) + ", arg2=") + this.arg2) + ", arg3=") + this.arg3) + ")"); + return (((((("BuilderWithExistingBuilderClassWithSetterPrefix.BuilderWithExistingBuilderClassWithSetterPrefixBuilder(arg1=" + this.arg1) + ", arg2=") + this.arg2) + ", arg3=") + this.arg3) + ")"); } } - BuilderWithExistingBuilderClass() { + BuilderWithExistingBuilderClassWithSetterPrefix() { super(); } - public static @Builder(setterPrefix = "with") BuilderWithExistingBuilderClass staticMethod(Z arg1, boolean arg2, String arg3) { + public static @Builder(setterPrefix = "with") BuilderWithExistingBuilderClassWithSetterPrefix staticMethod(Z arg1, boolean arg2, String arg3) { return null; } - public static @java.lang.SuppressWarnings("all") BuilderWithExistingBuilderClassBuilder builder() { - return new BuilderWithExistingBuilderClassBuilder(); + public static @java.lang.SuppressWarnings("all") BuilderWithExistingBuilderClassWithSetterPrefixBuilder builder() { + return new BuilderWithExistingBuilderClassWithSetterPrefixBuilder(); } } diff --git a/test/transform/resource/after-ecj/BuilderWithNoBuilderMethodWithSetterPrefix.java b/test/transform/resource/after-ecj/BuilderWithNoBuilderMethodWithSetterPrefix.java index 0b934767..30043dd9 100644 --- a/test/transform/resource/after-ecj/BuilderWithNoBuilderMethodWithSetterPrefix.java +++ b/test/transform/resource/after-ecj/BuilderWithNoBuilderMethodWithSetterPrefix.java @@ -1,27 +1,27 @@ import lombok.Builder; -@Builder(toBuilder = true,builderMethodName = "",setterPrefix = "with") class BuilderWithNoBuilderMethod { - public static @java.lang.SuppressWarnings("all") class BuilderWithNoBuilderMethodBuilder { +@Builder(toBuilder = true,builderMethodName = "",setterPrefix = "with") class BuilderWithNoBuilderMethodWithSetterPrefix { + public static @java.lang.SuppressWarnings("all") class BuilderWithNoBuilderMethodWithSetterPrefixBuilder { private @java.lang.SuppressWarnings("all") String a; - @java.lang.SuppressWarnings("all") BuilderWithNoBuilderMethodBuilder() { + @java.lang.SuppressWarnings("all") BuilderWithNoBuilderMethodWithSetterPrefixBuilder() { super(); } - public @java.lang.SuppressWarnings("all") BuilderWithNoBuilderMethodBuilder withA(final String a) { + public @java.lang.SuppressWarnings("all") BuilderWithNoBuilderMethodWithSetterPrefixBuilder withA(final String a) { this.a = a; return this; } - public @java.lang.SuppressWarnings("all") BuilderWithNoBuilderMethod build() { - return new BuilderWithNoBuilderMethod(a); + public @java.lang.SuppressWarnings("all") BuilderWithNoBuilderMethodWithSetterPrefix build() { + return new BuilderWithNoBuilderMethodWithSetterPrefix(a); } public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { - return (("BuilderWithNoBuilderMethod.BuilderWithNoBuilderMethodBuilder(a=" + this.a) + ")"); + return (("BuilderWithNoBuilderMethodWithSetterPrefix.BuilderWithNoBuilderMethodWithSetterPrefixBuilder(a=" + this.a) + ")"); } } private String a = ""; - @java.lang.SuppressWarnings("all") BuilderWithNoBuilderMethod(final String a) { + @java.lang.SuppressWarnings("all") BuilderWithNoBuilderMethodWithSetterPrefix(final String a) { super(); this.a = a; } - public @java.lang.SuppressWarnings("all") BuilderWithNoBuilderMethodBuilder toBuilder() { - return new BuilderWithNoBuilderMethodBuilder().withA(this.a); + public @java.lang.SuppressWarnings("all") BuilderWithNoBuilderMethodWithSetterPrefixBuilder toBuilder() { + return new BuilderWithNoBuilderMethodWithSetterPrefixBuilder().withA(this.a); } } diff --git a/test/transform/resource/after-ecj/BuilderWithNonNullWithSetterPrefix.java b/test/transform/resource/after-ecj/BuilderWithNonNullWithSetterPrefix.java index 6379e25f..7f8cb80b 100644 --- a/test/transform/resource/after-ecj/BuilderWithNonNullWithSetterPrefix.java +++ b/test/transform/resource/after-ecj/BuilderWithNonNullWithSetterPrefix.java @@ -1,10 +1,10 @@ -@lombok.Builder(setterPrefix = "with") class BuilderWithNonNull { - public static @java.lang.SuppressWarnings("all") class BuilderWithNonNullBuilder { +@lombok.Builder(setterPrefix = "with") class BuilderWithNonNullWithSetterPrefix { + public static @java.lang.SuppressWarnings("all") class BuilderWithNonNullWithSetterPrefixBuilder { private @java.lang.SuppressWarnings("all") String id; - @java.lang.SuppressWarnings("all") BuilderWithNonNullBuilder() { + @java.lang.SuppressWarnings("all") BuilderWithNonNullWithSetterPrefixBuilder() { super(); } - public @java.lang.SuppressWarnings("all") BuilderWithNonNullBuilder withId(final @lombok.NonNull String id) { + public @java.lang.SuppressWarnings("all") BuilderWithNonNullWithSetterPrefixBuilder withId(final @lombok.NonNull String id) { if ((id == null)) { throw new java.lang.NullPointerException("id is marked non-null but is null"); @@ -12,15 +12,15 @@ this.id = id; return this; } - public @java.lang.SuppressWarnings("all") BuilderWithNonNull build() { - return new BuilderWithNonNull(id); + public @java.lang.SuppressWarnings("all") BuilderWithNonNullWithSetterPrefix build() { + return new BuilderWithNonNullWithSetterPrefix(id); } public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { - return (("BuilderWithNonNull.BuilderWithNonNullBuilder(id=" + this.id) + ")"); + return (("BuilderWithNonNullWithSetterPrefix.BuilderWithNonNullWithSetterPrefixBuilder(id=" + this.id) + ")"); } } private final @lombok.NonNull String id; - @java.lang.SuppressWarnings("all") BuilderWithNonNull(final @lombok.NonNull String id) { + @java.lang.SuppressWarnings("all") BuilderWithNonNullWithSetterPrefix(final @lombok.NonNull String id) { super(); if ((id == null)) { @@ -28,7 +28,7 @@ } this.id = id; } - public static @java.lang.SuppressWarnings("all") BuilderWithNonNullBuilder builder() { - return new BuilderWithNonNullBuilder(); + public static @java.lang.SuppressWarnings("all") BuilderWithNonNullWithSetterPrefixBuilder builder() { + return new BuilderWithNonNullWithSetterPrefixBuilder(); } } diff --git a/test/transform/resource/after-ecj/BuilderWithRecursiveGenericsWithSetterPrefix.java b/test/transform/resource/after-ecj/BuilderWithRecursiveGenericsWithSetterPrefix.java index 32b9c20e..2ce25b0a 100644 --- a/test/transform/resource/after-ecj/BuilderWithRecursiveGenericsWithSetterPrefix.java +++ b/test/transform/resource/after-ecj/BuilderWithRecursiveGenericsWithSetterPrefix.java @@ -1,7 +1,7 @@ import java.util.Set; import lombok.Builder; import lombok.Value; -public class BuilderWithRecursiveGenerics { +public class BuilderWithRecursiveGenericsWithSetterPrefix { interface Inter> { } public static final @Builder(setterPrefix = "with(setterPrefix = "with")") @Value class Test, Quz extends Inter> { @@ -23,7 +23,7 @@ public class BuilderWithRecursiveGenerics { return new Test(foo, bar); } public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { - return (((("BuilderWithRecursiveGenerics.Test.TestBuilder(foo=" + this.foo) + ", bar=") + this.bar) + ")"); + return (((("BuilderWithRecursiveGenericsWithSetterPrefix.Test.TestBuilder(foo=" + this.foo) + ", bar=") + this.bar) + ")"); } } private final Foo foo; @@ -45,9 +45,9 @@ public class BuilderWithRecursiveGenerics { public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) { if ((o == this)) return true; - if ((! (o instanceof BuilderWithRecursiveGenerics.Test))) + if ((! (o instanceof BuilderWithRecursiveGenericsWithSetterPrefix.Test))) return false; - final BuilderWithRecursiveGenerics.Test other = (BuilderWithRecursiveGenerics.Test) o; + final BuilderWithRecursiveGenericsWithSetterPrefix.Test other = (BuilderWithRecursiveGenericsWithSetterPrefix.Test) o; final java.lang.Object this$foo = this.getFoo(); final java.lang.Object other$foo = other.getFoo(); if (((this$foo == null) ? (other$foo != null) : (! this$foo.equals(other$foo)))) @@ -68,10 +68,10 @@ public class BuilderWithRecursiveGenerics { return result; } public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { - return (((("BuilderWithRecursiveGenerics.Test(foo=" + this.getFoo()) + ", bar=") + this.getBar()) + ")"); + return (((("BuilderWithRecursiveGenericsWithSetterPrefix.Test(foo=" + this.getFoo()) + ", bar=") + this.getBar()) + ")"); } } - public BuilderWithRecursiveGenerics() { + public BuilderWithRecursiveGenericsWithSetterPrefix() { super(); } } diff --git a/test/transform/resource/after-ecj/BuilderWithToBuilderWithSetterPrefix.java b/test/transform/resource/after-ecj/BuilderWithToBuilderWithSetterPrefix.java index 85378cab..c33315a4 100644 --- a/test/transform/resource/after-ecj/BuilderWithToBuilderWithSetterPrefix.java +++ b/test/transform/resource/after-ecj/BuilderWithToBuilderWithSetterPrefix.java @@ -1,44 +1,44 @@ import java.util.List; import lombok.Builder; -@Builder(toBuilder = true,setterPrefix = "with") @lombok.experimental.Accessors(prefix = "m") class BuilderWithToBuilder { - public static @java.lang.SuppressWarnings("all") class BuilderWithToBuilderBuilder { +@Builder(toBuilder = true,setterPrefix = "with") @lombok.experimental.Accessors(prefix = "m") class BuilderWithToBuilderWithSetterPrefix { + public static @java.lang.SuppressWarnings("all") class BuilderWithToBuilderWithSetterPrefixBuilder { private @java.lang.SuppressWarnings("all") String one; private @java.lang.SuppressWarnings("all") String two; private @java.lang.SuppressWarnings("all") T foo; private @java.lang.SuppressWarnings("all") java.util.ArrayList bars; - @java.lang.SuppressWarnings("all") BuilderWithToBuilderBuilder() { + @java.lang.SuppressWarnings("all") BuilderWithToBuilderWithSetterPrefixBuilder() { super(); } - public @java.lang.SuppressWarnings("all") BuilderWithToBuilderBuilder withOne(final String one) { + public @java.lang.SuppressWarnings("all") BuilderWithToBuilderWithSetterPrefixBuilder withOne(final String one) { this.one = one; return this; } - public @java.lang.SuppressWarnings("all") BuilderWithToBuilderBuilder withTwo(final String two) { + public @java.lang.SuppressWarnings("all") BuilderWithToBuilderWithSetterPrefixBuilder withTwo(final String two) { this.two = two; return this; } - public @java.lang.SuppressWarnings("all") BuilderWithToBuilderBuilder withFoo(final T foo) { + public @java.lang.SuppressWarnings("all") BuilderWithToBuilderWithSetterPrefixBuilder withFoo(final T foo) { this.foo = foo; return this; } - public @java.lang.SuppressWarnings("all") BuilderWithToBuilderBuilder withBar(final T bar) { + public @java.lang.SuppressWarnings("all") BuilderWithToBuilderWithSetterPrefixBuilder withBar(final T bar) { if ((this.bars == null)) this.bars = new java.util.ArrayList(); this.bars.add(bar); return this; } - public @java.lang.SuppressWarnings("all") BuilderWithToBuilderBuilder withBars(final java.util.Collection bars) { + public @java.lang.SuppressWarnings("all") BuilderWithToBuilderWithSetterPrefixBuilder withBars(final java.util.Collection bars) { if ((this.bars == null)) this.bars = new java.util.ArrayList(); this.bars.addAll(bars); return this; } - public @java.lang.SuppressWarnings("all") BuilderWithToBuilderBuilder clearBars() { + public @java.lang.SuppressWarnings("all") BuilderWithToBuilderWithSetterPrefixBuilder clearBars() { if ((this.bars != null)) this.bars.clear(); return this; } - public @java.lang.SuppressWarnings("all") BuilderWithToBuilder build() { + public @java.lang.SuppressWarnings("all") BuilderWithToBuilderWithSetterPrefix build() { java.util.List bars; switch (((this.bars == null) ? 0 : this.bars.size())) { case 0 : @@ -50,31 +50,31 @@ import lombok.Builder; default : bars = java.util.Collections.unmodifiableList(new java.util.ArrayList(this.bars)); } - return new BuilderWithToBuilder(one, two, foo, bars); + return new BuilderWithToBuilderWithSetterPrefix(one, two, foo, bars); } public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { - return (((((((("BuilderWithToBuilder.BuilderWithToBuilderBuilder(one=" + this.one) + ", two=") + this.two) + ", foo=") + this.foo) + ", bars=") + this.bars) + ")"); + return (((((((("BuilderWithToBuilderWithSetterPrefix.BuilderWithToBuilderWithSetterPrefixBuilder(one=" + this.one) + ", two=") + this.two) + ", foo=") + this.foo) + ", bars=") + this.bars) + ")"); } } private String mOne; private String mTwo; private @Builder.ObtainVia(method = "rrr",isStatic = true) T foo; private @lombok.Singular List bars; - public static K rrr(BuilderWithToBuilder x) { + public static K rrr(BuilderWithToBuilderWithSetterPrefix x) { return x.foo; } - @java.lang.SuppressWarnings("all") BuilderWithToBuilder(final String one, final String two, final T foo, final List bars) { + @java.lang.SuppressWarnings("all") BuilderWithToBuilderWithSetterPrefix(final String one, final String two, final T foo, final List bars) { super(); this.mOne = one; this.mTwo = two; this.foo = foo; this.bars = bars; } - public static @java.lang.SuppressWarnings("all") BuilderWithToBuilderBuilder builder() { - return new BuilderWithToBuilderBuilder(); + public static @java.lang.SuppressWarnings("all") BuilderWithToBuilderWithSetterPrefixBuilder builder() { + return new BuilderWithToBuilderWithSetterPrefixBuilder(); } - public @java.lang.SuppressWarnings("all") BuilderWithToBuilderBuilder toBuilder() { - final BuilderWithToBuilderBuilder builder = new BuilderWithToBuilderBuilder().withOne(this.mOne).withTwo(this.mTwo).withFoo(BuilderWithToBuilder.rrr(this)); + public @java.lang.SuppressWarnings("all") BuilderWithToBuilderWithSetterPrefixBuilder toBuilder() { + final BuilderWithToBuilderWithSetterPrefixBuilder builder = new BuilderWithToBuilderWithSetterPrefixBuilder().withOne(this.mOne).withTwo(this.mTwo).withFoo(BuilderWithToBuilderWithSetterPrefix.rrr(this)); if ((this.bars != null)) builder.withBars(this.bars); return builder; diff --git a/test/transform/resource/after-ecj/BuilderWithTolerateWithSetterPrefix.java b/test/transform/resource/after-ecj/BuilderWithTolerateWithSetterPrefix.java index a795bafc..6fa302e5 100644 --- a/test/transform/resource/after-ecj/BuilderWithTolerateWithSetterPrefix.java +++ b/test/transform/resource/after-ecj/BuilderWithTolerateWithSetterPrefix.java @@ -1,34 +1,34 @@ import lombok.Builder; import lombok.experimental.Tolerate; -public @Builder(setterPrefix = "with") class BuilderWithTolerate { - public static class BuilderWithTolerateBuilder { +public @Builder(setterPrefix = "with") class BuilderWithTolerateWithSetterPrefix { + public static class BuilderWithTolerateWithSetterPrefixBuilder { private @java.lang.SuppressWarnings("all") int value; - public @Tolerate BuilderWithTolerateBuilder withValue(String s) { + public @Tolerate BuilderWithTolerateWithSetterPrefixBuilder withValue(String s) { return this.withValue(Integer.parseInt(s)); } - @java.lang.SuppressWarnings("all") BuilderWithTolerateBuilder() { + @java.lang.SuppressWarnings("all") BuilderWithTolerateWithSetterPrefixBuilder() { super(); } - public @java.lang.SuppressWarnings("all") BuilderWithTolerateBuilder withValue(final int value) { + public @java.lang.SuppressWarnings("all") BuilderWithTolerateWithSetterPrefixBuilder withValue(final int value) { this.value = value; return this; } - public @java.lang.SuppressWarnings("all") BuilderWithTolerate build() { - return new BuilderWithTolerate(value); + public @java.lang.SuppressWarnings("all") BuilderWithTolerateWithSetterPrefix build() { + return new BuilderWithTolerateWithSetterPrefix(value); } public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { - return (("BuilderWithTolerate.BuilderWithTolerateBuilder(value=" + this.value) + ")"); + return (("BuilderWithTolerateWithSetterPrefix.BuilderWithTolerateWithSetterPrefixBuilder(value=" + this.value) + ")"); } } private final int value; public static void main(String[] args) { - BuilderWithTolerate.builder().withValue("42").build(); + BuilderWithTolerateWithSetterPrefix.builder().withValue("42").build(); } - @java.lang.SuppressWarnings("all") BuilderWithTolerate(final int value) { + @java.lang.SuppressWarnings("all") BuilderWithTolerateWithSetterPrefix(final int value) { super(); this.value = value; } - public static @java.lang.SuppressWarnings("all") BuilderWithTolerateBuilder builder() { - return new BuilderWithTolerateBuilder(); + public static @java.lang.SuppressWarnings("all") BuilderWithTolerateWithSetterPrefixBuilder builder() { + return new BuilderWithTolerateWithSetterPrefixBuilder(); } } diff --git a/test/transform/resource/before/BuilderSimpleWithSetterPrefix.java b/test/transform/resource/before/BuilderSimpleWithSetterPrefix.java index 38f3c029..19ab7af1 100644 --- a/test/transform/resource/before/BuilderSimpleWithSetterPrefix.java +++ b/test/transform/resource/before/BuilderSimpleWithSetterPrefix.java @@ -1,6 +1,6 @@ import java.util.List; @lombok.Builder(access = lombok.AccessLevel.PROTECTED, setterPrefix = "with") -class BuilderWithPrefix { +class BuilderSimpleWithSetterPrefix { private int unprefixed; } -- cgit From e1bd41fab9d62b5478e50b5c2fe2e45a0d767334 Mon Sep 17 00:00:00 2001 From: abrinkman94 Date: Thu, 19 Sep 2019 11:30:12 -0500 Subject: Added setterPrefix to javac --- src/core/lombok/javac/handlers/HandleBuilder.java | 9 ++++---- .../javac/handlers/JavacSingularsRecipes.java | 26 +++++++++++++++++++--- 2 files changed, 28 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/HandleBuilder.java b/src/core/lombok/javac/handlers/HandleBuilder.java index da40692e..f199f161 100644 --- a/src/core/lombok/javac/handlers/HandleBuilder.java +++ b/src/core/lombok/javac/handlers/HandleBuilder.java @@ -180,7 +180,7 @@ public class HandleBuilder extends JavacAnnotationHandler { bfd.builderFieldName = bfd.name; bfd.annotations = findCopyableAnnotations(fieldNode); bfd.type = fd.vartype; - bfd.singularData = getSingularData(fieldNode); + bfd.singularData = getSingularData(fieldNode, builderInstance.setterPrefix()); bfd.originalFieldNode = fieldNode; if (bfd.singularData != null && isDefault != null) { @@ -369,7 +369,7 @@ public class HandleBuilder extends JavacAnnotationHandler { bfd.rawName = raw.name; bfd.annotations = findCopyableAnnotations(param); bfd.type = raw.vartype; - bfd.singularData = getSingularData(param); + bfd.singularData = getSingularData(param, builderInstance.setterPrefix()); bfd.originalFieldNode = param; addObtainVia(bfd, param); builderFields.add(bfd); @@ -876,8 +876,9 @@ public class HandleBuilder extends JavacAnnotationHandler { * or parameter), or null if there's no {@code @Singular} annotation on it. * * @param node The node (field or method param) to inspect for its name and potential {@code @Singular} annotation. + * @param setterPrefix */ - private SingularData getSingularData(JavacNode node) { + private SingularData getSingularData(JavacNode node, final String setterPrefix) { for (JavacNode child : node.down()) { if (!annotationTypeMatches(Singular.class, child)) continue; Name pluralName = node.getKind() == Kind.FIELD ? removePrefixFromField(node) : ((JCVariableDecl) node.get()).name; @@ -919,7 +920,7 @@ public class HandleBuilder extends JavacAnnotationHandler { return null; } - return new SingularData(child, singularName, pluralName, typeArgs, targetFqn, singularizer); + return new SingularData(child, singularName, pluralName, typeArgs, targetFqn, singularizer, setterPrefix); } return null; diff --git a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java index 341d44df..f693af83 100644 --- a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java +++ b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java @@ -117,6 +117,7 @@ public class JavacSingularsRecipes { private final List typeArgs; private final String targetFqn; private final JavacSingularizer singularizer; + private final String setterPrefix; public SingularData(JavacNode annotation, Name singularName, Name pluralName, List typeArgs, String targetFqn, JavacSingularizer singularizer) { this.annotation = annotation; @@ -125,6 +126,17 @@ public class JavacSingularsRecipes { this.typeArgs = typeArgs; this.targetFqn = targetFqn; this.singularizer = singularizer; + this.setterPrefix = null; + } + + public SingularData(JavacNode annotation, Name singularName, Name pluralName, List typeArgs, String targetFqn, JavacSingularizer singularizer, String setterPrefix) { + this.annotation = annotation; + this.singularName = singularName; + this.pluralName = pluralName; + this.typeArgs = typeArgs; + this.targetFqn = targetFqn; + this.singularizer = singularizer; + this.setterPrefix = setterPrefix; } public JavacNode getAnnotation() { @@ -138,6 +150,8 @@ public class JavacSingularsRecipes { public Name getPluralName() { return pluralName; } + + public String getSetterPrefix() { return setterPrefix; } public List getTypeArgs() { return typeArgs; @@ -279,8 +293,12 @@ public class JavacSingularsRecipes { ListBuffer statements = generateSingularMethodStatements(maker, data, builderType, source); List params = generateSingularMethodParameters(maker, data, builderType, source); Name name = data.getSingularName(); - if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName(getAddMethodName(), name.toString())); - + Name prefixedSingularName = data.getSetterPrefix().length() == 0 ? name : + builderType.toName(HandlerUtil.buildAccessorName(data.getSetterPrefix(), name.toString())); + + name = fluent ? prefixedSingularName : builderType.toName(HandlerUtil.buildAccessorName(getAddMethodName(), + name.toString())); + statements.prepend(createConstructBuilderVarIfNeeded(maker, data, builderType, source)); finishAndInjectMethod(cfv, maker, returnType, returnStatement, data, builderType, source, deprecate, statements, name, params, access); } @@ -307,7 +325,9 @@ public class JavacSingularsRecipes { private void generatePluralMethod(CheckerFrameworkVersion cfv, boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent, AccessLevel access) { ListBuffer statements = generatePluralMethodStatements(maker, data, builderType, source); Name name = data.getPluralName(); - if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName(getAddMethodName() + "All", name.toString())); + Name prefixedSingularName = builderType.toName(data.getSetterPrefix()); + name = fluent ? prefixedSingularName : builderType.toName(HandlerUtil.buildAccessorName( + getAddMethodName() + "All", name.toString())); JCExpression paramType = getPluralMethodParamType(builderType); paramType = addTypeArgs(getTypeArgumentsCount(), true, builderType, paramType, data.getTypeArgs(), source); long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext()); -- cgit From bae66a3450cf6118d7447a390baf333f862c7d8e Mon Sep 17 00:00:00 2001 From: Caleb Brinkman Date: Thu, 19 Sep 2019 13:14:43 -0500 Subject: Fix null pointers and incorrect tests --- src/core/lombok/javac/handlers/JavacSingularsRecipes.java | 7 ++++--- .../resource/after-delombok/BuilderSimpleWithSetterPrefix.java | 2 +- .../resource/after-ecj/BuilderSimpleWithSetterPrefix.java | 10 +++++----- 3 files changed, 10 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java index f693af83..56116346 100644 --- a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java +++ b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java @@ -126,7 +126,7 @@ public class JavacSingularsRecipes { this.typeArgs = typeArgs; this.targetFqn = targetFqn; this.singularizer = singularizer; - this.setterPrefix = null; + this.setterPrefix = ""; } public SingularData(JavacNode annotation, Name singularName, Name pluralName, List typeArgs, String targetFqn, JavacSingularizer singularizer, String setterPrefix) { @@ -293,8 +293,9 @@ public class JavacSingularsRecipes { ListBuffer statements = generateSingularMethodStatements(maker, data, builderType, source); List params = generateSingularMethodParameters(maker, data, builderType, source); Name name = data.getSingularName(); - Name prefixedSingularName = data.getSetterPrefix().length() == 0 ? name : - builderType.toName(HandlerUtil.buildAccessorName(data.getSetterPrefix(), name.toString())); + String setterPrefix = data.getSetterPrefix(); + Name prefixedSingularName = setterPrefix.isEmpty() ? name : + builderType.toName(HandlerUtil.buildAccessorName(setterPrefix, name.toString())); name = fluent ? prefixedSingularName : builderType.toName(HandlerUtil.buildAccessorName(getAddMethodName(), name.toString())); diff --git a/test/transform/resource/after-delombok/BuilderSimpleWithSetterPrefix.java b/test/transform/resource/after-delombok/BuilderSimpleWithSetterPrefix.java index b10ad619..24ca09d6 100644 --- a/test/transform/resource/after-delombok/BuilderSimpleWithSetterPrefix.java +++ b/test/transform/resource/after-delombok/BuilderSimpleWithSetterPrefix.java @@ -10,7 +10,7 @@ class BuilderSimpleWithSetterPrefix { @java.lang.SuppressWarnings("all") private int unprefixed; @java.lang.SuppressWarnings("all") - BuilderSimpelWithSetterPrefixBuilder() { + BuilderSimpleWithSetterPrefixBuilder() { } @java.lang.SuppressWarnings("all") public BuilderSimpleWithSetterPrefixBuilder withUnprefixed(final int unprefixed) { diff --git a/test/transform/resource/after-ecj/BuilderSimpleWithSetterPrefix.java b/test/transform/resource/after-ecj/BuilderSimpleWithSetterPrefix.java index 98c42fe9..3bc8d882 100644 --- a/test/transform/resource/after-ecj/BuilderSimpleWithSetterPrefix.java +++ b/test/transform/resource/after-ecj/BuilderSimpleWithSetterPrefix.java @@ -1,6 +1,6 @@ import java.util.List; -@lombok.Builder(access = lombok.AccessLevel.PROTECTED,setterPrefix = "with") class BuilderWithPrefix { - protected static @java.lang.SuppressWarnings("all") class BuilderWithPrefixBuilder { +@lombok.Builder(access = lombok.AccessLevel.PROTECTED,setterPrefix = "with") class BulderSimpleWithSetterPrefix { + protected static @java.lang.SuppressWarnings("all") class BuilderSimpleWithSetterPrefix { private @java.lang.SuppressWarnings("all") int unprefixed; @java.lang.SuppressWarnings("all") BuilderWithPrefixBuilder() { super(); @@ -17,11 +17,11 @@ import java.util.List; } } private int unprefixed; - @java.lang.SuppressWarnings("all") BuilderWithPrefix(final int unprefixed) { + @java.lang.SuppressWarnings("all") BuilderSimpleWithSetterPrefixBuilder(final int unprefixed) { super(); this.unprefixed = unprefixed; } - protected static @java.lang.SuppressWarnings("all") BuilderWithPrefixBuilder builder() { - return new BuilderWithPrefixBuilder(); + protected static @java.lang.SuppressWarnings("all") BuilderSimpleWithSetterPrefixBuilder builder() { + return new BuilderSimpleWithSetterPrefixBuilder(); } } -- cgit From 24a49a9d2bc9ae6776eabcbeb8ce6bbe4ad5ebcf Mon Sep 17 00:00:00 2001 From: Caleb Brinkman Date: Thu, 19 Sep 2019 15:16:02 -0500 Subject: Fix more copy/paste test errors --- .../javac/handlers/JavacSingularsRecipes.java | 7 +- .../BuilderSingularGuavaMapsWithSetterPrefix.java | 94 +++++++++++++ .../BuilderSingularSetsWithPrefix.java | 153 --------------------- .../BuilderSingularSetsWithSetterPrefix.java | 153 +++++++++++++++++++++ .../after-ecj/BuilderSimpleWithSetterPrefix.java | 2 +- .../before/BuilderSingularGuavaMapsWithPrefix.java | 12 -- .../BuilderSingularGuavaMapsWithSetterPrefix.java | 12 ++ ...rSingularToBuilderWithNullWithSetterPrefix.java | 2 +- ...derSingularNoAutoWithSetterPrefix.java.messages | 2 + 9 files changed, 267 insertions(+), 170 deletions(-) create mode 100644 test/transform/resource/after-delombok/BuilderSingularGuavaMapsWithSetterPrefix.java delete mode 100644 test/transform/resource/after-delombok/BuilderSingularSetsWithPrefix.java create mode 100644 test/transform/resource/after-delombok/BuilderSingularSetsWithSetterPrefix.java delete mode 100644 test/transform/resource/before/BuilderSingularGuavaMapsWithPrefix.java create mode 100644 test/transform/resource/before/BuilderSingularGuavaMapsWithSetterPrefix.java create mode 100644 test/transform/resource/messages-delombok/BuilderSingularNoAutoWithSetterPrefix.java.messages (limited to 'src') diff --git a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java index 56116346..10e6f9b4 100644 --- a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java +++ b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java @@ -326,9 +326,10 @@ public class JavacSingularsRecipes { private void generatePluralMethod(CheckerFrameworkVersion cfv, boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent, AccessLevel access) { ListBuffer statements = generatePluralMethodStatements(maker, data, builderType, source); Name name = data.getPluralName(); - Name prefixedSingularName = builderType.toName(data.getSetterPrefix()); - name = fluent ? prefixedSingularName : builderType.toName(HandlerUtil.buildAccessorName( - getAddMethodName() + "All", name.toString())); + + Name prefixedSingularName = data.getSetterPrefix().isEmpty() ? name : builderType.toName(HandlerUtil.buildAccessorName(data.getSetterPrefix(), data.getPluralName().toString())); + name = fluent ? prefixedSingularName + : builderType.toName(HandlerUtil.buildAccessorName(getAddMethodName() + "All", name.toString())); JCExpression paramType = getPluralMethodParamType(builderType); paramType = addTypeArgs(getTypeArgumentsCount(), true, builderType, paramType, data.getTypeArgs(), source); long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext()); diff --git a/test/transform/resource/after-delombok/BuilderSingularGuavaMapsWithSetterPrefix.java b/test/transform/resource/after-delombok/BuilderSingularGuavaMapsWithSetterPrefix.java new file mode 100644 index 00000000..b3162854 --- /dev/null +++ b/test/transform/resource/after-delombok/BuilderSingularGuavaMapsWithSetterPrefix.java @@ -0,0 +1,94 @@ +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableBiMap; +import com.google.common.collect.ImmutableSortedMap; +class BuilderSingularGuavaMapsWithSetterPrefix { + private ImmutableMap battleaxes; + private ImmutableSortedMap vertices; + @SuppressWarnings("all") + private ImmutableBiMap rawMap; + @java.lang.SuppressWarnings("all") + BuilderSingularGuavaMapsWithSetterPrefix(final ImmutableMap battleaxes, final ImmutableSortedMap vertices, final ImmutableBiMap rawMap) { + this.battleaxes = battleaxes; + this.vertices = vertices; + this.rawMap = rawMap; + } + @java.lang.SuppressWarnings("all") + public static class BuilderSingularGuavaMapsWithSetterPrefixBuilder { + @java.lang.SuppressWarnings("all") + private com.google.common.collect.ImmutableMap.Builder battleaxes; + @java.lang.SuppressWarnings("all") + private com.google.common.collect.ImmutableSortedMap.Builder vertices; + @java.lang.SuppressWarnings("all") + private com.google.common.collect.ImmutableBiMap.Builder rawMap; + @java.lang.SuppressWarnings("all") + BuilderSingularGuavaMapsWithSetterPrefixBuilder() { + } + @java.lang.SuppressWarnings("all") + public BuilderSingularGuavaMapsWithSetterPrefixBuilder withBattleaxe(final K key, final V value) { + if (this.battleaxes == null) this.battleaxes = com.google.common.collect.ImmutableMap.builder(); + this.battleaxes.put(key, value); + return this; + } + @java.lang.SuppressWarnings("all") + public BuilderSingularGuavaMapsWithSetterPrefixBuilder withBattleaxes(final java.util.Map battleaxes) { + if (this.battleaxes == null) this.battleaxes = com.google.common.collect.ImmutableMap.builder(); + this.battleaxes.putAll(battleaxes); + return this; + } + @java.lang.SuppressWarnings("all") + public BuilderSingularGuavaMapsWithSetterPrefixBuilder clearBattleaxes() { + this.battleaxes = null; + return this; + } + @java.lang.SuppressWarnings("all") + public BuilderSingularGuavaMapsWithSetterPrefixBuilder withVertex(final Integer key, final V value) { + if (this.vertices == null) this.vertices = com.google.common.collect.ImmutableSortedMap.naturalOrder(); + this.vertices.put(key, value); + return this; + } + @java.lang.SuppressWarnings("all") + public BuilderSingularGuavaMapsWithSetterPrefixBuilder withVertices(final java.util.Map vertices) { + if (this.vertices == null) this.vertices = com.google.common.collect.ImmutableSortedMap.naturalOrder(); + this.vertices.putAll(vertices); + return this; + } + @java.lang.SuppressWarnings("all") + public BuilderSingularGuavaMapsWithSetterPrefixBuilder clearVertices() { + this.vertices = null; + return this; + } + @java.lang.SuppressWarnings("all") + public BuilderSingularGuavaMapsWithSetterPrefixBuilder withRawMap(final java.lang.Object key, final java.lang.Object value) { + if (this.rawMap == null) this.rawMap = com.google.common.collect.ImmutableBiMap.builder(); + this.rawMap.put(key, value); + return this; + } + @java.lang.SuppressWarnings("all") + public BuilderSingularGuavaMapsWithSetterPrefixBuilder withRawMap(final java.util.Map rawMap) { + if (this.rawMap == null) this.rawMap = com.google.common.collect.ImmutableBiMap.builder(); + this.rawMap.putAll(rawMap); + return this; + } + @java.lang.SuppressWarnings("all") + public BuilderSingularGuavaMapsWithSetterPrefixBuilder clearRawMap() { + this.rawMap = null; + return this; + } + @java.lang.SuppressWarnings("all") + public BuilderSingularGuavaMapsWithSetterPrefix build() { + com.google.common.collect.ImmutableMap battleaxes = this.battleaxes == null ? com.google.common.collect.ImmutableMap.of() : this.battleaxes.build(); + com.google.common.collect.ImmutableSortedMap vertices = this.vertices == null ? com.google.common.collect.ImmutableSortedMap.of() : this.vertices.build(); + com.google.common.collect.ImmutableBiMap rawMap = this.rawMap == null ? com.google.common.collect.ImmutableBiMap.of() : this.rawMap.build(); + return new BuilderSingularGuavaMapsWithSetterPrefix(battleaxes, vertices, rawMap); + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public java.lang.String toString() { + return "BuilderSingularGuavaMapsWithSetterPrefix.BuilderSingularGuavaMapsWithSetterPrefixBuilder(battleaxes=" + this.battleaxes + ", vertices=" + this.vertices + ", rawMap=" + this.rawMap + ")"; + } + } + @java.lang.SuppressWarnings("all") + public static BuilderSingularGuavaMapsWithSetterPrefixBuilder builder() { + return new BuilderSingularGuavaMapsWithSetterPrefixBuilder(); + } +} diff --git a/test/transform/resource/after-delombok/BuilderSingularSetsWithPrefix.java b/test/transform/resource/after-delombok/BuilderSingularSetsWithPrefix.java deleted file mode 100644 index e3817b59..00000000 --- a/test/transform/resource/after-delombok/BuilderSingularSetsWithPrefix.java +++ /dev/null @@ -1,153 +0,0 @@ -import java.util.Set; -import java.util.SortedSet; -class BuilderSingularSets { - private Set dangerMice; - private SortedSet octopodes; - @SuppressWarnings("all") - private Set rawSet; - private Set stringSet; - @java.lang.SuppressWarnings("all") - BuilderSingularSets(final Set dangerMice, final SortedSet octopodes, final Set rawSet, final Set stringSet) { - this.dangerMice = dangerMice; - this.octopodes = octopodes; - this.rawSet = rawSet; - this.stringSet = stringSet; - } - @java.lang.SuppressWarnings("all") - public static class BuilderSingularSetsBuilder { - @java.lang.SuppressWarnings("all") - private java.util.ArrayList dangerMice; - @java.lang.SuppressWarnings("all") - private java.util.ArrayList octopodes; - @java.lang.SuppressWarnings("all") - private java.util.ArrayList rawSet; - @java.lang.SuppressWarnings("all") - private java.util.ArrayList stringSet; - @java.lang.SuppressWarnings("all") - BuilderSingularSetsBuilder() { - } - @java.lang.SuppressWarnings("all") - public BuilderSingularSetsBuilder withDangerMouse(final T dangerMouse) { - if (this.dangerMice == null) this.dangerMice = new java.util.ArrayList(); - this.dangerMice.add(dangerMouse); - return this; - } - @java.lang.SuppressWarnings("all") - public BuilderSingularSetsBuilder withDangerMice(final java.util.Collection dangerMice) { - if (this.dangerMice == null) this.dangerMice = new java.util.ArrayList(); - this.dangerMice.addAll(dangerMice); - return this; - } - @java.lang.SuppressWarnings("all") - public BuilderSingularSetsBuilder clearDangerMice() { - if (this.dangerMice != null) this.dangerMice.clear(); - return this; - } - @java.lang.SuppressWarnings("all") - public BuilderSingularSetsBuilder withOctopus(final Number octopus) { - if (this.octopodes == null) this.octopodes = new java.util.ArrayList(); - this.octopodes.add(octopus); - return this; - } - @java.lang.SuppressWarnings("all") - public BuilderSingularSetsBuilder withOctopodes(final java.util.Collection octopodes) { - if (this.octopodes == null) this.octopodes = new java.util.ArrayList(); - this.octopodes.addAll(octopodes); - return this; - } - @java.lang.SuppressWarnings("all") - public BuilderSingularSetsBuilder clearOctopodes() { - if (this.octopodes != null) this.octopodes.clear(); - return this; - } - @java.lang.SuppressWarnings("all") - public BuilderSingularSetsBuilder withRawSet(final java.lang.Object rawSet) { - if (this.rawSet == null) this.rawSet = new java.util.ArrayList(); - this.rawSet.add(rawSet); - return this; - } - @java.lang.SuppressWarnings("all") - public BuilderSingularSetsBuilder withRawSet(final java.util.Collection rawSet) { - if (this.rawSet == null) this.rawSet = new java.util.ArrayList(); - this.rawSet.addAll(rawSet); - return this; - } - @java.lang.SuppressWarnings("all") - public BuilderSingularSetsBuilder clearRawSet() { - if (this.rawSet != null) this.rawSet.clear(); - return this; - } - @java.lang.SuppressWarnings("all") - public BuilderSingularSetsBuilder withStringSet(final String stringSet) { - if (this.stringSet == null) this.stringSet = new java.util.ArrayList(); - this.stringSet.add(stringSet); - return this; - } - @java.lang.SuppressWarnings("all") - public BuilderSingularSetsBuilder withStringSet(final java.util.Collection stringSet) { - if (this.stringSet == null) this.stringSet = new java.util.ArrayList(); - this.stringSet.addAll(stringSet); - return this; - } - @java.lang.SuppressWarnings("all") - public BuilderSingularSetsBuilder clearStringSet() { - if (this.stringSet != null) this.stringSet.clear(); - return this; - } - @java.lang.SuppressWarnings("all") - public BuilderSingularSets build() { - java.util.Set dangerMice; - switch (this.dangerMice == null ? 0 : this.dangerMice.size()) { - case 0: - dangerMice = java.util.Collections.emptySet(); - break; - case 1: - dangerMice = java.util.Collections.singleton(this.dangerMice.get(0)); - break; - default: - dangerMice = new java.util.LinkedHashSet(this.dangerMice.size() < 1073741824 ? 1 + this.dangerMice.size() + (this.dangerMice.size() - 3) / 3 : java.lang.Integer.MAX_VALUE); - dangerMice.addAll(this.dangerMice); - dangerMice = java.util.Collections.unmodifiableSet(dangerMice); - } - java.util.SortedSet octopodes = new java.util.TreeSet(); - if (this.octopodes != null) octopodes.addAll(this.octopodes); - octopodes = java.util.Collections.unmodifiableSortedSet(octopodes); - java.util.Set rawSet; - switch (this.rawSet == null ? 0 : this.rawSet.size()) { - case 0: - rawSet = java.util.Collections.emptySet(); - break; - case 1: - rawSet = java.util.Collections.singleton(this.rawSet.get(0)); - break; - default: - rawSet = new java.util.LinkedHashSet(this.rawSet.size() < 1073741824 ? 1 + this.rawSet.size() + (this.rawSet.size() - 3) / 3 : java.lang.Integer.MAX_VALUE); - rawSet.addAll(this.rawSet); - rawSet = java.util.Collections.unmodifiableSet(rawSet); - } - java.util.Set stringSet; - switch (this.stringSet == null ? 0 : this.stringSet.size()) { - case 0: - stringSet = java.util.Collections.emptySet(); - break; - case 1: - stringSet = java.util.Collections.singleton(this.stringSet.get(0)); - break; - default: - stringSet = new java.util.LinkedHashSet(this.stringSet.size() < 1073741824 ? 1 + this.stringSet.size() + (this.stringSet.size() - 3) / 3 : java.lang.Integer.MAX_VALUE); - stringSet.addAll(this.stringSet); - stringSet = java.util.Collections.unmodifiableSet(stringSet); - } - return new BuilderSingularSets(dangerMice, octopodes, rawSet, stringSet); - } - @java.lang.Override - @java.lang.SuppressWarnings("all") - public java.lang.String toString() { - return "BuilderSingularSets.BuilderSingularSetsBuilder(dangerMice=" + this.dangerMice + ", octopodes=" + this.octopodes + ", rawSet=" + this.rawSet + ", stringSet=" + this.stringSet + ")"; - } - } - @java.lang.SuppressWarnings("all") - public static BuilderSingularSetsBuilder builder() { - return new BuilderSingularSetsBuilder(); - } -} diff --git a/test/transform/resource/after-delombok/BuilderSingularSetsWithSetterPrefix.java b/test/transform/resource/after-delombok/BuilderSingularSetsWithSetterPrefix.java new file mode 100644 index 00000000..9702b850 --- /dev/null +++ b/test/transform/resource/after-delombok/BuilderSingularSetsWithSetterPrefix.java @@ -0,0 +1,153 @@ +import java.util.Set; +import java.util.SortedSet; +class BuilderSingularSetsWithSetterPrefix { + private Set dangerMice; + private SortedSet octopodes; + @SuppressWarnings("all") + private Set rawSet; + private Set stringSet; + @java.lang.SuppressWarnings("all") + BuilderSingularSetsWithSetterPrefix(final Set dangerMice, final SortedSet octopodes, final Set rawSet, final Set stringSet) { + this.dangerMice = dangerMice; + this.octopodes = octopodes; + this.rawSet = rawSet; + this.stringSet = stringSet; + } + @java.lang.SuppressWarnings("all") + public static class BuilderSingularSetsWithSetterPrefixBuilder { + @java.lang.SuppressWarnings("all") + private java.util.ArrayList dangerMice; + @java.lang.SuppressWarnings("all") + private java.util.ArrayList octopodes; + @java.lang.SuppressWarnings("all") + private java.util.ArrayList rawSet; + @java.lang.SuppressWarnings("all") + private java.util.ArrayList stringSet; + @java.lang.SuppressWarnings("all") + BuilderSingularSetsWithSetterPrefixBuilder() { + } + @java.lang.SuppressWarnings("all") + public BuilderSingularSetsWithSetterPrefixBuilder withDangerMouse(final T dangerMouse) { + if (this.dangerMice == null) this.dangerMice = new java.util.ArrayList(); + this.dangerMice.add(dangerMouse); + return this; + } + @java.lang.SuppressWarnings("all") + public BuilderSingularSetsWithSetterPrefixBuilder withDangerMice(final java.util.Collection dangerMice) { + if (this.dangerMice == null) this.dangerMice = new java.util.ArrayList(); + this.dangerMice.addAll(dangerMice); + return this; + } + @java.lang.SuppressWarnings("all") + public BuilderSingularSetsWithSetterPrefixBuilder clearDangerMice() { + if (this.dangerMice != null) this.dangerMice.clear(); + return this; + } + @java.lang.SuppressWarnings("all") + public BuilderSingularSetsWithSetterPrefixBuilder withOctopus(final Number octopus) { + if (this.octopodes == null) this.octopodes = new java.util.ArrayList(); + this.octopodes.add(octopus); + return this; + } + @java.lang.SuppressWarnings("all") + public BuilderSingularSetsWithSetterPrefixBuilder withOctopodes(final java.util.Collection octopodes) { + if (this.octopodes == null) this.octopodes = new java.util.ArrayList(); + this.octopodes.addAll(octopodes); + return this; + } + @java.lang.SuppressWarnings("all") + public BuilderSingularSetsWithSetterPrefixBuilder clearOctopodes() { + if (this.octopodes != null) this.octopodes.clear(); + return this; + } + @java.lang.SuppressWarnings("all") + public BuilderSingularSetsWithSetterPrefixBuilder withRawSet(final java.lang.Object rawSet) { + if (this.rawSet == null) this.rawSet = new java.util.ArrayList(); + this.rawSet.add(rawSet); + return this; + } + @java.lang.SuppressWarnings("all") + public BuilderSingularSetsWithSetterPrefixBuilder withRawSet(final java.util.Collection rawSet) { + if (this.rawSet == null) this.rawSet = new java.util.ArrayList(); + this.rawSet.addAll(rawSet); + return this; + } + @java.lang.SuppressWarnings("all") + public BuilderSingularSetsWithSetterPrefixBuilder clearRawSet() { + if (this.rawSet != null) this.rawSet.clear(); + return this; + } + @java.lang.SuppressWarnings("all") + public BuilderSingularSetsWithSetterPrefixBuilder withStringSet(final String stringSet) { + if (this.stringSet == null) this.stringSet = new java.util.ArrayList(); + this.stringSet.add(stringSet); + return this; + } + @java.lang.SuppressWarnings("all") + public BuilderSingularSetsWithSetterPrefixBuilder withStringSet(final java.util.Collection stringSet) { + if (this.stringSet == null) this.stringSet = new java.util.ArrayList(); + this.stringSet.addAll(stringSet); + return this; + } + @java.lang.SuppressWarnings("all") + public BuilderSingularSetsWithSetterPrefixBuilder clearStringSet() { + if (this.stringSet != null) this.stringSet.clear(); + return this; + } + @java.lang.SuppressWarnings("all") + public BuilderSingularSetsWithSetterPrefix build() { + java.util.Set dangerMice; + switch (this.dangerMice == null ? 0 : this.dangerMice.size()) { + case 0: + dangerMice = java.util.Collections.emptySet(); + break; + case 1: + dangerMice = java.util.Collections.singleton(this.dangerMice.get(0)); + break; + default: + dangerMice = new java.util.LinkedHashSet(this.dangerMice.size() < 1073741824 ? 1 + this.dangerMice.size() + (this.dangerMice.size() - 3) / 3 : java.lang.Integer.MAX_VALUE); + dangerMice.addAll(this.dangerMice); + dangerMice = java.util.Collections.unmodifiableSet(dangerMice); + } + java.util.SortedSet octopodes = new java.util.TreeSet(); + if (this.octopodes != null) octopodes.addAll(this.octopodes); + octopodes = java.util.Collections.unmodifiableSortedSet(octopodes); + java.util.Set rawSet; + switch (this.rawSet == null ? 0 : this.rawSet.size()) { + case 0: + rawSet = java.util.Collections.emptySet(); + break; + case 1: + rawSet = java.util.Collections.singleton(this.rawSet.get(0)); + break; + default: + rawSet = new java.util.LinkedHashSet(this.rawSet.size() < 1073741824 ? 1 + this.rawSet.size() + (this.rawSet.size() - 3) / 3 : java.lang.Integer.MAX_VALUE); + rawSet.addAll(this.rawSet); + rawSet = java.util.Collections.unmodifiableSet(rawSet); + } + java.util.Set stringSet; + switch (this.stringSet == null ? 0 : this.stringSet.size()) { + case 0: + stringSet = java.util.Collections.emptySet(); + break; + case 1: + stringSet = java.util.Collections.singleton(this.stringSet.get(0)); + break; + default: + stringSet = new java.util.LinkedHashSet(this.stringSet.size() < 1073741824 ? 1 + this.stringSet.size() + (this.stringSet.size() - 3) / 3 : java.lang.Integer.MAX_VALUE); + stringSet.addAll(this.stringSet); + stringSet = java.util.Collections.unmodifiableSet(stringSet); + } + return new BuilderSingularSetsWithSetterPrefix(dangerMice, octopodes, rawSet, stringSet); + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public java.lang.String toString() { + return "BuilderSingularSetsWithSetterPrefix.BuilderSingularSetsWithSetterPrefixBuilder(dangerMice=" + this.dangerMice + ", octopodes=" + this.octopodes + ", rawSet=" + this.rawSet + ", stringSet=" + this.stringSet + ")"; + } + } + @java.lang.SuppressWarnings("all") + public static BuilderSingularSetsWithSetterPrefixBuilder builder() { + return new BuilderSingularSetsWithSetterPrefixBuilder(); + } +} diff --git a/test/transform/resource/after-ecj/BuilderSimpleWithSetterPrefix.java b/test/transform/resource/after-ecj/BuilderSimpleWithSetterPrefix.java index 3bc8d882..ad3485c6 100644 --- a/test/transform/resource/after-ecj/BuilderSimpleWithSetterPrefix.java +++ b/test/transform/resource/after-ecj/BuilderSimpleWithSetterPrefix.java @@ -1,5 +1,5 @@ import java.util.List; -@lombok.Builder(access = lombok.AccessLevel.PROTECTED,setterPrefix = "with") class BulderSimpleWithSetterPrefix { +@lombok.Builder(access = lombok.AccessLevel.PROTECTED,setterPrefix = "with") class BuilderSimpleWithSetterPrefix { protected static @java.lang.SuppressWarnings("all") class BuilderSimpleWithSetterPrefix { private @java.lang.SuppressWarnings("all") int unprefixed; @java.lang.SuppressWarnings("all") BuilderWithPrefixBuilder() { diff --git a/test/transform/resource/before/BuilderSingularGuavaMapsWithPrefix.java b/test/transform/resource/before/BuilderSingularGuavaMapsWithPrefix.java deleted file mode 100644 index a2b48cb3..00000000 --- a/test/transform/resource/before/BuilderSingularGuavaMapsWithPrefix.java +++ /dev/null @@ -1,12 +0,0 @@ -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableBiMap; -import com.google.common.collect.ImmutableSortedMap; - -import lombok.Singular; - -@lombok.Builder(setterPrefix = "with") -class BuilderSingularGuavaMapsWithSetterPrefix { - @Singular private ImmutableMap battleaxes; - @Singular private ImmutableSortedMap vertices; - @SuppressWarnings("all") @Singular("rawMap") private ImmutableBiMap rawMap; -} diff --git a/test/transform/resource/before/BuilderSingularGuavaMapsWithSetterPrefix.java b/test/transform/resource/before/BuilderSingularGuavaMapsWithSetterPrefix.java new file mode 100644 index 00000000..a2b48cb3 --- /dev/null +++ b/test/transform/resource/before/BuilderSingularGuavaMapsWithSetterPrefix.java @@ -0,0 +1,12 @@ +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableBiMap; +import com.google.common.collect.ImmutableSortedMap; + +import lombok.Singular; + +@lombok.Builder(setterPrefix = "with") +class BuilderSingularGuavaMapsWithSetterPrefix { + @Singular private ImmutableMap battleaxes; + @Singular private ImmutableSortedMap vertices; + @SuppressWarnings("all") @Singular("rawMap") private ImmutableBiMap rawMap; +} diff --git a/test/transform/resource/before/BuilderSingularToBuilderWithNullWithSetterPrefix.java b/test/transform/resource/before/BuilderSingularToBuilderWithNullWithSetterPrefix.java index 845b38df..454cac97 100644 --- a/test/transform/resource/before/BuilderSingularToBuilderWithNullWithSetterPrefix.java +++ b/test/transform/resource/before/BuilderSingularToBuilderWithNullWithSetterPrefix.java @@ -5,6 +5,6 @@ class BuilderSingularToBuilderWithNullWithSetterPrefix { @Singular private java.util.List elems; public static void test() { - new BuilderSingularToBuilderWithNull(null).toBuilder(); + new BuilderSingularToBuilderWithNullWithSetterPrefix(null).toBuilder(); } } diff --git a/test/transform/resource/messages-delombok/BuilderSingularNoAutoWithSetterPrefix.java.messages b/test/transform/resource/messages-delombok/BuilderSingularNoAutoWithSetterPrefix.java.messages new file mode 100644 index 00000000..8719789b --- /dev/null +++ b/test/transform/resource/messages-delombok/BuilderSingularNoAutoWithSetterPrefix.java.messages @@ -0,0 +1,2 @@ +8 The singular must be specified explicitly (e.g. @Singular("task")) because auto singularization is disabled. +10 The singular must be specified explicitly (e.g. @Singular("task")) because auto singularization is disabled. -- cgit From 666defaff365d9841d5136063fc6f9e6ee5c0403 Mon Sep 17 00:00:00 2001 From: Caleb Brinkman Date: Fri, 25 Oct 2019 15:38:07 -0500 Subject: Fix up some more tests and copy-paste errors --- .../lombok/eclipse/handlers/HandleBuilder.java | 15 ++++++++--- ...WildcardListsWithToBuilderWithSetterPrefix.java | 1 - ...erWithExistingBuilderClassWithSetterPrefix.java | 4 +-- ...BuilderWithNoBuilderMethodWithSetterPrefix.java | 1 - .../BuilderWithToBuilderWithSetterPrefix.java | 1 - .../after-ecj/BuilderSimpleWithSetterPrefix.java | 10 ++++---- .../BuilderSingularSetsWithSetterPrefix.java | 16 ++++++------ ...uilderSingularWithPrefixesWithSetterPrefix.java | 8 +++--- ...erWithExistingBuilderClassWithSetterPrefix.java | 2 +- ...ilderWithRecursiveGenericsWithSetterPrefix.java | 2 +- .../BuilderWithToBuilderWithSetterPrefix.java | 29 +++++++++++----------- ...BuilderWithNoBuilderMethodWithSetterPrefix.java | 2 +- .../BuilderWithToBuilderWithSetterPrefix.java | 4 +-- .../BuilderWithTolerateWithSetterPrefix.java | 2 +- 14 files changed, 51 insertions(+), 46 deletions(-) (limited to 'src') diff --git a/src/core/lombok/eclipse/handlers/HandleBuilder.java b/src/core/lombok/eclipse/handlers/HandleBuilder.java index ec2be523..017cde17 100755 --- a/src/core/lombok/eclipse/handlers/HandleBuilder.java +++ b/src/core/lombok/eclipse/handlers/HandleBuilder.java @@ -539,7 +539,7 @@ public class HandleBuilder extends EclipseAnnotationHandler { tps[i].name = typeArgsForToBuilder.get(i); } } - MethodDeclaration md = generateToBuilderMethod(cfv, toBuilderMethodName, builderClassName, tdParent, tps, builderFields, fluent, ast, accessForOuters); + MethodDeclaration md = generateToBuilderMethod(cfv, toBuilderMethodName, builderClassName, tdParent, tps, builderFields, fluent, ast, accessForOuters, builderInstance.setterPrefix()); if (md != null) injectMethod(tdParent, md); } @@ -552,7 +552,7 @@ public class HandleBuilder extends EclipseAnnotationHandler { } private static final char[] BUILDER_TEMP_VAR = {'b', 'u', 'i', 'l', 'd', 'e', 'r'}; - private MethodDeclaration generateToBuilderMethod(CheckerFrameworkVersion cfv, String methodName, String builderClassName, EclipseNode type, TypeParameter[] typeParams, List builderFields, boolean fluent, ASTNode source, AccessLevel access) { + private MethodDeclaration generateToBuilderMethod(CheckerFrameworkVersion cfv, String methodName, String builderClassName, EclipseNode type, TypeParameter[] typeParams, List builderFields, boolean fluent, ASTNode source, AccessLevel access, String prefix) { int pS = source.sourceStart, pE = source.sourceEnd; long p = (long) pS << 32 | pE; @@ -567,7 +567,14 @@ public class HandleBuilder extends EclipseAnnotationHandler { Expression receiver = invoke; List statements = null; for (BuilderFieldData bfd : builderFields) { - char[] setterName = fluent ? bfd.name : HandlerUtil.buildAccessorName("set", new String(bfd.name)).toCharArray(); + String setterPrefix = prefix.isEmpty() ? "set" : prefix; + //char[] setterName = fluent ? bfd.name : HandlerUtil.buildAccessorName("set", new String(bfd.name)).toCharArray(); + String setterName; + if(fluent) { + setterName = prefix.isEmpty() ? new String(bfd.name) : HandlerUtil.buildAccessorName(setterPrefix, new String(bfd.name)); + } else { + setterName = HandlerUtil.buildAccessorName(setterPrefix, new String(bfd.name)); + } MessageSend ms = new MessageSend(); Expression[] tgt = new Expression[bfd.singularData == null ? 1 : 2]; @@ -600,7 +607,7 @@ public class HandleBuilder extends EclipseAnnotationHandler { } } - ms.selector = setterName; + ms.selector = setterName.toCharArray(); if (bfd.singularData == null) { ms.arguments = tgt; ms.receiver = receiver; diff --git a/test/transform/resource/after-delombok/BuilderSingularWildcardListsWithToBuilderWithSetterPrefix.java b/test/transform/resource/after-delombok/BuilderSingularWildcardListsWithToBuilderWithSetterPrefix.java index 8e849f44..367f0ac1 100644 --- a/test/transform/resource/after-delombok/BuilderSingularWildcardListsWithToBuilderWithSetterPrefix.java +++ b/test/transform/resource/after-delombok/BuilderSingularWildcardListsWithToBuilderWithSetterPrefix.java @@ -1,6 +1,5 @@ import java.util.List; import java.util.Collection; -@Builder(toBuilder = true, setterPrefix = "with") class BuilderSingularWildcardListsWithToBuilderWithSetterPrefix { private List objects; private Collection numbers; diff --git a/test/transform/resource/after-delombok/BuilderWithExistingBuilderClassWithSetterPrefix.java b/test/transform/resource/after-delombok/BuilderWithExistingBuilderClassWithSetterPrefix.java index 9b7b0c95..95f89c9d 100644 --- a/test/transform/resource/after-delombok/BuilderWithExistingBuilderClassWithSetterPrefix.java +++ b/test/transform/resource/after-delombok/BuilderWithExistingBuilderClassWithSetterPrefix.java @@ -2,7 +2,7 @@ class BuilderWithExistingBuilderClassWithSetterPrefix { public static BuilderWithExistingBuilderClassWithSetterPrefix staticMethod(Z arg1, boolean arg2, String arg3) { return null; } - public static class BuilderWithExistingBuilderClassBuilderWithSetterPrefixBuilder { + public static class BuilderWithExistingBuilderClassWithSetterPrefixBuilder { @java.lang.SuppressWarnings("all") private boolean arg2; @java.lang.SuppressWarnings("all") @@ -11,7 +11,7 @@ class BuilderWithExistingBuilderClassWithSetterPrefix { public void withArg2(boolean arg) { } @java.lang.SuppressWarnings("all") - BuilderWithExistingBuilderClassBuilderWithSetterPrefixBuilder() { + BuilderWithExistingBuilderClassWithSetterPrefixBuilder() { } @java.lang.SuppressWarnings("all") public BuilderWithExistingBuilderClassWithSetterPrefixBuilder withArg1(final Z arg1) { diff --git a/test/transform/resource/after-delombok/BuilderWithNoBuilderMethodWithSetterPrefix.java b/test/transform/resource/after-delombok/BuilderWithNoBuilderMethodWithSetterPrefix.java index 2381dcbe..0f478ed1 100644 --- a/test/transform/resource/after-delombok/BuilderWithNoBuilderMethodWithSetterPrefix.java +++ b/test/transform/resource/after-delombok/BuilderWithNoBuilderMethodWithSetterPrefix.java @@ -1,4 +1,3 @@ -import lombok.Builder class BuilderWithNoBuilderMethodWithSetterPrefix { private String a = ""; @java.lang.SuppressWarnings("all") diff --git a/test/transform/resource/after-delombok/BuilderWithToBuilderWithSetterPrefix.java b/test/transform/resource/after-delombok/BuilderWithToBuilderWithSetterPrefix.java index 091aed4d..322c667c 100644 --- a/test/transform/resource/after-delombok/BuilderWithToBuilderWithSetterPrefix.java +++ b/test/transform/resource/after-delombok/BuilderWithToBuilderWithSetterPrefix.java @@ -1,5 +1,4 @@ import java.util.List; -import lombok.Builder; class BuilderWithToBuilderWithSetterPrefix { private String mOne; private String mTwo; diff --git a/test/transform/resource/after-ecj/BuilderSimpleWithSetterPrefix.java b/test/transform/resource/after-ecj/BuilderSimpleWithSetterPrefix.java index 110774e2..993c66da 100644 --- a/test/transform/resource/after-ecj/BuilderSimpleWithSetterPrefix.java +++ b/test/transform/resource/after-ecj/BuilderSimpleWithSetterPrefix.java @@ -5,19 +5,19 @@ import java.util.List; @java.lang.SuppressWarnings("all") BuilderSimpleWithSetterPrefixBuilder() { super(); } - public @java.lang.SuppressWarnings("all") BuilderWithPrefixBuilder withUnprefixed(final int unprefixed) { + public @java.lang.SuppressWarnings("all") BuilderSimpleWithSetterPrefixBuilder withUnprefixed(final int unprefixed) { this.unprefixed = unprefixed; return this; } - public @java.lang.SuppressWarnings("all") BuilderWithPrefix build() { - return new BuilderWithPrefix(unprefixed); + public @java.lang.SuppressWarnings("all") BuilderSimpleWithSetterPrefix build() { + return new BuilderSimpleWithSetterPrefix(unprefixed); } public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { - return (("BuilderWithPrefix.BuilderWithPrefixBuilder(unprefixed=" + this.unprefixed) + ")"); + return (("BuilderSimpleWithSetterPrefix.BuilderSimpleWithSetterPrefixBuilder(unprefixed=" + this.unprefixed) + ")"); } } private int unprefixed; - @java.lang.SuppressWarnings("all") BuilderSimpleWithSetterPrefixBuilder(final int unprefixed) { + @java.lang.SuppressWarnings("all") BuilderSimpleWithSetterPrefix(final int unprefixed) { super(); this.unprefixed = unprefixed; } diff --git a/test/transform/resource/after-ecj/BuilderSingularSetsWithSetterPrefix.java b/test/transform/resource/after-ecj/BuilderSingularSetsWithSetterPrefix.java index cb5041a7..905e9190 100644 --- a/test/transform/resource/after-ecj/BuilderSingularSetsWithSetterPrefix.java +++ b/test/transform/resource/after-ecj/BuilderSingularSetsWithSetterPrefix.java @@ -10,13 +10,13 @@ import lombok.Singular; @java.lang.SuppressWarnings("all") BuilderSingularSetsWithSetterPrefixBuilder() { super(); } - public @java.lang.SuppressWarnings("all") BuilderSingularSetsWithSetterPrefixBuilder dangerMouse(final T dangerMouse) { + public @java.lang.SuppressWarnings("all") BuilderSingularSetsWithSetterPrefixBuilder withDangerMouse(final T dangerMouse) { if ((this.dangerMice == null)) this.dangerMice = new java.util.ArrayList(); this.dangerMice.add(dangerMouse); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularSetsWithSetterPrefixBuilder dangerMice(final java.util.Collection dangerMice) { + public @java.lang.SuppressWarnings("all") BuilderSingularSetsWithSetterPrefixBuilder withDangerMice(final java.util.Collection dangerMice) { if ((this.dangerMice == null)) this.dangerMice = new java.util.ArrayList(); this.dangerMice.addAll(dangerMice); @@ -27,13 +27,13 @@ import lombok.Singular; this.dangerMice.clear(); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularSetsWithSetterPrefixBuilder octopus(final Number octopus) { + public @java.lang.SuppressWarnings("all") BuilderSingularSetsWithSetterPrefixBuilder withOctopus(final Number octopus) { if ((this.octopodes == null)) this.octopodes = new java.util.ArrayList(); this.octopodes.add(octopus); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularSetsWithSetterPrefixBuilder octopodes(final java.util.Collection octopodes) { + public @java.lang.SuppressWarnings("all") BuilderSingularSetsWithSetterPrefixBuilder withOctopodes(final java.util.Collection octopodes) { if ((this.octopodes == null)) this.octopodes = new java.util.ArrayList(); this.octopodes.addAll(octopodes); @@ -44,13 +44,13 @@ import lombok.Singular; this.octopodes.clear(); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularSetsWithSetterPrefixBuilder rawSet(final java.lang.Object rawSet) { + public @java.lang.SuppressWarnings("all") BuilderSingularSetsWithSetterPrefixBuilder withRawSet(final java.lang.Object rawSet) { if ((this.rawSet == null)) this.rawSet = new java.util.ArrayList(); this.rawSet.add(rawSet); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularSetsWithSetterPrefixBuilder rawSet(final java.util.Collection rawSet) { + public @java.lang.SuppressWarnings("all") BuilderSingularSetsWithSetterPrefixBuilder withRawSet(final java.util.Collection rawSet) { if ((this.rawSet == null)) this.rawSet = new java.util.ArrayList(); this.rawSet.addAll(rawSet); @@ -61,13 +61,13 @@ import lombok.Singular; this.rawSet.clear(); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularSetsWithSetterPrefixBuilder stringSet(final String stringSet) { + public @java.lang.SuppressWarnings("all") BuilderSingularSetsWithSetterPrefixBuilder withStringSet(final String stringSet) { if ((this.stringSet == null)) this.stringSet = new java.util.ArrayList(); this.stringSet.add(stringSet); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularSetsWithSetterPrefixBuilder stringSet(final java.util.Collection stringSet) { + public @java.lang.SuppressWarnings("all") BuilderSingularSetsWithSetterPrefixBuilder withStringSet(final java.util.Collection stringSet) { if ((this.stringSet == null)) this.stringSet = new java.util.ArrayList(); this.stringSet.addAll(stringSet); diff --git a/test/transform/resource/after-ecj/BuilderSingularWithPrefixesWithSetterPrefix.java b/test/transform/resource/after-ecj/BuilderSingularWithPrefixesWithSetterPrefix.java index 920803cc..f3218f27 100644 --- a/test/transform/resource/after-ecj/BuilderSingularWithPrefixesWithSetterPrefix.java +++ b/test/transform/resource/after-ecj/BuilderSingularWithPrefixesWithSetterPrefix.java @@ -22,7 +22,7 @@ import lombok.Singular; this.elems.clear(); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularWithPrefixesWithSetterPrefixes build() { + public @java.lang.SuppressWarnings("all") BuilderSingularWithPrefixesWithSetterPrefix build() { java.util.List elems; switch (((this.elems == null) ? 0 : this.elems.size())) { case 0 : @@ -34,14 +34,14 @@ import lombok.Singular; default : elems = java.util.Collections.unmodifiableList(new java.util.ArrayList(this.elems)); } - return new BuilderSingularWithPrefixesWithSetterPrefixes(elems); + return new BuilderSingularWithPrefixesWithSetterPrefix(elems); } public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { - return (("BuilderSingularWithPrefixesWithSetterPrefixes.BuilderSingularWithPrefixesWithSetterPrefixBuilder(elems=" + this.elems) + ")"); + return (("BuilderSingularWithPrefixesWithSetterPrefix.BuilderSingularWithPrefixesWithSetterPrefixBuilder(elems=" + this.elems) + ")"); } } private @Singular java.util.List _elems; - @java.lang.SuppressWarnings("all") BuilderSingularWithPrefixesWithSetterPrefixes(final java.util.List elems) { + @java.lang.SuppressWarnings("all") BuilderSingularWithPrefixesWithSetterPrefix(final java.util.List elems) { super(); this._elems = elems; } diff --git a/test/transform/resource/after-ecj/BuilderWithExistingBuilderClassWithSetterPrefix.java b/test/transform/resource/after-ecj/BuilderWithExistingBuilderClassWithSetterPrefix.java index b14c120f..8da2f012 100644 --- a/test/transform/resource/after-ecj/BuilderWithExistingBuilderClassWithSetterPrefix.java +++ b/test/transform/resource/after-ecj/BuilderWithExistingBuilderClassWithSetterPrefix.java @@ -1,6 +1,6 @@ import lombok.Builder; class BuilderWithExistingBuilderClassWithSetterPrefix { - public static class BuilderWithExistingBuilderClassBuilderWithSetterPrefixBuilder { + public static class BuilderWithExistingBuilderClassWithSetterPrefixBuilder { private @java.lang.SuppressWarnings("all") boolean arg2; private @java.lang.SuppressWarnings("all") String arg3; private Z arg1; diff --git a/test/transform/resource/after-ecj/BuilderWithRecursiveGenericsWithSetterPrefix.java b/test/transform/resource/after-ecj/BuilderWithRecursiveGenericsWithSetterPrefix.java index 2ce25b0a..7c5b191d 100644 --- a/test/transform/resource/after-ecj/BuilderWithRecursiveGenericsWithSetterPrefix.java +++ b/test/transform/resource/after-ecj/BuilderWithRecursiveGenericsWithSetterPrefix.java @@ -4,7 +4,7 @@ import lombok.Value; public class BuilderWithRecursiveGenericsWithSetterPrefix { interface Inter> { } - public static final @Builder(setterPrefix = "with(setterPrefix = "with")") @Value class Test, Quz extends Inter> { + public static final @Builder(setterPrefix = "with") @Value class Test, Quz extends Inter> { public static @java.lang.SuppressWarnings("all") class TestBuilder, Quz extends Inter> { private @java.lang.SuppressWarnings("all") Foo foo; private @java.lang.SuppressWarnings("all") Bar bar; diff --git a/test/transform/resource/after-ecj/BuilderWithToBuilderWithSetterPrefix.java b/test/transform/resource/after-ecj/BuilderWithToBuilderWithSetterPrefix.java index c33315a4..6f3906d9 100644 --- a/test/transform/resource/after-ecj/BuilderWithToBuilderWithSetterPrefix.java +++ b/test/transform/resource/after-ecj/BuilderWithToBuilderWithSetterPrefix.java @@ -80,44 +80,45 @@ import lombok.Builder; return builder; } } -@lombok.experimental.Accessors(prefix = "m") class ConstructorWithToBuilder { - public static @java.lang.SuppressWarnings("all") class ConstructorWithToBuilderBuilder { + +@lombok.experimental.Accessors(prefix = "m") class ConstructorWithToBuilderWithSetterPrefix { + public static @java.lang.SuppressWarnings("all") class ConstructorWithToBuilderWithSetterPrefixBuilder { private @java.lang.SuppressWarnings("all") String mOne; private @java.lang.SuppressWarnings("all") T baz; private @java.lang.SuppressWarnings("all") com.google.common.collect.ImmutableList bars; - @java.lang.SuppressWarnings("all") ConstructorWithToBuilderBuilder() { + @java.lang.SuppressWarnings("all") ConstructorWithToBuilderWithSetterPrefixBuilder() { super(); } - public @java.lang.SuppressWarnings("all") ConstructorWithToBuilderBuilder withMOne(final String mOne) { + public @java.lang.SuppressWarnings("all") ConstructorWithToBuilderWithSetterPrefixBuilder withMOne(final String mOne) { this.mOne = mOne; return this; } - public @java.lang.SuppressWarnings("all") ConstructorWithToBuilderBuilder withBaz(final T baz) { + public @java.lang.SuppressWarnings("all") ConstructorWithToBuilderWithSetterPrefixBuilder withBaz(final T baz) { this.baz = baz; return this; } - public @java.lang.SuppressWarnings("all") ConstructorWithToBuilderBuilder withBars(final com.google.common.collect.ImmutableList bars) { + public @java.lang.SuppressWarnings("all") ConstructorWithToBuilderWithSetterPrefixBuilder withBars(final com.google.common.collect.ImmutableList bars) { this.bars = bars; return this; } - public @java.lang.SuppressWarnings("all") ConstructorWithToBuilder build() { - return new ConstructorWithToBuilder(mOne, baz, bars); + public @java.lang.SuppressWarnings("all") ConstructorWithToBuilderWithSetterPrefix build() { + return new ConstructorWithToBuilderWithSetterPrefix(mOne, baz, bars); } public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { - return (((((("ConstructorWithToBuilder.ConstructorWithToBuilderBuilder(mOne=" + this.mOne) + ", baz=") + this.baz) + ", bars=") + this.bars) + ")"); + return (((((("ConstructorWithToBuilderWithSetterPrefix.ConstructorWithToBuilderWithSetterPrefixBuilder(mOne=" + this.mOne) + ", baz=") + this.baz) + ", bars=") + this.bars) + ")"); } } private String mOne; private String mTwo; private T foo; private @lombok.Singular com.google.common.collect.ImmutableList bars; - public @Builder(toBuilder = true) ConstructorWithToBuilder(String mOne, @Builder.ObtainVia(field = "foo") T baz, com.google.common.collect.ImmutableList bars) { + public @Builder(toBuilder = true,setterPrefix = "with") ConstructorWithToBuilderWithSetterPrefix(String mOne, @Builder.ObtainVia(field = "foo") T baz, com.google.common.collect.ImmutableList bars) { super(); } - public static @java.lang.SuppressWarnings("all") ConstructorWithToBuilderBuilder builder() { - return new ConstructorWithToBuilderBuilder(); + public static @java.lang.SuppressWarnings("all") ConstructorWithToBuilderWithSetterPrefixBuilder builder() { + return new ConstructorWithToBuilderWithSetterPrefixBuilder(); } - public @java.lang.SuppressWarnings("all") ConstructorWithToBuilderBuilder toBuilder() { - return new ConstructorWithToBuilderBuilder().withMOne(this.mOne).withBaz(this.foo).withBars(this.bars); + public @java.lang.SuppressWarnings("all") ConstructorWithToBuilderWithSetterPrefixBuilder toBuilder() { + return new ConstructorWithToBuilderWithSetterPrefixBuilder().withMOne(this.mOne).withBaz(this.foo).withBars(this.bars); } } diff --git a/test/transform/resource/before/BuilderWithNoBuilderMethodWithSetterPrefix.java b/test/transform/resource/before/BuilderWithNoBuilderMethodWithSetterPrefix.java index 6fddd748..80197dd3 100644 --- a/test/transform/resource/before/BuilderWithNoBuilderMethodWithSetterPrefix.java +++ b/test/transform/resource/before/BuilderWithNoBuilderMethodWithSetterPrefix.java @@ -1,4 +1,4 @@ -import lombok.Builder +import lombok.Builder; @Builder(toBuilder = true, builderMethodName = "",setterPrefix = "with") class BuilderWithNoBuilderMethodWithSetterPrefix { private String a = ""; diff --git a/test/transform/resource/before/BuilderWithToBuilderWithSetterPrefix.java b/test/transform/resource/before/BuilderWithToBuilderWithSetterPrefix.java index b33211e9..3b442b8d 100644 --- a/test/transform/resource/before/BuilderWithToBuilderWithSetterPrefix.java +++ b/test/transform/resource/before/BuilderWithToBuilderWithSetterPrefix.java @@ -5,7 +5,7 @@ class BuilderWithToBuilderWithSetterPrefix { private String mOne, mTwo; @Builder.ObtainVia(method = "rrr", isStatic = true) private T foo; @lombok.Singular private List bars; - public static K rrr(BuilderWithToBuilder x) { + public static K rrr(BuilderWithToBuilderWithSetterPrefix x) { return x.foo; } } @@ -15,6 +15,6 @@ class ConstructorWithToBuilderWithSetterPrefix { private T foo; @lombok.Singular private com.google.common.collect.ImmutableList bars; @Builder(toBuilder = true, setterPrefix = "with") - public ConstructorWithToBuilder(String mOne, @Builder.ObtainVia(field = "foo") T baz, com.google.common.collect.ImmutableList bars) { + public ConstructorWithToBuilderWithSetterPrefix(String mOne, @Builder.ObtainVia(field = "foo") T baz, com.google.common.collect.ImmutableList bars) { } } diff --git a/test/transform/resource/before/BuilderWithTolerateWithSetterPrefix.java b/test/transform/resource/before/BuilderWithTolerateWithSetterPrefix.java index fa7c0298..5c77e177 100644 --- a/test/transform/resource/before/BuilderWithTolerateWithSetterPrefix.java +++ b/test/transform/resource/before/BuilderWithTolerateWithSetterPrefix.java @@ -12,7 +12,7 @@ public class BuilderWithTolerateWithSetterPrefix { public static class BuilderWithTolerateWithSetterPrefixBuilder { @Tolerate public BuilderWithTolerateWithSetterPrefixBuilder withValue(String s) { - return this.value(Integer.parseInt(s)); + return this.withValue(Integer.parseInt(s)); } } } -- cgit From 65302bc13a1ab670dac552e2214989c7381f71a8 Mon Sep 17 00:00:00 2001 From: Caleb Brinkman Date: Mon, 28 Oct 2019 12:09:15 -0500 Subject: More test fixes --- src/core/lombok/eclipse/handlers/HandleBuilder.java | 12 ++++++------ .../BuilderWithExistingBuilderClassWithSetterPrefix.java | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/core/lombok/eclipse/handlers/HandleBuilder.java b/src/core/lombok/eclipse/handlers/HandleBuilder.java index 017cde17..70b07fb8 100755 --- a/src/core/lombok/eclipse/handlers/HandleBuilder.java +++ b/src/core/lombok/eclipse/handlers/HandleBuilder.java @@ -931,12 +931,6 @@ public class HandleBuilder extends EclipseAnnotationHandler { FieldDeclaration fd = (FieldDeclaration) fieldNode.get(); char[] name = fd.name; - for (int i = 0; i < len; i++) { - if (!(existing[i] instanceof MethodDeclaration)) continue; - char[] existingName = existing[i].selector; - if (Arrays.equals(name, existingName) && !isTolerate(fieldNode, existing[i])) return; - } - String setterPrefix = prefix.isEmpty() ? "set" : prefix; String setterName; if(fluent) { @@ -945,6 +939,12 @@ public class HandleBuilder extends EclipseAnnotationHandler { setterName = HandlerUtil.buildAccessorName(setterPrefix, new String(paramName)); } + for (int i = 0; i < len; i++) { + if (!(existing[i] instanceof MethodDeclaration)) continue; + char[] existingName = existing[i].selector; + if (Arrays.equals(setterName.toCharArray(), existingName) && !isTolerate(fieldNode, existing[i])) return; + } + List methodAnnsList = Collections.emptyList(); Annotation[] methodAnns = EclipseHandlerUtil.findCopyableToSetterAnnotations(originalFieldNode); if (methodAnns != null && methodAnns.length > 0) methodAnnsList = Arrays.asList(methodAnns); diff --git a/test/transform/resource/before/BuilderWithExistingBuilderClassWithSetterPrefix.java b/test/transform/resource/before/BuilderWithExistingBuilderClassWithSetterPrefix.java index 99c3ccc6..e30dd1ff 100644 --- a/test/transform/resource/before/BuilderWithExistingBuilderClassWithSetterPrefix.java +++ b/test/transform/resource/before/BuilderWithExistingBuilderClassWithSetterPrefix.java @@ -6,7 +6,7 @@ class BuilderWithExistingBuilderClassWithSetterPrefix { return null; } - public static class BuilderWithExistingBuilderClassBuilderWithSetterPrefixBuilder { + public static class BuilderWithExistingBuilderClassWithSetterPrefixBuilder { private Z arg1; public void withArg2(boolean arg) { -- cgit From 7a8bc61bae5f807887bce9a2cbfaed8afea8a588 Mon Sep 17 00:00:00 2001 From: Caleb Brinkman Date: Mon, 28 Oct 2019 12:13:11 -0500 Subject: Remove now-unused variables --- src/core/lombok/eclipse/handlers/HandleBuilder.java | 2 -- 1 file changed, 2 deletions(-) (limited to 'src') diff --git a/src/core/lombok/eclipse/handlers/HandleBuilder.java b/src/core/lombok/eclipse/handlers/HandleBuilder.java index 70b07fb8..63eb60a3 100755 --- a/src/core/lombok/eclipse/handlers/HandleBuilder.java +++ b/src/core/lombok/eclipse/handlers/HandleBuilder.java @@ -928,8 +928,6 @@ public class HandleBuilder extends EclipseAnnotationHandler { AbstractMethodDeclaration[] existing = td.methods; if (existing == null) existing = EMPTY; int len = existing.length; - FieldDeclaration fd = (FieldDeclaration) fieldNode.get(); - char[] name = fd.name; String setterPrefix = prefix.isEmpty() ? "set" : prefix; String setterName; -- cgit From 2a7afbc1d1f450dec98b224ffd990a7a972d770a Mon Sep 17 00:00:00 2001 From: Caleb Brinkman Date: Mon, 28 Oct 2019 12:43:43 -0500 Subject: Fix more singulars and tests --- src/core/lombok/eclipse/handlers/HandleBuilder.java | 1 - .../eclipse/handlers/singulars/EclipseGuavaSingularizer.java | 6 ++++-- src/core/lombok/javac/handlers/HandleBuilder.java | 12 +++++++++--- 3 files changed, 13 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/core/lombok/eclipse/handlers/HandleBuilder.java b/src/core/lombok/eclipse/handlers/HandleBuilder.java index 63eb60a3..aab97e18 100755 --- a/src/core/lombok/eclipse/handlers/HandleBuilder.java +++ b/src/core/lombok/eclipse/handlers/HandleBuilder.java @@ -568,7 +568,6 @@ public class HandleBuilder extends EclipseAnnotationHandler { List statements = null; for (BuilderFieldData bfd : builderFields) { String setterPrefix = prefix.isEmpty() ? "set" : prefix; - //char[] setterName = fluent ? bfd.name : HandlerUtil.buildAccessorName("set", new String(bfd.name)).toCharArray(); String setterName; if(fluent) { setterName = prefix.isEmpty() ? new String(bfd.name) : HandlerUtil.buildAccessorName(setterPrefix, new String(bfd.name)); diff --git a/src/core/lombok/eclipse/handlers/singulars/EclipseGuavaSingularizer.java b/src/core/lombok/eclipse/handlers/singulars/EclipseGuavaSingularizer.java index 338f5eab..8f80d228 100755 --- a/src/core/lombok/eclipse/handlers/singulars/EclipseGuavaSingularizer.java +++ b/src/core/lombok/eclipse/handlers/singulars/EclipseGuavaSingularizer.java @@ -172,7 +172,8 @@ abstract class EclipseGuavaSingularizer extends EclipseSingularizer { md.arguments[i].annotations = typeUseAnns; } md.returnType = returnType; - md.selector = fluent ? data.getSingularName() : HandlerUtil.buildAccessorName(getAddMethodName(), new String(data.getSingularName())).toCharArray(); + char[] prefixedSingularName = data.getSetterPrefix().length == 0 ? data.getSingularName() : HandlerUtil.buildAccessorName(new String(data.getSetterPrefix()), new String(data.getSingularName())).toCharArray(); + md.selector = fluent ? prefixedSingularName : HandlerUtil.buildAccessorName("add", new String(data.getSingularName())).toCharArray(); md.annotations = generateSelfReturnAnnotations(deprecate, cfv, data.getSource()); data.setGeneratedByRecursive(md); @@ -204,7 +205,8 @@ abstract class EclipseGuavaSingularizer extends EclipseSingularizer { Argument param = new Argument(data.getPluralName(), 0, paramType, ClassFileConstants.AccFinal); md.arguments = new Argument[] {param}; md.returnType = returnType; - md.selector = fluent ? data.getPluralName() : HandlerUtil.buildAccessorName(getAddMethodName() + "All", new String(data.getPluralName())).toCharArray(); + char[] prefixedSelector = data.getSetterPrefix().length == 0 ? data.getPluralName() : HandlerUtil.buildAccessorName(new String(data.getSetterPrefix()), new String(data.getPluralName())).toCharArray(); + md.selector = fluent ? prefixedSelector : HandlerUtil.buildAccessorName("addAll", new String(data.getPluralName())).toCharArray(); md.annotations = generateSelfReturnAnnotations(deprecate, cfv, data.getSource()); data.setGeneratedByRecursive(md); diff --git a/src/core/lombok/javac/handlers/HandleBuilder.java b/src/core/lombok/javac/handlers/HandleBuilder.java index f199f161..a7235a40 100644 --- a/src/core/lombok/javac/handlers/HandleBuilder.java +++ b/src/core/lombok/javac/handlers/HandleBuilder.java @@ -487,7 +487,7 @@ public class HandleBuilder extends JavacAnnotationHandler { } tps = lb.toList(); } - JCMethodDecl md = generateToBuilderMethod(cfv, toBuilderMethodName, builderClassName, tdParent, tps, builderFields, fluent, ast, accessForOuters); + JCMethodDecl md = generateToBuilderMethod(cfv, toBuilderMethodName, builderClassName, tdParent, tps, builderFields, fluent, ast, accessForOuters, builderInstance.setterPrefix()); if (md != null) { recursiveSetGeneratedBy(md, ast, annotationNode.getContext()); injectMethod(tdParent, md); @@ -536,7 +536,7 @@ public class HandleBuilder extends JavacAnnotationHandler { } private static final String BUILDER_TEMP_VAR = "builder"; - private JCMethodDecl generateToBuilderMethod(CheckerFrameworkVersion cfv, String toBuilderMethodName, String builderClassName, JavacNode type, List typeParams, java.util.List builderFields, boolean fluent, JCAnnotation ast, AccessLevel access) { + private JCMethodDecl generateToBuilderMethod(CheckerFrameworkVersion cfv, String toBuilderMethodName, String builderClassName, JavacNode type, List typeParams, java.util.List builderFields, boolean fluent, JCAnnotation ast, AccessLevel access, String prefix) { // return new ThingieBuilder().setA(this.a).setB(this.b); JavacTreeMaker maker = type.getTreeMaker(); @@ -549,7 +549,13 @@ public class HandleBuilder extends JavacAnnotationHandler { JCExpression invoke = call; ListBuffer statements = new ListBuffer(); for (BuilderFieldData bfd : builderFields) { - Name setterName = fluent ? bfd.name : type.toName(HandlerUtil.buildAccessorName("set", bfd.name.toString())); + String prefixedSetterName; + if(fluent) { + prefixedSetterName = prefix.isEmpty() ? bfd.name.toString() : HandlerUtil.buildAccessorName(prefix, bfd.name.toString()); + } else { + prefixedSetterName = HandlerUtil.buildAccessorName(prefix, bfd.name.toString()); + } + Name setterName = type.toName(prefixedSetterName); JCExpression[] tgt = new JCExpression[bfd.singularData == null ? 1 : 2]; if (bfd.obtainVia == null || !bfd.obtainVia.field().isEmpty()) { for (int i = 0; i < tgt.length; i++) { -- cgit From 1b0c2f34a50531e2af4d8c88ff196a9526e00ac8 Mon Sep 17 00:00:00 2001 From: Caleb Brinkman Date: Mon, 28 Oct 2019 13:41:13 -0500 Subject: Fix eclipse map singularization --- .../singulars/EclipseJavaUtilMapSingularizer.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilMapSingularizer.java b/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilMapSingularizer.java index 8684987f..4ceafd1e 100755 --- a/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilMapSingularizer.java +++ b/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilMapSingularizer.java @@ -28,6 +28,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.logging.Handler; import org.eclipse.jdt.internal.compiler.ast.Annotation; import org.eclipse.jdt.internal.compiler.ast.Argument; @@ -62,6 +63,7 @@ import lombok.eclipse.handlers.EclipseSingularsRecipes.SingularData; import lombok.eclipse.handlers.EclipseSingularsRecipes.StatementMaker; import lombok.eclipse.handlers.EclipseSingularsRecipes.TypeReferenceMaker; import lombok.eclipse.handlers.HandleNonNull; +import org.objectweb.asm.Handle; @ProviderFor(EclipseSingularizer.class) public class EclipseJavaUtilMapSingularizer extends EclipseJavaUtilSingularizer { @@ -245,7 +247,13 @@ public class EclipseJavaUtilMapSingularizer extends EclipseJavaUtilSingularizer valueParam.annotations = typeUseAnnsValue; md.arguments = new Argument[] {keyParam, valueParam}; md.returnType = returnType; - md.selector = fluent ? data.getSingularName() : HandlerUtil.buildAccessorName("put", new String(data.getSingularName())).toCharArray(); + + String name = new String(data.getSingularName()); + String setterPrefix = new String(data.getSetterPrefix()); + String prefixedSingularName = setterPrefix.isEmpty() ? name : HandlerUtil.buildAccessorName(setterPrefix, name); + String setterName = fluent ? prefixedSingularName : HandlerUtil.buildAccessorName("put", name); + + md.selector = setterName.toCharArray(); md.annotations = generateSelfReturnAnnotations(deprecate, cfv, data.getSource()); data.setGeneratedByRecursive(md); @@ -309,7 +317,13 @@ public class EclipseJavaUtilMapSingularizer extends EclipseJavaUtilSingularizer Argument param = new Argument(data.getPluralName(), 0, paramType, ClassFileConstants.AccFinal); md.arguments = new Argument[] {param}; md.returnType = returnType; - md.selector = fluent ? data.getPluralName() : HandlerUtil.buildAccessorName("putAll", new String(data.getPluralName())).toCharArray(); + + String name = new String(data.getPluralName()); + String setterPrefix = new String(data.getSetterPrefix()); + String prefixedSingularName = setterPrefix.isEmpty() ? name : HandlerUtil.buildAccessorName(setterPrefix, name); + String setterName = fluent ? prefixedSingularName : HandlerUtil.buildAccessorName("put", name); + + md.selector = setterName.toCharArray(); md.annotations = generateSelfReturnAnnotations(deprecate, cfv, data.getSource()); data.setGeneratedByRecursive(md); -- cgit From b7e42d13ea98e280914f09f91fc03f355ea9682b Mon Sep 17 00:00:00 2001 From: Caleb Brinkman Date: Mon, 28 Oct 2019 13:48:59 -0500 Subject: Fix last test --- src/core/lombok/javac/handlers/HandleBuilder.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/HandleBuilder.java b/src/core/lombok/javac/handlers/HandleBuilder.java index a7235a40..46cb9b9a 100644 --- a/src/core/lombok/javac/handlers/HandleBuilder.java +++ b/src/core/lombok/javac/handlers/HandleBuilder.java @@ -826,13 +826,6 @@ public class HandleBuilder extends JavacAnnotationHandler { private void makePrefixedSetterMethodForBuilder(CheckerFrameworkVersion cfv, JavacNode builderType, boolean deprecate, JavacNode fieldNode, Name paramName, Name nameOfSetFlag, JavacNode source, boolean fluent, boolean chain, List annosOnParam, JavacNode originalFieldNode, AccessLevel access, String prefix) { Name fieldName = ((JCVariableDecl) fieldNode.get()).name; - for (JavacNode child : builderType.down()) { - if (child.getKind() != Kind.METHOD) continue; - JCMethodDecl methodDecl = (JCMethodDecl) child.get(); - Name existingName = methodDecl.name; - if (existingName.equals(fieldName) && !isTolerate(fieldNode, methodDecl)) return; - } - String setterPrefix = prefix.isEmpty() ? "set" : prefix; String setterName; if(fluent) { @@ -841,6 +834,13 @@ public class HandleBuilder extends JavacAnnotationHandler { setterName = HandlerUtil.buildAccessorName(setterPrefix, paramName.toString()); } + for (JavacNode child : builderType.down()) { + if (child.getKind() != Kind.METHOD) continue; + JCMethodDecl methodDecl = (JCMethodDecl) child.get(); + Name existingName = methodDecl.name; + if (existingName.equals(builderType.toName(setterName)) && !isTolerate(fieldNode, methodDecl)) return; + } + JavacTreeMaker maker = fieldNode.getTreeMaker(); List methodAnns = JavacHandlerUtil.findCopyableToSetterAnnotations(originalFieldNode); -- cgit From 35f9a8360e06a628823eae38a82b65b8bf1f5926 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Wed, 11 Dec 2019 00:44:52 +0100 Subject: [trivial] formatting --- .../lombok/eclipse/handlers/HandleBuilder.java | 250 ++++++++++----------- 1 file changed, 125 insertions(+), 125 deletions(-) (limited to 'src') diff --git a/src/core/lombok/eclipse/handlers/HandleBuilder.java b/src/core/lombok/eclipse/handlers/HandleBuilder.java index aab97e18..40098eb4 100755 --- a/src/core/lombok/eclipse/handlers/HandleBuilder.java +++ b/src/core/lombok/eclipse/handlers/HandleBuilder.java @@ -101,17 +101,17 @@ import lombok.experimental.NonFinal; @HandlerPriority(-1024) //-2^10; to ensure we've picked up @FieldDefault's changes (-2048) but @Value hasn't removed itself yet (-512), so that we can error on presence of it on the builder classes. public class HandleBuilder extends EclipseAnnotationHandler { private HandleConstructor handleConstructor = new HandleConstructor(); - + private static final char[] CLEAN_FIELD_NAME = "$lombokUnclean".toCharArray(); private static final char[] CLEAN_METHOD_NAME = "$lombokClean".toCharArray(); - + private static final boolean toBoolean(Object expr, boolean defaultValue) { if (expr == null) return defaultValue; if (expr instanceof FalseLiteral) return false; if (expr instanceof TrueLiteral) return true; return ((Boolean) expr).booleanValue(); } - + static class BuilderFieldData { Annotation[] annotations; TypeReference type; @@ -124,10 +124,10 @@ public class HandleBuilder extends EclipseAnnotationHandler { ObtainVia obtainVia; EclipseNode obtainViaNode; EclipseNode originalFieldNode; - + List createdFields = new ArrayList(); } - + private static boolean equals(String a, char[] b) { if (a.length() != b.length) return false; for (int i = 0; i < b.length; i++) { @@ -135,7 +135,7 @@ public class HandleBuilder extends EclipseAnnotationHandler { } return true; } - + private static boolean equals(String a, char[][] b) { if (a == null || a.isEmpty()) return b.length == 0; String[] aParts = a.split("\\."); @@ -145,24 +145,24 @@ public class HandleBuilder extends EclipseAnnotationHandler { } return true; } - + private static final char[] DEFAULT_PREFIX = {'$', 'd', 'e', 'f', 'a', 'u', 'l', 't', '$'}; private static final char[] SET_PREFIX = {'$', 's', 'e', 't'}; private static final char[] VALUE_PREFIX = {'$', 'v', 'a', 'l', 'u', 'e'}; - + private static final char[] prefixWith(char[] prefix, char[] name) { char[] out = new char[prefix.length + name.length]; System.arraycopy(prefix, 0, out, 0, prefix.length); System.arraycopy(name, 0, out, prefix.length, name.length); return out; } - + @Override public void handle(AnnotationValues annotation, Annotation ast, EclipseNode annotationNode) { handleFlagUsage(annotationNode, ConfigurationKeys.BUILDER_FLAG_USAGE, "@Builder"); CheckerFrameworkVersion cfv = getCheckerFrameworkVersion(annotationNode); - + long p = (long) ast.sourceStart << 32 | ast.sourceEnd; - + Builder builderInstance = annotation.getInstance(); AccessLevel accessForOuters = builderInstance.access(); if (accessForOuters == null) accessForOuters = AccessLevel.PUBLIC; @@ -171,22 +171,22 @@ public class HandleBuilder extends EclipseAnnotationHandler { accessForOuters = AccessLevel.PUBLIC; } AccessLevel accessForInners = accessForOuters == AccessLevel.PROTECTED ? AccessLevel.PUBLIC : accessForOuters; - + // These exist just to support the 'old' lombok.experimental.Builder, which had these properties. lombok.Builder no longer has them. boolean fluent = toBoolean(annotation.getActualExpression("fluent"), true); boolean chain = toBoolean(annotation.getActualExpression("chain"), true); - + String builderMethodName = builderInstance.builderMethodName(); String buildMethodName = builderInstance.buildMethodName(); String builderClassName = builderInstance.builderClassName(); String toBuilderMethodName = "toBuilder"; boolean toBuilder = builderInstance.toBuilder(); List typeArgsForToBuilder = null; - + if (builderMethodName == null) builderMethodName = "builder"; if (buildMethodName == null) buildMethodName = "build"; if (builderClassName == null) builderClassName = ""; - + boolean generateBuilderMethod; if (builderMethodName.isEmpty()) { generateBuilderMethod = false; @@ -195,44 +195,44 @@ public class HandleBuilder extends EclipseAnnotationHandler { } else { generateBuilderMethod = true; } - + if (!checkName("buildMethodName", buildMethodName, annotationNode)) return; if (!builderClassName.isEmpty()) { if (!checkName("builderClassName", builderClassName, annotationNode)) return; } - + EclipseNode parent = annotationNode.up(); - + List builderFields = new ArrayList(); TypeReference returnType; TypeParameter[] typeParams; TypeReference[] thrownExceptions; char[] nameOfStaticBuilderMethod; EclipseNode tdParent; - + EclipseNode fillParametersFrom = parent.get() instanceof AbstractMethodDeclaration ? parent : null; boolean addCleaning = false; boolean isStatic = true; - + List nonFinalNonDefaultedFields = null; - + if (builderClassName.isEmpty()) builderClassName = annotationNode.getAst().readConfiguration(ConfigurationKeys.BUILDER_CLASS_NAME); if (builderClassName == null || builderClassName.isEmpty()) builderClassName = "*Builder"; boolean replaceNameInBuilderClassName = builderClassName.contains("*"); - + if (parent.get() instanceof TypeDeclaration) { tdParent = parent; TypeDeclaration td = (TypeDeclaration) tdParent.get(); - + List allFields = new ArrayList(); boolean valuePresent = (hasAnnotation(lombok.Value.class, parent) || hasAnnotation("lombok.experimental.Value", parent)); for (EclipseNode fieldNode : HandleConstructor.findAllFields(tdParent, true)) { FieldDeclaration fd = (FieldDeclaration) fieldNode.get(); EclipseNode isDefault = findAnnotation(Builder.Default.class, fieldNode); boolean isFinal = ((fd.modifiers & ClassFileConstants.AccFinal) != 0) || (valuePresent && !hasAnnotation(NonFinal.class, fieldNode)); - + Annotation[] copyableAnnotations = findCopyableAnnotations(fieldNode); - + BuilderFieldData bfd = new BuilderFieldData(); bfd.rawName = fieldNode.getName().toCharArray(); bfd.name = removePrefixFromField(fieldNode); @@ -241,28 +241,28 @@ public class HandleBuilder extends EclipseAnnotationHandler { bfd.type = fd.type; bfd.singularData = getSingularData(fieldNode, ast, builderInstance.setterPrefix()); bfd.originalFieldNode = fieldNode; - + if (bfd.singularData != null && isDefault != null) { isDefault.addError("@Builder.Default and @Singular cannot be mixed."); isDefault = null; } - + if (fd.initialization == null && isDefault != null) { isDefault.addWarning("@Builder.Default requires an initializing expression (' = something;')."); isDefault = null; } - + if (fd.initialization != null && isDefault == null) { if (isFinal) continue; if (nonFinalNonDefaultedFields == null) nonFinalNonDefaultedFields = new ArrayList(); nonFinalNonDefaultedFields.add(fieldNode); } - + if (isDefault != null) { bfd.nameOfDefaultProvider = prefixWith(DEFAULT_PREFIX, bfd.name); bfd.nameOfSetFlag = prefixWith(bfd.name, SET_PREFIX); bfd.builderFieldName = prefixWith(bfd.name, VALUE_PREFIX); - + MethodDeclaration md = generateDefaultProvider(bfd.nameOfDefaultProvider, td.typeParameters, fieldNode, ast); if (md != null) injectMethod(tdParent, md); } @@ -270,10 +270,10 @@ public class HandleBuilder extends EclipseAnnotationHandler { builderFields.add(bfd); allFields.add(fieldNode); } - + handleConstructor.generateConstructor(tdParent, AccessLevel.PACKAGE, allFields, false, null, SkipIfConstructorExists.I_AM_BUILDER, Collections.emptyList(), annotationNode); - + returnType = namePlusTypeParamsToTypeReference(td.name, td.typeParameters, p); typeParams = td.typeParameters; thrownExceptions = null; @@ -286,7 +286,7 @@ public class HandleBuilder extends EclipseAnnotationHandler { annotationNode.addError("@Builder is not supported on constructors with constructor type parameters."); return; } - + tdParent = parent.up(); TypeDeclaration td = (TypeDeclaration) tdParent.get(); returnType = namePlusTypeParamsToTypeReference(td.name, td.typeParameters, p); @@ -299,7 +299,7 @@ public class HandleBuilder extends EclipseAnnotationHandler { MethodDeclaration md = (MethodDeclaration) parent.get(); tdParent = parent.up(); isStatic = md.isStatic(); - + if (toBuilder) { final String TO_BUILDER_NOT_SUPPORTED = "@Builder(toBuilder=true) is only supported if you return your own type."; char[] token; @@ -308,7 +308,7 @@ public class HandleBuilder extends EclipseAnnotationHandler { annotationNode.addError(TO_BUILDER_NOT_SUPPORTED); return; } - + if (md.returnType instanceof SingleTypeReference) { token = ((SingleTypeReference) md.returnType).token; } else if (md.returnType instanceof QualifiedTypeReference) { @@ -321,17 +321,17 @@ public class HandleBuilder extends EclipseAnnotationHandler { annotationNode.addError(TO_BUILDER_NOT_SUPPORTED); return; } - + if (pkg != null && !equals(parent.getPackageDeclaration(), pkg)) { annotationNode.addError(TO_BUILDER_NOT_SUPPORTED); return; } - + if (tdParent == null || !equals(tdParent.getName(), token)) { annotationNode.addError(TO_BUILDER_NOT_SUPPORTED); return; } - + TypeParameter[] tpOnType = ((TypeDeclaration) tdParent.get()).typeParameters; TypeParameter[] tpOnMethod = md.typeParameters; TypeReference[][] tpOnRet_ = null; @@ -341,7 +341,7 @@ public class HandleBuilder extends EclipseAnnotationHandler { } else if (md.returnType instanceof ParameterizedQualifiedTypeReference) { tpOnRet_ = ((ParameterizedQualifiedTypeReference) md.returnType).typeArguments; } - + if (tpOnRet_ != null) for (int i = 0; i < tpOnRet_.length - 1; i++) { if (tpOnRet_[i] != null && tpOnRet_[i].length > 0) { annotationNode.addError("@Builder(toBuilder=true) is not supported if returning a type with generics applied to an intermediate."); @@ -350,11 +350,11 @@ public class HandleBuilder extends EclipseAnnotationHandler { } TypeReference[] tpOnRet = tpOnRet_ == null ? null : tpOnRet_[tpOnRet_.length - 1]; typeArgsForToBuilder = new ArrayList(); - + // Every typearg on this method needs to be found in the return type, but the reverse is not true. // We also need to 'map' them. - - + + if (tpOnMethod != null) for (TypeParameter onMethod : tpOnMethod) { int pos = -1; if (tpOnRet != null) for (int i = 0; i < tpOnRet.length; i++) { @@ -366,11 +366,11 @@ public class HandleBuilder extends EclipseAnnotationHandler { annotationNode.addError("@Builder(toBuilder=true) requires that each type parameter on the static method is part of the typeargs of the return value. Type parameter " + new String(onMethod.name) + " is not part of the return type."); return; } - + typeArgsForToBuilder.add(tpOnType[pos].name); } } - + returnType = copyType(md.returnType, ast); typeParams = md.typeParameters; thrownExceptions = md.thrownExceptions; @@ -394,29 +394,29 @@ public class HandleBuilder extends EclipseAnnotationHandler { annotationNode.addError("Unexpected kind of return type on annotated method. Specify 'builderClassName' to solve this problem."); return; } - + if (Character.isLowerCase(token[0])) { char[] newToken = new char[token.length]; System.arraycopy(token, 1, newToken, 1, token.length - 1); newToken[0] = Character.toTitleCase(token[0]); token = newToken; } - + builderClassName = builderClassName.replace("*", new String(token)); } } else { annotationNode.addError("@Builder is only supported on types, constructors, and methods."); return; } - + if (fillParametersFrom != null) { for (EclipseNode param : fillParametersFrom.down()) { if (param.getKind() != Kind.ARGUMENT) continue; BuilderFieldData bfd = new BuilderFieldData(); Argument arg = (Argument) param.get(); - + Annotation[] copyableAnnotations = findCopyableAnnotations(param); - + bfd.rawName = arg.name; bfd.name = arg.name; bfd.builderFieldName = bfd.name; @@ -428,7 +428,7 @@ public class HandleBuilder extends EclipseAnnotationHandler { builderFields.add(bfd); } } - + EclipseNode builderType = findInnerClass(tdParent, builderClassName); if (builderType == null) { builderType = makeBuilderClass(isStatic, tdParent, builderClassName, typeParams, ast, accessForOuters); @@ -454,7 +454,7 @@ public class HandleBuilder extends EclipseAnnotationHandler { } } } - + for (BuilderFieldData bfd : builderFields) { if (bfd.singularData != null && bfd.singularData.getSingularizer() != null) { if (bfd.singularData.getSingularizer().requiresCleaning()) { @@ -473,7 +473,7 @@ public class HandleBuilder extends EclipseAnnotationHandler { } } } - + generateBuilderFields(builderType, builderFields, ast); if (addCleaning) { FieldDeclaration cleanDecl = new FieldDeclaration(CLEAN_FIELD_NAME, 0, -1); @@ -483,18 +483,18 @@ public class HandleBuilder extends EclipseAnnotationHandler { cleanDecl.traverse(new SetGeneratedByVisitor(ast), (MethodScope) null); injectFieldAndMarkGenerated(builderType, cleanDecl); } - + if (constructorExists(builderType) == MemberExistsResult.NOT_EXISTS) { ConstructorDeclaration cd = HandleConstructor.createConstructor( AccessLevel.PACKAGE, builderType, Collections.emptyList(), false, annotationNode, Collections.emptyList()); if (cd != null) injectMethod(builderType, cd); } - + for (BuilderFieldData bfd : builderFields) { makePrefixedSetterMethodsForBuilder(cfv, builderType, bfd, annotationNode, fluent, chain, accessForInners, bfd.originalFieldNode, builderInstance.setterPrefix()); } - + { MemberExistsResult methodExists = methodExists(buildMethodName, builderType, -1); if (methodExists == MemberExistsResult.EXISTS_BY_LOMBOK) methodExists = methodExists(buildMethodName, builderType, 0); @@ -503,7 +503,7 @@ public class HandleBuilder extends EclipseAnnotationHandler { if (md != null) injectMethod(builderType, md); } } - + if (methodExists("toString", builderType, 0) == MemberExistsResult.NOT_EXISTS) { List> fieldNodes = new ArrayList>(); for (BuilderFieldData bfd : builderFields) { @@ -514,18 +514,18 @@ public class HandleBuilder extends EclipseAnnotationHandler { MethodDeclaration md = HandleToString.createToString(builderType, fieldNodes, true, false, ast, FieldAccess.ALWAYS_FIELD); if (md != null) injectMethod(builderType, md); } - + if (addCleaning) { MethodDeclaration cleanMethod = generateCleanMethod(builderFields, builderType, ast); if (cleanMethod != null) injectMethod(builderType, cleanMethod); } - + if (generateBuilderMethod && methodExists(builderMethodName, tdParent, -1) != MemberExistsResult.NOT_EXISTS) generateBuilderMethod = false; if (generateBuilderMethod) { MethodDeclaration md = generateBuilderMethod(cfv, isStatic, builderMethodName, builderClassName, tdParent, typeParams, ast, accessForOuters); if (md != null) injectMethod(tdParent, md); } - + if (toBuilder) switch (methodExists(toBuilderMethodName, tdParent, 0)) { case EXISTS_BY_USER: annotationNode.addWarning("Not generating toBuilder() as it already exists."); @@ -540,22 +540,22 @@ public class HandleBuilder extends EclipseAnnotationHandler { } } MethodDeclaration md = generateToBuilderMethod(cfv, toBuilderMethodName, builderClassName, tdParent, tps, builderFields, fluent, ast, accessForOuters, builderInstance.setterPrefix()); - + if (md != null) injectMethod(tdParent, md); } - + if (nonFinalNonDefaultedFields != null && generateBuilderMethod) { for (EclipseNode fieldNode : nonFinalNonDefaultedFields) { fieldNode.addWarning("@Builder will ignore the initializing expression entirely. If you want the initializing expression to serve as default, add @Builder.Default. If it is not supposed to be settable during building, make the field final."); } } } - + private static final char[] BUILDER_TEMP_VAR = {'b', 'u', 'i', 'l', 'd', 'e', 'r'}; private MethodDeclaration generateToBuilderMethod(CheckerFrameworkVersion cfv, String methodName, String builderClassName, EclipseNode type, TypeParameter[] typeParams, List builderFields, boolean fluent, ASTNode source, AccessLevel access, String prefix) { int pS = source.sourceStart, pE = source.sourceEnd; long p = (long) pS << 32 | pE; - + MethodDeclaration out = new MethodDeclaration(((CompilationUnitDeclaration) type.top().get()).compilationResult); out.selector = methodName.toCharArray(); out.modifiers = toEclipseModifier(access); @@ -563,7 +563,7 @@ public class HandleBuilder extends EclipseAnnotationHandler { out.returnType = namePlusTypeParamsToTypeReference(builderClassName.toCharArray(), typeParams, p); AllocationExpression invoke = new AllocationExpression(); invoke.type = namePlusTypeParamsToTypeReference(builderClassName.toCharArray(), typeParams, p); - + Expression receiver = invoke; List statements = null; for (BuilderFieldData bfd : builderFields) { @@ -576,7 +576,7 @@ public class HandleBuilder extends EclipseAnnotationHandler { } MessageSend ms = new MessageSend(); Expression[] tgt = new Expression[bfd.singularData == null ? 1 : 2]; - + if (bfd.obtainVia == null || !bfd.obtainVia.field().isEmpty()) { char[] fieldName = bfd.obtainVia == null ? bfd.rawName : bfd.obtainVia.field().toCharArray(); for (int i = 0; i < tgt.length; i++) { @@ -605,7 +605,7 @@ public class HandleBuilder extends EclipseAnnotationHandler { tgt[i] = obtainExpr; } } - + ms.selector = setterName.toCharArray(); if (bfd.singularData == null) { ms.arguments = tgt; @@ -619,7 +619,7 @@ public class HandleBuilder extends EclipseAnnotationHandler { statements.add(new IfStatement(isNotNull, ms, pS, pE)); } } - + if (statements != null) { out.statements = new Statement[statements.size() + 2]; for (int i = 0; i < statements.size(); i++) out.statements[i + 1] = statements.get(i); @@ -633,25 +633,24 @@ public class HandleBuilder extends EclipseAnnotationHandler { } else { out.statements = new Statement[] {new ReturnStatement(receiver, pS, pE)}; } - + if (cfv.generateUnique()) { out.annotations = new Annotation[] {generateNamedAnnotation(source, CheckerFrameworkVersion.NAME__UNIQUE)}; } - + out.traverse(new SetGeneratedByVisitor(source), ((TypeDeclaration) type.get()).scope); return out; - } - + private MethodDeclaration generateCleanMethod(List builderFields, EclipseNode builderType, ASTNode source) { List statements = new ArrayList(); - + for (BuilderFieldData bfd : builderFields) { if (bfd.singularData != null && bfd.singularData.getSingularizer() != null) { bfd.singularData.getSingularizer().appendCleaningCode(bfd.singularData, builderType, statements); } } - + FieldReference thisUnclean = new FieldReference(CLEAN_FIELD_NAME, 0); thisUnclean.receiver = new ThisReference(0, 0); statements.add(new Assignment(thisUnclean, new FalseLiteral(0, 0), 0)); @@ -664,15 +663,15 @@ public class HandleBuilder extends EclipseAnnotationHandler { decl.traverse(new SetGeneratedByVisitor(source), (ClassScope) null); return decl; } - + static Argument[] generateBuildArgs(CheckerFrameworkVersion cfv, EclipseNode type, List builderFields, ASTNode source) { if (!cfv.generateCalledMethods()) return null; - + List mandatories = new ArrayList(); for (BuilderFieldData bfd : builderFields) { if (bfd.singularData == null && bfd.nameOfSetFlag == null) mandatories.add(bfd.name); } - + if (mandatories.size() == 0) return null; char[][] nameCalled = fromQualifiedName(CheckerFrameworkVersion.NAME__CALLED); SingleMemberAnnotation ann = new SingleMemberAnnotation(new QualifiedTypeReference(nameCalled, poss(source, nameCalled.length)), source.sourceStart); @@ -692,12 +691,12 @@ public class HandleBuilder extends EclipseAnnotationHandler { arg.annotations = new Annotation[] {ann}; return new Argument[] {arg}; } - + public MethodDeclaration generateBuildMethod(CheckerFrameworkVersion cfv, EclipseNode tdParent, boolean isStatic, String name, char[] staticName, TypeReference returnType, List builderFields, EclipseNode type, TypeReference[] thrownExceptions, boolean addCleaning, ASTNode source, AccessLevel access) { MethodDeclaration out = new MethodDeclaration(((CompilationUnitDeclaration) type.top().get()).compilationResult); out.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG; List statements = new ArrayList(); - + if (addCleaning) { FieldReference thisUnclean = new FieldReference(CLEAN_FIELD_NAME, 0); thisUnclean.receiver = new ThisReference(0, 0); @@ -706,13 +705,13 @@ public class HandleBuilder extends EclipseAnnotationHandler { invokeClean.selector = CLEAN_METHOD_NAME; statements.add(new IfStatement(notClean, invokeClean, 0, 0)); } - + for (BuilderFieldData bfd : builderFields) { if (bfd.singularData != null && bfd.singularData.getSingularizer() != null) { bfd.singularData.getSingularizer().appendBuildCode(bfd.singularData, type, statements, bfd.builderFieldName, "this"); } } - + List args = new ArrayList(); for (BuilderFieldData bfd : builderFields) { if (bfd.nameOfSetFlag != null) { @@ -722,7 +721,7 @@ public class HandleBuilder extends EclipseAnnotationHandler { inv.receiver = new SingleNameReference(((TypeDeclaration) tdParent.get()).name, 0L); inv.selector = bfd.nameOfDefaultProvider; inv.typeArguments = typeParameterNames(((TypeDeclaration) type.get()).typeParameters); - + args.add(new ConditionalExpression( new SingleNameReference(bfd.nameOfSetFlag, 0L), new SingleNameReference(bfd.builderFieldName, 0L), @@ -731,19 +730,19 @@ public class HandleBuilder extends EclipseAnnotationHandler { args.add(new SingleNameReference(bfd.builderFieldName, 0L)); } } - + if (addCleaning) { FieldReference thisUnclean = new FieldReference(CLEAN_FIELD_NAME, 0); thisUnclean.receiver = new ThisReference(0, 0); statements.add(new Assignment(thisUnclean, new TrueLiteral(0, 0), 0)); } - + out.modifiers = toEclipseModifier(access); out.selector = name.toCharArray(); out.thrownExceptions = copyTypes(thrownExceptions); out.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG; out.returnType = returnType; - + if (staticName == null) { AllocationExpression allocationStatement = new AllocationExpression(); allocationStatement.type = copyType(out.returnType); @@ -752,11 +751,12 @@ public class HandleBuilder extends EclipseAnnotationHandler { } else { MessageSend invoke = new MessageSend(); invoke.selector = staticName; - if (isStatic) + if (isStatic) { invoke.receiver = new SingleNameReference(type.up().getName().toCharArray(), 0); - else + } else { invoke.receiver = new QualifiedThisReference(new SingleTypeReference(type.up().getName().toCharArray(), 0) , 0, 0); - + } + invoke.typeArguments = typeParameterNames(((TypeDeclaration) type.get()).typeParameters); invoke.arguments = args.isEmpty() ? null : args.toArray(new Expression[0]); if (returnType instanceof SingleTypeReference && Arrays.equals(TypeConstants.VOID, ((SingleTypeReference) returnType).token)) { @@ -773,20 +773,20 @@ public class HandleBuilder extends EclipseAnnotationHandler { out.traverse(new SetGeneratedByVisitor(source), (ClassScope) null); return out; } - + private TypeReference[] typeParameterNames(TypeParameter[] typeParameters) { if (typeParameters == null) return null; - + TypeReference[] trs = new TypeReference[typeParameters.length]; for (int i = 0; i < trs.length; i++) { trs[i] = new SingleTypeReference(typeParameters[i].name, 0); } return trs; } - + public static MethodDeclaration generateDefaultProvider(char[] methodName, TypeParameter[] typeParameters, EclipseNode fieldNode, ASTNode source) { int pS = source.sourceStart, pE = source.sourceEnd; - + MethodDeclaration out = new MethodDeclaration(((CompilationUnitDeclaration) fieldNode.top().get()).compilationResult); out.typeParameters = copyTypeParams(typeParameters, source); out.selector = methodName; @@ -796,15 +796,15 @@ public class HandleBuilder extends EclipseAnnotationHandler { out.returnType = copyType(fd.type, source); out.statements = new Statement[] {new ReturnStatement(fd.initialization, pS, pE)}; fd.initialization = null; - + out.traverse(new SetGeneratedByVisitor(source), ((TypeDeclaration) fieldNode.up().get()).scope); return out; } - + public MethodDeclaration generateBuilderMethod(CheckerFrameworkVersion cfv, boolean isStatic, String builderMethodName, String builderClassName, EclipseNode type, TypeParameter[] typeParams, ASTNode source, AccessLevel access) { int pS = source.sourceStart, pE = source.sourceEnd; long p = (long) pS << 32 | pE; - + MethodDeclaration out = new MethodDeclaration(((CompilationUnitDeclaration) type.top().get()).compilationResult); out.selector = builderMethodName.toCharArray(); out.modifiers = toEclipseModifier(access); @@ -827,13 +827,13 @@ public class HandleBuilder extends EclipseAnnotationHandler { out.traverse(new SetGeneratedByVisitor(source), ((TypeDeclaration) type.get()).scope); return out; } - + public void generateBuilderFields(EclipseNode builderType, List builderFields, ASTNode source) { List existing = new ArrayList(); for (EclipseNode child : builderType.down()) { if (child.getKind() == Kind.FIELD) existing.add(child); } - + for (BuilderFieldData bfd : builderFields) { if (bfd.singularData != null && bfd.singularData.getSingularizer() != null) { bfd.createdFields.addAll(bfd.singularData.getSingularizer().generateFields(bfd.singularData, builderType)); @@ -844,7 +844,7 @@ public class HandleBuilder extends EclipseAnnotationHandler { if (Arrays.equals(n, bfd.builderFieldName)) field = exists; if (bfd.nameOfSetFlag != null && Arrays.equals(n, bfd.nameOfSetFlag)) setFlag = exists; } - + if (field == null) { FieldDeclaration fd = new FieldDeclaration(bfd.builderFieldName, 0, 0); fd.bits |= Eclipse.ECLIPSE_DO_NOT_TOUCH_FLAG; @@ -865,9 +865,9 @@ public class HandleBuilder extends EclipseAnnotationHandler { } } } - + private static final AbstractMethodDeclaration[] EMPTY = {}; - + public void makeSetterMethodsForBuilder(CheckerFrameworkVersion cfv, EclipseNode builderType, BuilderFieldData bfd, EclipseNode sourceNode, boolean fluent, boolean chain, AccessLevel access, EclipseNode originalFieldNode) { boolean deprecate = isFieldDeprecated(bfd.originalFieldNode); if (bfd.singularData == null || bfd.singularData.getSingularizer() == null) { @@ -876,7 +876,7 @@ public class HandleBuilder extends EclipseAnnotationHandler { bfd.singularData.getSingularizer().generateMethods(cfv, bfd.singularData, deprecate, builderType, fluent, chain, access); } } - + private void makeSimpleSetterMethodForBuilder(CheckerFrameworkVersion cfv, EclipseNode builderType, boolean deprecate, EclipseNode fieldNode, char[] paramName, char[] nameOfSetFlag, EclipseNode sourceNode, boolean fluent, boolean chain, Annotation[] annotations, AccessLevel access, EclipseNode originalFieldNode) { TypeDeclaration td = (TypeDeclaration) builderType.get(); AbstractMethodDeclaration[] existing = td.methods; @@ -885,34 +885,34 @@ public class HandleBuilder extends EclipseAnnotationHandler { int len = existing.length; FieldDeclaration fd = (FieldDeclaration) fieldNode.get(); char[] name = fd.name; - + for (int i = 0; i < len; i++) { if (!(existing[i] instanceof MethodDeclaration)) continue; char[] existingName = existing[i].selector; if (Arrays.equals(name, existingName) && !isTolerate(fieldNode, existing[i])) return; } - + String setterName = fluent ? new String(paramName) : HandlerUtil.buildAccessorName("set", new String(paramName)); - + List methodAnnsList = Arrays.asList(EclipseHandlerUtil.findCopyableToSetterAnnotations(originalFieldNode)); Annotation[] methodAnns = EclipseHandlerUtil.findCopyableToSetterAnnotations(originalFieldNode); if (methodAnns != null && methodAnns.length > 0) methodAnnsList = Arrays.asList(methodAnns); MethodDeclaration setter = HandleSetter.createSetter(td, deprecate, fieldNode, setterName, paramName, nameOfSetFlag, chain, toEclipseModifier(access), sourceNode, methodAnnsList, annotations != null ? Arrays.asList(copyAnnotations(sourceNode.get(), annotations)) : Collections.emptyList()); - if (cfv.generateCalledMethods()) { - Argument[] arr = setter.arguments == null ? new Argument[0] : setter.arguments; - Argument[] newArr = new Argument[arr.length + 1]; - System.arraycopy(arr, 0, newArr, 1, arr.length); - newArr[0] = new Argument(new char[] { 't', 'h', 'i', 's' }, 0, new SingleTypeReference(builderType.getName().toCharArray(), 0), Modifier.FINAL); - char[][] nameNotCalled = fromQualifiedName(CheckerFrameworkVersion.NAME__NOT_CALLED); - SingleMemberAnnotation ann = new SingleMemberAnnotation(new QualifiedTypeReference(nameNotCalled, poss(source, nameNotCalled.length)), source.sourceStart); - ann.memberValue = new StringLiteral(setterName.toCharArray(), 0, 0, 0); - newArr[0].annotations = new Annotation[] {ann}; - setter.arguments = newArr; - } + if (cfv.generateCalledMethods()) { + Argument[] arr = setter.arguments == null ? new Argument[0] : setter.arguments; + Argument[] newArr = new Argument[arr.length + 1]; + System.arraycopy(arr, 0, newArr, 1, arr.length); + newArr[0] = new Argument(new char[] { 't', 'h', 'i', 's' }, 0, new SingleTypeReference(builderType.getName().toCharArray(), 0), Modifier.FINAL); + char[][] nameNotCalled = fromQualifiedName(CheckerFrameworkVersion.NAME__NOT_CALLED); + SingleMemberAnnotation ann = new SingleMemberAnnotation(new QualifiedTypeReference(nameNotCalled, poss(source, nameNotCalled.length)), source.sourceStart); + ann.memberValue = new StringLiteral(setterName.toCharArray(), 0, 0, 0); + newArr[0].annotations = new Annotation[] {ann}; + setter.arguments = newArr; + } injectMethod(builderType, setter); } - + public void makePrefixedSetterMethodsForBuilder(CheckerFrameworkVersion cfv, EclipseNode builderType, BuilderFieldData bfd, EclipseNode sourceNode, boolean fluent, boolean chain, AccessLevel access, EclipseNode originalFieldNode, String prefix) { boolean deprecate = isFieldDeprecated(bfd.originalFieldNode); if (bfd.singularData == null || bfd.singularData.getSingularizer() == null) { @@ -921,13 +921,13 @@ public class HandleBuilder extends EclipseAnnotationHandler { bfd.singularData.getSingularizer().generateMethods(cfv, bfd.singularData, deprecate, builderType, fluent, chain, access); } } - + private void makePrefixedSetterMethodForBuilder(CheckerFrameworkVersion cfv, EclipseNode builderType, boolean deprecate, EclipseNode fieldNode, char[] paramName, char[] nameOfSetFlag, EclipseNode sourceNode, boolean fluent, boolean chain, Annotation[] annotations, AccessLevel access, EclipseNode originalFieldNode, String prefix) { TypeDeclaration td = (TypeDeclaration) builderType.get(); AbstractMethodDeclaration[] existing = td.methods; if (existing == null) existing = EMPTY; int len = existing.length; - + String setterPrefix = prefix.isEmpty() ? "set" : prefix; String setterName; if(fluent) { @@ -935,13 +935,13 @@ public class HandleBuilder extends EclipseAnnotationHandler { } else { setterName = HandlerUtil.buildAccessorName(setterPrefix, new String(paramName)); } - + for (int i = 0; i < len; i++) { if (!(existing[i] instanceof MethodDeclaration)) continue; char[] existingName = existing[i].selector; if (Arrays.equals(setterName.toCharArray(), existingName) && !isTolerate(fieldNode, existing[i])) return; } - + List methodAnnsList = Collections.emptyList(); Annotation[] methodAnns = EclipseHandlerUtil.findCopyableToSetterAnnotations(originalFieldNode); if (methodAnns != null && methodAnns.length > 0) methodAnnsList = Arrays.asList(methodAnns); @@ -962,7 +962,7 @@ public class HandleBuilder extends EclipseAnnotationHandler { } injectMethod(builderType, setter); } - + public EclipseNode makeBuilderClass(boolean isStatic, EclipseNode tdParent, String builderClassName, TypeParameter[] typeParams, ASTNode source, AccessLevel access) { TypeDeclaration parent = (TypeDeclaration) tdParent.get(); TypeDeclaration builder = new TypeDeclaration(parent.compilationResult); @@ -974,7 +974,7 @@ public class HandleBuilder extends EclipseAnnotationHandler { builder.traverse(new SetGeneratedByVisitor(source), (ClassScope) null); return injectType(tdParent, builder); } - + private void addObtainVia(BuilderFieldData bfd, EclipseNode node) { for (EclipseNode child : node.down()) { if (!annotationTypeMatches(ObtainVia.class, child)) continue; @@ -984,7 +984,7 @@ public class HandleBuilder extends EclipseAnnotationHandler { return; } } - + /** * Returns the explicitly requested singular annotation on this node (field * or parameter), or null if there's no {@code @Singular} annotation on it. @@ -1011,7 +1011,7 @@ public class HandleBuilder extends EclipseAnnotationHandler { } } char[] singularName = explicitSingular.toCharArray(); - + TypeReference type = ((AbstractVariableDeclaration) node.get()).type; TypeReference[] typeArgs = null; String typeName; @@ -1031,7 +1031,7 @@ public class HandleBuilder extends EclipseAnnotationHandler { } else { typeName = type.toString(); } - + String targetFqn = EclipseSingularsRecipes.get().toQualified(typeName); EclipseSingularizer singularizer = EclipseSingularsRecipes.get().getSingularizer(targetFqn); if (singularizer == null) { @@ -1041,7 +1041,7 @@ public class HandleBuilder extends EclipseAnnotationHandler { return new SingularData(child, singularName, pluralName, typeArgs == null ? Collections.emptyList() : Arrays.asList(typeArgs), targetFqn, singularizer, source, setterPrefix.toCharArray()); } - + return null; } } -- cgit From 870937a46f912592206abda57638d142ae81e763 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Wed, 11 Dec 2019 01:48:16 +0100 Subject: [builder] setterPrefix option code review, formatting cleanup, and docs --- doc/changelog.markdown | 1 + src/core/lombok/Builder.java | 11 ++-- .../eclipse/handlers/EclipseSingularsRecipes.java | 17 ++--- .../lombok/eclipse/handlers/HandleBuilder.java | 66 +++---------------- .../singulars/EclipseJavaUtilMapSingularizer.java | 20 +++--- src/core/lombok/javac/handlers/HandleBuilder.java | 73 +++++----------------- .../javac/handlers/JavacSingularsRecipes.java | 32 ++++------ website/templates/features/Builder.html | 6 +- 8 files changed, 64 insertions(+), 162 deletions(-) (limited to 'src') diff --git a/doc/changelog.markdown b/doc/changelog.markdown index 44b7f553..b859c5a8 100644 --- a/doc/changelog.markdown +++ b/doc/changelog.markdown @@ -3,6 +3,7 @@ Lombok Changelog ### v1.18.11 "Edgy Guinea Pig" * PLATFORM: Support for JDK13 (including `yield` in switch expressions, as well as delombok having a nicer style for arrow-style switch blocks, and text blocks). +* 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). ### v1.18.10 (September 10th, 2019) diff --git a/src/core/lombok/Builder.java b/src/core/lombok/Builder.java index fcbe1a09..4ca3da65 100644 --- a/src/core/lombok/Builder.java +++ b/src/core/lombok/Builder.java @@ -155,14 +155,17 @@ public @interface Builder { AccessLevel access() default lombok.AccessLevel.PUBLIC; /** - * Prefix to prepend to set methods in the generated builder class. By default, generated methods to not include a - * prefix. If this value populated, the first letter of the generated method name will be capitalized. + * Prefix to prepend to 'set' methods in the generated builder class. By default, generated methods do not include a prefix. * - * For example, a method normally generated as {@code someField(String someField)} would instead be generated as {@code withSomeField(String someField)} + * For example, a method normally generated as {@code someField(String someField)} would instead be + * generated as {@code withSomeField(String someField)} if using {@code @Builder(setterPrefix = "with")}. * * Note that using "with" to prefix builder setter methods is strongly discouraged as as "with" normally * suggests immutable data structures, and builders by definition are mutable objects. - * + * + * For {@code @Singular} fields, the generated methods are called {@code withName}, {@code withNames}, and {@code clearNames}, instead of + * the default {@code name}, {@code names}, and {@code clearNames}. + * * @return The prefix to prepend to generated method names. */ String setterPrefix() default ""; diff --git a/src/core/lombok/eclipse/handlers/EclipseSingularsRecipes.java b/src/core/lombok/eclipse/handlers/EclipseSingularsRecipes.java index ce5a1b4c..cb2ebe18 100755 --- a/src/core/lombok/eclipse/handlers/EclipseSingularsRecipes.java +++ b/src/core/lombok/eclipse/handlers/EclipseSingularsRecipes.java @@ -129,16 +129,9 @@ public class EclipseSingularsRecipes { private final ASTNode source; public SingularData(EclipseNode annotation, char[] singularName, char[] pluralName, List typeArgs, String targetFqn, EclipseSingularizer singularizer, ASTNode source) { - this.annotation = annotation; - this.singularName = singularName; - this.pluralName = pluralName; - this.typeArgs = typeArgs; - this.targetFqn = targetFqn; - this.singularizer = singularizer; - this.source = source; - this.setterPrefix = new char[0]; + this(annotation, singularName, pluralName, typeArgs, targetFqn, singularizer, source, new char[0]); } - + public SingularData(EclipseNode annotation, char[] singularName, char[] pluralName, List typeArgs, String targetFqn, EclipseSingularizer singularizer, ASTNode source, char[] setterPrefix) { this.annotation = annotation; this.singularName = singularName; @@ -149,7 +142,7 @@ public class EclipseSingularsRecipes { this.source = source; this.setterPrefix = setterPrefix; } - + public void setGeneratedByRecursive(ASTNode target) { SetGeneratedByVisitor visitor = new SetGeneratedByVisitor(source); @@ -177,11 +170,11 @@ public class EclipseSingularsRecipes { public char[] getPluralName() { return pluralName; } - + public char[] getSetterPrefix() { return setterPrefix; } - + public List getTypeArgs() { return typeArgs; } diff --git a/src/core/lombok/eclipse/handlers/HandleBuilder.java b/src/core/lombok/eclipse/handlers/HandleBuilder.java index 40098eb4..70978e23 100755 --- a/src/core/lombok/eclipse/handlers/HandleBuilder.java +++ b/src/core/lombok/eclipse/handlers/HandleBuilder.java @@ -1,16 +1,16 @@ /* * Copyright (C) 2013-2019 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 * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -567,13 +567,10 @@ public class HandleBuilder extends EclipseAnnotationHandler { Expression receiver = invoke; List statements = null; for (BuilderFieldData bfd : builderFields) { - String setterPrefix = prefix.isEmpty() ? "set" : prefix; - String setterName; - if(fluent) { - setterName = prefix.isEmpty() ? new String(bfd.name) : HandlerUtil.buildAccessorName(setterPrefix, new String(bfd.name)); - } else { - setterName = HandlerUtil.buildAccessorName(setterPrefix, new String(bfd.name)); - } + String setterName = new String(bfd.name); + String setterPrefix = !prefix.isEmpty() ? prefix : fluent ? "" : "set"; + if (!setterPrefix.isEmpty()) setterName = HandlerUtil.buildAccessorName(setterPrefix, setterName); + MessageSend ms = new MessageSend(); Expression[] tgt = new Expression[bfd.singularData == null ? 1 : 2]; @@ -868,51 +865,6 @@ public class HandleBuilder extends EclipseAnnotationHandler { private static final AbstractMethodDeclaration[] EMPTY = {}; - public void makeSetterMethodsForBuilder(CheckerFrameworkVersion cfv, EclipseNode builderType, BuilderFieldData bfd, EclipseNode sourceNode, boolean fluent, boolean chain, AccessLevel access, EclipseNode originalFieldNode) { - boolean deprecate = isFieldDeprecated(bfd.originalFieldNode); - if (bfd.singularData == null || bfd.singularData.getSingularizer() == null) { - makeSimpleSetterMethodForBuilder(cfv, builderType, deprecate, bfd.createdFields.get(0), bfd.name, bfd.nameOfSetFlag, sourceNode, fluent, chain, bfd.annotations, access, originalFieldNode); - } else { - bfd.singularData.getSingularizer().generateMethods(cfv, bfd.singularData, deprecate, builderType, fluent, chain, access); - } - } - - private void makeSimpleSetterMethodForBuilder(CheckerFrameworkVersion cfv, EclipseNode builderType, boolean deprecate, EclipseNode fieldNode, char[] paramName, char[] nameOfSetFlag, EclipseNode sourceNode, boolean fluent, boolean chain, Annotation[] annotations, AccessLevel access, EclipseNode originalFieldNode) { - TypeDeclaration td = (TypeDeclaration) builderType.get(); - AbstractMethodDeclaration[] existing = td.methods; - ASTNode source = sourceNode.get(); - if (existing == null) existing = EMPTY; - int len = existing.length; - FieldDeclaration fd = (FieldDeclaration) fieldNode.get(); - char[] name = fd.name; - - for (int i = 0; i < len; i++) { - if (!(existing[i] instanceof MethodDeclaration)) continue; - char[] existingName = existing[i].selector; - if (Arrays.equals(name, existingName) && !isTolerate(fieldNode, existing[i])) return; - } - - String setterName = fluent ? new String(paramName) : HandlerUtil.buildAccessorName("set", new String(paramName)); - - List methodAnnsList = Arrays.asList(EclipseHandlerUtil.findCopyableToSetterAnnotations(originalFieldNode)); - Annotation[] methodAnns = EclipseHandlerUtil.findCopyableToSetterAnnotations(originalFieldNode); - if (methodAnns != null && methodAnns.length > 0) methodAnnsList = Arrays.asList(methodAnns); - MethodDeclaration setter = HandleSetter.createSetter(td, deprecate, fieldNode, setterName, paramName, nameOfSetFlag, chain, toEclipseModifier(access), - sourceNode, methodAnnsList, annotations != null ? Arrays.asList(copyAnnotations(sourceNode.get(), annotations)) : Collections.emptyList()); - if (cfv.generateCalledMethods()) { - Argument[] arr = setter.arguments == null ? new Argument[0] : setter.arguments; - Argument[] newArr = new Argument[arr.length + 1]; - System.arraycopy(arr, 0, newArr, 1, arr.length); - newArr[0] = new Argument(new char[] { 't', 'h', 'i', 's' }, 0, new SingleTypeReference(builderType.getName().toCharArray(), 0), Modifier.FINAL); - char[][] nameNotCalled = fromQualifiedName(CheckerFrameworkVersion.NAME__NOT_CALLED); - SingleMemberAnnotation ann = new SingleMemberAnnotation(new QualifiedTypeReference(nameNotCalled, poss(source, nameNotCalled.length)), source.sourceStart); - ann.memberValue = new StringLiteral(setterName.toCharArray(), 0, 0, 0); - newArr[0].annotations = new Annotation[] {ann}; - setter.arguments = newArr; - } - injectMethod(builderType, setter); - } - public void makePrefixedSetterMethodsForBuilder(CheckerFrameworkVersion cfv, EclipseNode builderType, BuilderFieldData bfd, EclipseNode sourceNode, boolean fluent, boolean chain, AccessLevel access, EclipseNode originalFieldNode, String prefix) { boolean deprecate = isFieldDeprecated(bfd.originalFieldNode); if (bfd.singularData == null || bfd.singularData.getSingularizer() == null) { @@ -988,9 +940,9 @@ public class HandleBuilder extends EclipseAnnotationHandler { /** * Returns the explicitly requested singular annotation on this node (field * or parameter), or null if there's no {@code @Singular} annotation on it. - * + * * @param node The node (field or method param) to inspect for its name and potential {@code @Singular} annotation. - * @param setterPrefix + * @param setterPrefix Explicitly requested setter prefix. */ private SingularData getSingularData(EclipseNode node, ASTNode source, final String setterPrefix) { for (EclipseNode child : node.down()) { diff --git a/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilMapSingularizer.java b/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilMapSingularizer.java index 4ceafd1e..b0223c50 100755 --- a/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilMapSingularizer.java +++ b/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilMapSingularizer.java @@ -28,7 +28,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; -import java.util.logging.Handler; import org.eclipse.jdt.internal.compiler.ast.Annotation; import org.eclipse.jdt.internal.compiler.ast.Argument; @@ -63,7 +62,6 @@ import lombok.eclipse.handlers.EclipseSingularsRecipes.SingularData; import lombok.eclipse.handlers.EclipseSingularsRecipes.StatementMaker; import lombok.eclipse.handlers.EclipseSingularsRecipes.TypeReferenceMaker; import lombok.eclipse.handlers.HandleNonNull; -import org.objectweb.asm.Handle; @ProviderFor(EclipseSingularizer.class) public class EclipseJavaUtilMapSingularizer extends EclipseJavaUtilSingularizer { @@ -247,12 +245,11 @@ public class EclipseJavaUtilMapSingularizer extends EclipseJavaUtilSingularizer valueParam.annotations = typeUseAnnsValue; md.arguments = new Argument[] {keyParam, valueParam}; md.returnType = returnType; - + String name = new String(data.getSingularName()); - String setterPrefix = new String(data.getSetterPrefix()); - String prefixedSingularName = setterPrefix.isEmpty() ? name : HandlerUtil.buildAccessorName(setterPrefix, name); - String setterName = fluent ? prefixedSingularName : HandlerUtil.buildAccessorName("put", name); - + String setterPrefix = data.getSetterPrefix().length > 0 ? new String(data.getSetterPrefix()) : fluent ? "" : "put"; + String setterName = HandlerUtil.buildAccessorName(setterPrefix, name); + md.selector = setterName.toCharArray(); md.annotations = generateSelfReturnAnnotations(deprecate, cfv, data.getSource()); @@ -317,12 +314,11 @@ public class EclipseJavaUtilMapSingularizer extends EclipseJavaUtilSingularizer Argument param = new Argument(data.getPluralName(), 0, paramType, ClassFileConstants.AccFinal); md.arguments = new Argument[] {param}; md.returnType = returnType; - + String name = new String(data.getPluralName()); - String setterPrefix = new String(data.getSetterPrefix()); - String prefixedSingularName = setterPrefix.isEmpty() ? name : HandlerUtil.buildAccessorName(setterPrefix, name); - String setterName = fluent ? prefixedSingularName : HandlerUtil.buildAccessorName("put", name); - + String setterPrefix = data.getSetterPrefix().length > 0 ? new String(data.getSetterPrefix()) : fluent ? "" : "put"; + String setterName = HandlerUtil.buildAccessorName(setterPrefix, name); + md.selector = setterName.toCharArray(); md.annotations = generateSelfReturnAnnotations(deprecate, cfv, data.getSource()); diff --git a/src/core/lombok/javac/handlers/HandleBuilder.java b/src/core/lombok/javac/handlers/HandleBuilder.java index 46cb9b9a..349b1382 100644 --- a/src/core/lombok/javac/handlers/HandleBuilder.java +++ b/src/core/lombok/javac/handlers/HandleBuilder.java @@ -104,7 +104,7 @@ public class HandleBuilder extends JavacAnnotationHandler { @Override public void handle(AnnotationValues annotation, JCAnnotation ast, JavacNode annotationNode) { handleFlagUsage(annotationNode, ConfigurationKeys.BUILDER_FLAG_USAGE, "@Builder"); CheckerFrameworkVersion cfv = getCheckerFrameworkVersion(annotationNode); - + Builder builderInstance = annotation.getInstance(); AccessLevel accessForOuters = builderInstance.access(); if (accessForOuters == null) accessForOuters = AccessLevel.PUBLIC; @@ -549,12 +549,10 @@ public class HandleBuilder extends JavacAnnotationHandler { JCExpression invoke = call; ListBuffer statements = new ListBuffer(); for (BuilderFieldData bfd : builderFields) { - String prefixedSetterName; - if(fluent) { - prefixedSetterName = prefix.isEmpty() ? bfd.name.toString() : HandlerUtil.buildAccessorName(prefix, bfd.name.toString()); - } else { - prefixedSetterName = HandlerUtil.buildAccessorName(prefix, bfd.name.toString()); - } + String setterPrefix = !prefix.isEmpty() ? prefix : fluent ? "" : "set"; + String prefixedSetterName = bfd.name.toString(); + if (!setterPrefix.isEmpty()) prefixedSetterName = HandlerUtil.buildAccessorName(setterPrefix, prefixedSetterName); + Name setterName = type.toName(prefixedSetterName); JCExpression[] tgt = new JCExpression[bfd.singularData == null ? 1 : 2]; if (bfd.obtainVia == null || !bfd.obtainVia.field().isEmpty()) { @@ -782,37 +780,6 @@ public class HandleBuilder extends JavacAnnotationHandler { for (JCVariableDecl gen : generated) recursiveSetGeneratedBy(gen, source, builderType.getContext()); } - public void makeSetterMethodsForBuilder(CheckerFrameworkVersion cfv, JavacNode builderType, BuilderFieldData fieldNode, JavacNode source, boolean fluent, boolean chain, AccessLevel access) { - boolean deprecate = isFieldDeprecated(fieldNode.originalFieldNode); - if (fieldNode.singularData == null || fieldNode.singularData.getSingularizer() == null) { - makeSimpleSetterMethodForBuilder(cfv, builderType, deprecate, fieldNode.createdFields.get(0), fieldNode.name, fieldNode.nameOfSetFlag, source, fluent, chain, fieldNode.annotations, fieldNode.originalFieldNode, access); - } else { - fieldNode.singularData.getSingularizer().generateMethods(cfv, fieldNode.singularData, deprecate, builderType, source.get(), fluent, chain, access); - } - } - - private void makeSimpleSetterMethodForBuilder(CheckerFrameworkVersion cfv, JavacNode builderType, boolean deprecate, JavacNode fieldNode, Name paramName, Name nameOfSetFlag, JavacNode source, boolean fluent, boolean chain, List annosOnParam, JavacNode originalFieldNode, AccessLevel access) { - Name fieldName = ((JCVariableDecl) fieldNode.get()).name; - - for (JavacNode child : builderType.down()) { - if (child.getKind() != Kind.METHOD) continue; - JCMethodDecl methodDecl = (JCMethodDecl) child.get(); - Name existingName = methodDecl.name; - if (existingName.equals(fieldName) && !isTolerate(fieldNode, methodDecl)) return; - } - - String setterName = fluent ? paramName.toString() : HandlerUtil.buildAccessorName("set", paramName.toString()); - - JavacTreeMaker maker = fieldNode.getTreeMaker(); - - List methodAnns = JavacHandlerUtil.findCopyableToSetterAnnotations(originalFieldNode); - JCMethodDecl newMethod = HandleSetter.createSetter(toJavacModifier(access), deprecate, fieldNode, maker, setterName, paramName, nameOfSetFlag, chain, source, methodAnns, annosOnParam); - recursiveSetGeneratedBy(newMethod, source.get(), builderType.getContext()); - copyJavadoc(originalFieldNode, newMethod, CopyJavadoc.SETTER); - - injectMethod(builderType, newMethod); - } - public void makePrefixedSetterMethodsForBuilder(CheckerFrameworkVersion cfv, JavacNode builderType, BuilderFieldData fieldNode, JavacNode source, boolean fluent, boolean chain, AccessLevel access, String prefix) { boolean deprecate = isFieldDeprecated(fieldNode.originalFieldNode); if (fieldNode.singularData == null || fieldNode.singularData.getSingularizer() == null) { @@ -822,27 +789,21 @@ public class HandleBuilder extends JavacAnnotationHandler { fieldNode.singularData.getSingularizer().generateMethods(cfv, fieldNode.singularData, deprecate, builderType, source.get(), fluent, chain, access); } } - + private void makePrefixedSetterMethodForBuilder(CheckerFrameworkVersion cfv, JavacNode builderType, boolean deprecate, JavacNode fieldNode, Name paramName, Name nameOfSetFlag, JavacNode source, boolean fluent, boolean chain, List annosOnParam, JavacNode originalFieldNode, AccessLevel access, String prefix) { - Name fieldName = ((JCVariableDecl) fieldNode.get()).name; - - String setterPrefix = prefix.isEmpty() ? "set" : prefix; - String setterName; - if(fluent) { - setterName = prefix.isEmpty() ? paramName.toString() : HandlerUtil.buildAccessorName(setterPrefix, paramName.toString()); - } else { - setterName = HandlerUtil.buildAccessorName(setterPrefix, paramName.toString()); - } - + String setterPrefix = !prefix.isEmpty() ? prefix : fluent ? "" : "set"; + String setterName = HandlerUtil.buildAccessorName(setterPrefix, paramName.toString()); + Name setterName_ = builderType.toName(setterName); + for (JavacNode child : builderType.down()) { if (child.getKind() != Kind.METHOD) continue; JCMethodDecl methodDecl = (JCMethodDecl) child.get(); Name existingName = methodDecl.name; - if (existingName.equals(builderType.toName(setterName)) && !isTolerate(fieldNode, methodDecl)) return; + if (existingName.equals(setterName_) && !isTolerate(fieldNode, methodDecl)) return; } - + JavacTreeMaker maker = fieldNode.getTreeMaker(); - + List methodAnns = JavacHandlerUtil.findCopyableToSetterAnnotations(originalFieldNode); JCMethodDecl newMethod = HandleSetter.createSetter(toJavacModifier(access), deprecate, fieldNode, maker, setterName, paramName, nameOfSetFlag, chain, source, methodAnns, annosOnParam); if (cfv.generateCalledMethods()) { @@ -853,10 +814,10 @@ public class HandleBuilder extends JavacAnnotationHandler { } recursiveSetGeneratedBy(newMethod, source.get(), builderType.getContext()); copyJavadoc(originalFieldNode, newMethod, CopyJavadoc.SETTER); - + injectMethod(builderType, newMethod); } - + public JavacNode makeBuilderClass(boolean isStatic, JavacNode source, JavacNode tdParent, String builderClassName, List typeParams, JCAnnotation ast, AccessLevel access) { JavacTreeMaker maker = tdParent.getTreeMaker(); int modifiers = toJavacModifier(access); @@ -882,9 +843,9 @@ public class HandleBuilder extends JavacAnnotationHandler { * or parameter), or null if there's no {@code @Singular} annotation on it. * * @param node The node (field or method param) to inspect for its name and potential {@code @Singular} annotation. - * @param setterPrefix + * @param setterPrefix Explicitly requested setter prefix. */ - private SingularData getSingularData(JavacNode node, final String setterPrefix) { + private SingularData getSingularData(JavacNode node, String setterPrefix) { for (JavacNode child : node.down()) { if (!annotationTypeMatches(Singular.class, child)) continue; Name pluralName = node.getKind() == Kind.FIELD ? removePrefixFromField(node) : ((JCVariableDecl) node.get()).name; diff --git a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java index 87081dde..86f148ca 100644 --- a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java +++ b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java @@ -122,15 +122,9 @@ public class JavacSingularsRecipes { private final String setterPrefix; public SingularData(JavacNode annotation, Name singularName, Name pluralName, List typeArgs, String targetFqn, JavacSingularizer singularizer) { - this.annotation = annotation; - this.singularName = singularName; - this.pluralName = pluralName; - this.typeArgs = typeArgs; - this.targetFqn = targetFqn; - this.singularizer = singularizer; - this.setterPrefix = ""; + this(annotation, singularName, pluralName, typeArgs, targetFqn, singularizer, ""); } - + public SingularData(JavacNode annotation, Name singularName, Name pluralName, List typeArgs, String targetFqn, JavacSingularizer singularizer, String setterPrefix) { this.annotation = annotation; this.singularName = singularName; @@ -152,8 +146,10 @@ public class JavacSingularsRecipes { public Name getPluralName() { return pluralName; } - - public String getSetterPrefix() { return setterPrefix; } + + public String getSetterPrefix() { + return setterPrefix; + } public List getTypeArgs() { return typeArgs; @@ -296,12 +292,9 @@ public class JavacSingularsRecipes { List params = generateSingularMethodParameters(maker, data, builderType, source); Name name = data.getSingularName(); String setterPrefix = data.getSetterPrefix(); - Name prefixedSingularName = setterPrefix.isEmpty() ? name : - builderType.toName(HandlerUtil.buildAccessorName(setterPrefix, name.toString())); - - name = fluent ? prefixedSingularName : builderType.toName(HandlerUtil.buildAccessorName(getAddMethodName(), - name.toString())); - + if (setterPrefix.isEmpty() && !fluent) setterPrefix = getAddMethodName(); + if (!setterPrefix.isEmpty()) name = builderType.toName(HandlerUtil.buildAccessorName(setterPrefix, name.toString())); + statements.prepend(createConstructBuilderVarIfNeeded(maker, data, builderType, source)); finishAndInjectMethod(cfv, maker, returnType, returnStatement, data, builderType, source, deprecate, statements, name, params, access); } @@ -328,10 +321,9 @@ public class JavacSingularsRecipes { private void generatePluralMethod(CheckerFrameworkVersion cfv, boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent, AccessLevel access) { ListBuffer statements = generatePluralMethodStatements(maker, data, builderType, source); Name name = data.getPluralName(); - - Name prefixedSingularName = data.getSetterPrefix().isEmpty() ? name : builderType.toName(HandlerUtil.buildAccessorName(data.getSetterPrefix(), data.getPluralName().toString())); - name = fluent ? prefixedSingularName - : builderType.toName(HandlerUtil.buildAccessorName(getAddMethodName() + "All", name.toString())); + String setterPrefix = data.getSetterPrefix(); + if (setterPrefix.isEmpty() && !fluent) setterPrefix = getAddMethodName() + "All"; + if (!setterPrefix.isEmpty()) name = builderType.toName(HandlerUtil.buildAccessorName(setterPrefix, name.toString())); JCExpression paramType = getPluralMethodParamType(builderType); paramType = addTypeArgs(getTypeArgumentsCount(), true, builderType, paramType, data.getTypeArgs(), source); long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext()); diff --git a/website/templates/features/Builder.html b/website/templates/features/Builder.html index d22877ea..08ff1ec8 100644 --- a/website/templates/features/Builder.html +++ b/website/templates/features/Builder.html @@ -68,10 +68,12 @@ If you want toBuilder() (default: no)
  • The access level of all generated elements (default: public). +
  • + (discouraged) If you want your builder's 'set' methods to have a prefix, i.e. Person.builder().setName("Jane").build() instead of Person.builder().name("Jane").build() and what it should be.
  • Example usage where all options are changed from their defaults:
    - @Builder(builderClassName = "HelloWorldBuilder", buildMethodName = "execute", builderMethodName = "helloWorld", toBuilder = true, access = AccessLevel.PRIVATE)
    + @Builder(builderClassName = "HelloWorldBuilder", buildMethodName = "execute", builderMethodName = "helloWorld", toBuilder = true, access = AccessLevel.PRIVATE, setterPrefix = "set")

    @@ -132,6 +134,8 @@ 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. +

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

    -- cgit