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)`. --- src/core/lombok/javac/handlers/HandleBuilder.java | 54 +++++++++++++++++++---- 1 file changed, 46 insertions(+), 8 deletions(-) (limited to 'src/core/lombok/javac/handlers') 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); -- 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/core/lombok/javac/handlers') 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/core/lombok/javac/handlers') 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/core/lombok/javac/handlers') 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 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/core/lombok/javac/handlers') 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 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/core/lombok/javac/handlers') 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