From d6057f8eb7d38994dc94645c55979f0f8a2233fa Mon Sep 17 00:00:00 2001 From: Jan Rieke Date: Fri, 12 Oct 2018 09:06:34 +0200 Subject: fixed toBuilder on Singular fields with wildcards (javac) --- src/core/lombok/javac/handlers/HandleBuilder.java | 3 ++- .../lombok/javac/handlers/singulars/JavacGuavaSingularizer.java | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'src/core') diff --git a/src/core/lombok/javac/handlers/HandleBuilder.java b/src/core/lombok/javac/handlers/HandleBuilder.java index 8170898b..6dd98c6f 100644 --- a/src/core/lombok/javac/handlers/HandleBuilder.java +++ b/src/core/lombok/javac/handlers/HandleBuilder.java @@ -521,7 +521,8 @@ public class HandleBuilder extends JavacAnnotationHandler { arg = tgt[0]; } else { JCExpression eqNull = maker.Binary(CTC_EQUAL, tgt[0], maker.Literal(CTC_BOT, null)); - List tas = cloneTypes(maker, bfd.singularData.getTypeArgs(), ast, type.getContext()); + // Use the singularizer to create the type args (will remove possible wildcards on the type). + List tas = bfd.singularData.getSingularizer().createTypeArgs(bfd.singularData.getTypeArgs().size(), false, type, bfd.singularData.getTypeArgs(), type.get()); JCExpression emptyList = maker.Apply(tas, chainDots(type, "java", "util", "Collections", "emptyList"), List.nil()); arg = maker.Conditional(eqNull, emptyList, tgt[1]); } diff --git a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java index 74010d52..a50565ac 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java @@ -169,13 +169,13 @@ abstract class JavacGuavaSingularizer extends JavacSingularizer { List jceBlank = List.nil(); JCExpression varType = chainDotsString(builderType, data.getTargetFqn()); - int agrumentsCount = getTypeArgumentsCount(); - varType = addTypeArgs(agrumentsCount, false, builderType, varType, data.getTypeArgs(), source); + int argumentsCount = getTypeArgumentsCount(); + varType = addTypeArgs(argumentsCount, false, builderType, varType, data.getTypeArgs(), source); JCExpression empty; { //ImmutableX.of() JCExpression emptyMethod = chainDots(builderType, "com", "google", "common", "collect", getSimpleTargetTypeName(data), "of"); - List invokeTypeArgs = createTypeArgs(agrumentsCount, false, builderType, data.getTypeArgs(), source); + List invokeTypeArgs = createTypeArgs(argumentsCount, false, builderType, data.getTypeArgs(), source); empty = maker.Apply(invokeTypeArgs, emptyMethod, jceBlank); } -- cgit From 80b5f8d41de3be9f93f49a3d5c2611405b2b1a6f Mon Sep 17 00:00:00 2001 From: Jan Rieke Date: Fri, 12 Oct 2018 15:26:25 +0200 Subject: fixed another missing type arg issue --- src/core/lombok/eclipse/handlers/HandleBuilder.java | 12 +++++++++++- src/core/lombok/javac/handlers/HandleBuilder.java | 2 +- .../resource/after-delombok/BuilderWithToBuilder.java | 2 +- test/transform/resource/after-ecj/BuilderWithToBuilder.java | 2 +- 4 files changed, 14 insertions(+), 4 deletions(-) (limited to 'src/core') diff --git a/src/core/lombok/eclipse/handlers/HandleBuilder.java b/src/core/lombok/eclipse/handlers/HandleBuilder.java index 280afc26..5fb98800 100644 --- a/src/core/lombok/eclipse/handlers/HandleBuilder.java +++ b/src/core/lombok/eclipse/handlers/HandleBuilder.java @@ -536,7 +536,17 @@ public class HandleBuilder extends EclipseAnnotationHandler { boolean obtainIsStatic = bfd.obtainVia.isStatic(); for (int i = 0; i < tgt.length; i++) { MessageSend obtainExpr = new MessageSend(); - obtainExpr.receiver = obtainIsStatic ? new SingleNameReference(type.getName().toCharArray(), 0) : new ThisReference(0, 0); + if (obtainIsStatic) { + if (typeParams != null && typeParams.length > 0) { + obtainExpr.typeArguments = new TypeReference[typeParams.length]; + for (int j = 0; j { if (bfd.obtainVia.isStatic()) { for (int i = 0; i < tgt.length; i++) { JCExpression c = maker.Select(maker.Ident(type.toName(type.getName())), type.toName(bfd.obtainVia.method())); - tgt[i] = maker.Apply(List.nil(), c, List.of(maker.Ident(type.toName("this")))); + tgt[i] = maker.Apply(typeParameterNames(maker, typeParams), c, List.of(maker.Ident(type.toName("this")))); } } else { for (int i = 0; i < tgt.length; i++) { diff --git a/test/transform/resource/after-delombok/BuilderWithToBuilder.java b/test/transform/resource/after-delombok/BuilderWithToBuilder.java index 8615a40b..445a65e5 100644 --- a/test/transform/resource/after-delombok/BuilderWithToBuilder.java +++ b/test/transform/resource/after-delombok/BuilderWithToBuilder.java @@ -86,7 +86,7 @@ class BuilderWithToBuilder { } @java.lang.SuppressWarnings("all") public BuilderWithToBuilderBuilder toBuilder() { - return new BuilderWithToBuilderBuilder().one(this.mOne).two(this.mTwo).foo(BuilderWithToBuilder.rrr(this)).bars(this.bars == null ? java.util.Collections.emptyList() : this.bars); + return new BuilderWithToBuilderBuilder().one(this.mOne).two(this.mTwo).foo(BuilderWithToBuilder.rrr(this)).bars(this.bars == null ? java.util.Collections.emptyList() : this.bars); } } class ConstructorWithToBuilder { diff --git a/test/transform/resource/after-ecj/BuilderWithToBuilder.java b/test/transform/resource/after-ecj/BuilderWithToBuilder.java index 636dc42d..320f37f1 100644 --- a/test/transform/resource/after-ecj/BuilderWithToBuilder.java +++ b/test/transform/resource/after-ecj/BuilderWithToBuilder.java @@ -74,7 +74,7 @@ import lombok.Builder; return new BuilderWithToBuilderBuilder(); } public @java.lang.SuppressWarnings("all") BuilderWithToBuilderBuilder toBuilder() { - return new BuilderWithToBuilderBuilder().one(this.mOne).two(this.mTwo).foo(BuilderWithToBuilder.rrr(this)).bars(((this.bars == null) ? java.util.Collections.emptyList() : this.bars)); + return new BuilderWithToBuilderBuilder().one(this.mOne).two(this.mTwo).foo(BuilderWithToBuilder.rrr(this)).bars(((this.bars == null) ? java.util.Collections.emptyList() : this.bars)); } } @lombok.experimental.Accessors(prefix = "m") class ConstructorWithToBuilder { -- cgit From e9d098a16c6b07fb39905ce154f810255a0dfc8f Mon Sep 17 00:00:00 2001 From: Jan Rieke Date: Fri, 12 Oct 2018 19:47:40 +0200 Subject: fixed toBuilder on Singular fields with wildcards (ecj) --- .../lombok/eclipse/handlers/HandleBuilder.java | 2 +- .../BuilderSingularWildcardListsWithToBuilder.java | 87 ++++++++++++++++++++++ 2 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 test/transform/resource/after-ecj/BuilderSingularWildcardListsWithToBuilder.java (limited to 'src/core') diff --git a/src/core/lombok/eclipse/handlers/HandleBuilder.java b/src/core/lombok/eclipse/handlers/HandleBuilder.java index 5fb98800..86c1da42 100644 --- a/src/core/lombok/eclipse/handlers/HandleBuilder.java +++ b/src/core/lombok/eclipse/handlers/HandleBuilder.java @@ -559,7 +559,7 @@ public class HandleBuilder extends EclipseAnnotationHandler { MessageSend emptyList = new MessageSend(); emptyList.receiver = generateQualifiedNameRef(source, TypeConstants.JAVA, TypeConstants.UTIL, "Collections".toCharArray()); emptyList.selector = EMPTY_LIST; - emptyList.typeArguments = copyTypes(bfd.singularData.getTypeArgs().toArray(new TypeReference[0])); + emptyList.typeArguments = bfd.singularData.getSingularizer().createTypeArgs(bfd.singularData.getTypeArgs().size(), false, type, bfd.singularData.getTypeArgs()); ms.arguments = new Expression[] {new ConditionalExpression(ifNull, emptyList, tgt[1])}; } ms.receiver = receiver; diff --git a/test/transform/resource/after-ecj/BuilderSingularWildcardListsWithToBuilder.java b/test/transform/resource/after-ecj/BuilderSingularWildcardListsWithToBuilder.java new file mode 100644 index 00000000..e8db5ffd --- /dev/null +++ b/test/transform/resource/after-ecj/BuilderSingularWildcardListsWithToBuilder.java @@ -0,0 +1,87 @@ +import java.util.List; +import java.util.Collection; +import lombok.Singular; +@lombok.Builder(toBuilder = true) class BuilderSingularWildcardListsWithToBuilder { + public static @java.lang.SuppressWarnings("all") class BuilderSingularWildcardListsWithToBuilderBuilder { + private @java.lang.SuppressWarnings("all") java.util.ArrayList objects; + private @java.lang.SuppressWarnings("all") java.util.ArrayList numbers; + @java.lang.SuppressWarnings("all") BuilderSingularWildcardListsWithToBuilderBuilder() { + super(); + } + public @java.lang.SuppressWarnings("all") BuilderSingularWildcardListsWithToBuilderBuilder object(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 objects(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() { + if ((this.objects != null)) + this.objects.clear(); + return this; + } + public @java.lang.SuppressWarnings("all") BuilderSingularWildcardListsWithToBuilderBuilder number(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 numbers(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() { + if ((this.numbers != null)) + this.numbers.clear(); + return this; + } + public @java.lang.SuppressWarnings("all") BuilderSingularWildcardListsWithToBuilder build() { + java.util.List objects; + switch (((this.objects == null) ? 0 : this.objects.size())) { + case 0 : + objects = java.util.Collections.emptyList(); + break; + case 1 : + objects = java.util.Collections.singletonList(this.objects.get(0)); + break; + default : + objects = java.util.Collections.unmodifiableList(new java.util.ArrayList(this.objects)); + } + java.util.Collection numbers; + switch (((this.numbers == null) ? 0 : this.numbers.size())) { + case 0 : + numbers = java.util.Collections.emptyList(); + break; + case 1 : + numbers = java.util.Collections.singletonList(this.numbers.get(0)); + break; + default : + numbers = java.util.Collections.unmodifiableList(new java.util.ArrayList(this.numbers)); + } + return new BuilderSingularWildcardListsWithToBuilder(objects, numbers); + } + public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + return (((("BuilderSingularWildcardListsWithToBuilder.BuilderSingularWildcardListsWithToBuilderBuilder(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) { + super(); + this.objects = objects; + this.numbers = numbers; + } + public static @java.lang.SuppressWarnings("all") BuilderSingularWildcardListsWithToBuilderBuilder builder() { + return new BuilderSingularWildcardListsWithToBuilderBuilder(); + } + public @java.lang.SuppressWarnings("all") BuilderSingularWildcardListsWithToBuilderBuilder toBuilder() { + return new BuilderSingularWildcardListsWithToBuilderBuilder().objects(((this.objects == null) ? java.util.Collections.emptyList() : this.objects)).numbers(((this.numbers == null) ? java.util.Collections.emptyList() : this.numbers)); + } +} \ No newline at end of file -- cgit