diff options
14 files changed, 51 insertions, 46 deletions
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<Builder> { 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<Builder> { } 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<BuilderFieldData> builderFields, boolean fluent, ASTNode source, AccessLevel access) { + private MethodDeclaration generateToBuilderMethod(CheckerFrameworkVersion cfv, String methodName, String builderClassName, EclipseNode type, TypeParameter[] typeParams, List<BuilderFieldData> 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<Builder> { Expression receiver = invoke; List<Statement> 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<Builder> { } } - 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<? extends Number> 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<T, K extends Number> { public static <Z extends Number> BuilderWithExistingBuilderClassWithSetterPrefix<String, Z> staticMethod(Z arg1, boolean arg2, String arg3) { return null; } - public static class BuilderWithExistingBuilderClassBuilderWithSetterPrefixBuilder<Z extends Number> { + public static class BuilderWithExistingBuilderClassWithSetterPrefixBuilder<Z extends Number> { @java.lang.SuppressWarnings("all") private boolean arg2; @java.lang.SuppressWarnings("all") @@ -11,7 +11,7 @@ class BuilderWithExistingBuilderClassWithSetterPrefix<T, K extends Number> { public void withArg2(boolean arg) { } @java.lang.SuppressWarnings("all") - BuilderWithExistingBuilderClassBuilderWithSetterPrefixBuilder() { + BuilderWithExistingBuilderClassWithSetterPrefixBuilder() { } @java.lang.SuppressWarnings("all") public BuilderWithExistingBuilderClassWithSetterPrefixBuilder<Z> 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<T> { 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<T> withUnprefixed(final int unprefixed) { + public @java.lang.SuppressWarnings("all") BuilderSimpleWithSetterPrefixBuilder<T> withUnprefixed(final int unprefixed) { this.unprefixed = unprefixed; return this; } - public @java.lang.SuppressWarnings("all") BuilderWithPrefix<T> build() { - return new BuilderWithPrefix<T>(unprefixed); + public @java.lang.SuppressWarnings("all") BuilderSimpleWithSetterPrefix<T> build() { + return new BuilderSimpleWithSetterPrefix<T>(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<T> dangerMouse(final T dangerMouse) { + public @java.lang.SuppressWarnings("all") BuilderSingularSetsWithSetterPrefixBuilder<T> withDangerMouse(final T dangerMouse) { if ((this.dangerMice == null)) this.dangerMice = new java.util.ArrayList<T>(); this.dangerMice.add(dangerMouse); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularSetsWithSetterPrefixBuilder<T> dangerMice(final java.util.Collection<? extends T> dangerMice) { + public @java.lang.SuppressWarnings("all") BuilderSingularSetsWithSetterPrefixBuilder<T> withDangerMice(final java.util.Collection<? extends T> dangerMice) { if ((this.dangerMice == null)) this.dangerMice = new java.util.ArrayList<T>(); this.dangerMice.addAll(dangerMice); @@ -27,13 +27,13 @@ import lombok.Singular; this.dangerMice.clear(); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularSetsWithSetterPrefixBuilder<T> octopus(final Number octopus) { + public @java.lang.SuppressWarnings("all") BuilderSingularSetsWithSetterPrefixBuilder<T> withOctopus(final Number octopus) { if ((this.octopodes == null)) this.octopodes = new java.util.ArrayList<Number>(); this.octopodes.add(octopus); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularSetsWithSetterPrefixBuilder<T> octopodes(final java.util.Collection<? extends Number> octopodes) { + public @java.lang.SuppressWarnings("all") BuilderSingularSetsWithSetterPrefixBuilder<T> withOctopodes(final java.util.Collection<? extends Number> octopodes) { if ((this.octopodes == null)) this.octopodes = new java.util.ArrayList<Number>(); this.octopodes.addAll(octopodes); @@ -44,13 +44,13 @@ import lombok.Singular; this.octopodes.clear(); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularSetsWithSetterPrefixBuilder<T> rawSet(final java.lang.Object rawSet) { + public @java.lang.SuppressWarnings("all") BuilderSingularSetsWithSetterPrefixBuilder<T> withRawSet(final java.lang.Object rawSet) { if ((this.rawSet == null)) this.rawSet = new java.util.ArrayList<java.lang.Object>(); this.rawSet.add(rawSet); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularSetsWithSetterPrefixBuilder<T> rawSet(final java.util.Collection<?> rawSet) { + public @java.lang.SuppressWarnings("all") BuilderSingularSetsWithSetterPrefixBuilder<T> withRawSet(final java.util.Collection<?> rawSet) { if ((this.rawSet == null)) this.rawSet = new java.util.ArrayList<java.lang.Object>(); this.rawSet.addAll(rawSet); @@ -61,13 +61,13 @@ import lombok.Singular; this.rawSet.clear(); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularSetsWithSetterPrefixBuilder<T> stringSet(final String stringSet) { + public @java.lang.SuppressWarnings("all") BuilderSingularSetsWithSetterPrefixBuilder<T> withStringSet(final String stringSet) { if ((this.stringSet == null)) this.stringSet = new java.util.ArrayList<String>(); this.stringSet.add(stringSet); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularSetsWithSetterPrefixBuilder<T> stringSet(final java.util.Collection<? extends String> stringSet) { + public @java.lang.SuppressWarnings("all") BuilderSingularSetsWithSetterPrefixBuilder<T> withStringSet(final java.util.Collection<? extends String> stringSet) { if ((this.stringSet == null)) this.stringSet = new java.util.ArrayList<String>(); 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<String> 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<String>(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<String> _elems; - @java.lang.SuppressWarnings("all") BuilderSingularWithPrefixesWithSetterPrefixes(final java.util.List<String> elems) { + @java.lang.SuppressWarnings("all") BuilderSingularWithPrefixesWithSetterPrefix(final java.util.List<String> 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<T, K extends Number> { - public static class BuilderWithExistingBuilderClassBuilderWithSetterPrefixBuilder<Z extends Number> { + public static class BuilderWithExistingBuilderClassWithSetterPrefixBuilder<Z extends Number> { 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<T, U extends Inter<T, U>> { } - public static final @Builder(setterPrefix = "with(setterPrefix = "with")") @Value class Test<Foo, Bar extends Set<Foo>, Quz extends Inter<Bar, Quz>> { + public static final @Builder(setterPrefix = "with") @Value class Test<Foo, Bar extends Set<Foo>, Quz extends Inter<Bar, Quz>> { public static @java.lang.SuppressWarnings("all") class TestBuilder<Foo, Bar extends Set<Foo>, Quz extends Inter<Bar, Quz>> { 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<T> { - public static @java.lang.SuppressWarnings("all") class ConstructorWithToBuilderBuilder<T> { + +@lombok.experimental.Accessors(prefix = "m") class ConstructorWithToBuilderWithSetterPrefix<T> { + public static @java.lang.SuppressWarnings("all") class ConstructorWithToBuilderWithSetterPrefixBuilder<T> { private @java.lang.SuppressWarnings("all") String mOne; private @java.lang.SuppressWarnings("all") T baz; private @java.lang.SuppressWarnings("all") com.google.common.collect.ImmutableList<T> bars; - @java.lang.SuppressWarnings("all") ConstructorWithToBuilderBuilder() { + @java.lang.SuppressWarnings("all") ConstructorWithToBuilderWithSetterPrefixBuilder() { super(); } - public @java.lang.SuppressWarnings("all") ConstructorWithToBuilderBuilder<T> withMOne(final String mOne) { + public @java.lang.SuppressWarnings("all") ConstructorWithToBuilderWithSetterPrefixBuilder<T> withMOne(final String mOne) { this.mOne = mOne; return this; } - public @java.lang.SuppressWarnings("all") ConstructorWithToBuilderBuilder<T> withBaz(final T baz) { + public @java.lang.SuppressWarnings("all") ConstructorWithToBuilderWithSetterPrefixBuilder<T> withBaz(final T baz) { this.baz = baz; return this; } - public @java.lang.SuppressWarnings("all") ConstructorWithToBuilderBuilder<T> withBars(final com.google.common.collect.ImmutableList<T> bars) { + public @java.lang.SuppressWarnings("all") ConstructorWithToBuilderWithSetterPrefixBuilder<T> withBars(final com.google.common.collect.ImmutableList<T> bars) { this.bars = bars; return this; } - public @java.lang.SuppressWarnings("all") ConstructorWithToBuilder<T> build() { - return new ConstructorWithToBuilder<T>(mOne, baz, bars); + public @java.lang.SuppressWarnings("all") ConstructorWithToBuilderWithSetterPrefix<T> build() { + return new ConstructorWithToBuilderWithSetterPrefix<T>(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<T> bars; - public @Builder(toBuilder = true) ConstructorWithToBuilder(String mOne, @Builder.ObtainVia(field = "foo") T baz, com.google.common.collect.ImmutableList<T> bars) { + public @Builder(toBuilder = true,setterPrefix = "with") ConstructorWithToBuilderWithSetterPrefix(String mOne, @Builder.ObtainVia(field = "foo") T baz, com.google.common.collect.ImmutableList<T> bars) { super(); } - public static @java.lang.SuppressWarnings("all") <T>ConstructorWithToBuilderBuilder<T> builder() { - return new ConstructorWithToBuilderBuilder<T>(); + public static @java.lang.SuppressWarnings("all") <T>ConstructorWithToBuilderWithSetterPrefixBuilder<T> builder() { + return new ConstructorWithToBuilderWithSetterPrefixBuilder<T>(); } - public @java.lang.SuppressWarnings("all") ConstructorWithToBuilderBuilder<T> toBuilder() { - return new ConstructorWithToBuilderBuilder<T>().withMOne(this.mOne).withBaz(this.foo).withBars(this.bars); + public @java.lang.SuppressWarnings("all") ConstructorWithToBuilderWithSetterPrefixBuilder<T> toBuilder() { + return new ConstructorWithToBuilderWithSetterPrefixBuilder<T>().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<T> { private String mOne, mTwo; @Builder.ObtainVia(method = "rrr", isStatic = true) private T foo; @lombok.Singular private List<T> bars; - public static <K> K rrr(BuilderWithToBuilder<K> x) { + public static <K> K rrr(BuilderWithToBuilderWithSetterPrefix<K> x) { return x.foo; } } @@ -15,6 +15,6 @@ class ConstructorWithToBuilderWithSetterPrefix<T> { private T foo; @lombok.Singular private com.google.common.collect.ImmutableList<T> bars; @Builder(toBuilder = true, setterPrefix = "with") - public ConstructorWithToBuilder(String mOne, @Builder.ObtainVia(field = "foo") T baz, com.google.common.collect.ImmutableList<T> bars) { + public ConstructorWithToBuilderWithSetterPrefix(String mOne, @Builder.ObtainVia(field = "foo") T baz, com.google.common.collect.ImmutableList<T> 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)); } } } |