diff options
author | Reinier Zwitserloot <reinier@zwitserloot.com> | 2018-10-29 23:29:10 +0100 |
---|---|---|
committer | Reinier Zwitserloot <reinier@zwitserloot.com> | 2018-10-29 23:29:10 +0100 |
commit | d8de0e3c49c97450c3cd78a7d1766a8f21150591 (patch) | |
tree | 47e8b626b1dda32d3ddcbccc022799653fc786b2 | |
parent | eca219ee6433cd964f0549a114a791ca4eb9f0fa (diff) | |
parent | e9d098a16c6b07fb39905ce154f810255a0dfc8f (diff) | |
download | lombok-d8de0e3c49c97450c3cd78a7d1766a8f21150591.tar.gz lombok-d8de0e3c49c97450c3cd78a7d1766a8f21150591.tar.bz2 lombok-d8de0e3c49c97450c3cd78a7d1766a8f21150591.zip |
Merge branch 'wildcardsSingularFix' of git://github.com/janrieke/lombok into janrieke-wildcardsSingularFix
6 files changed, 206 insertions, 5 deletions
diff --git a/src/core/lombok/eclipse/handlers/HandleBuilder.java b/src/core/lombok/eclipse/handlers/HandleBuilder.java index 89cf81e0..0ce1436d 100644 --- a/src/core/lombok/eclipse/handlers/HandleBuilder.java +++ b/src/core/lombok/eclipse/handlers/HandleBuilder.java @@ -537,7 +537,17 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> { 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<typeParams.length; j++) { + obtainExpr.typeArguments[j] = new SingleTypeReference(typeParams[j].name, 0); + } + } + obtainExpr.receiver = new SingleNameReference(type.getName().toCharArray(), 0); + } else { + obtainExpr.receiver = new ThisReference(0, 0); + } obtainExpr.selector = obtainName.toCharArray(); if (obtainIsStatic) obtainExpr.arguments = new Expression[] {new ThisReference(0, 0)}; tgt[i] = obtainExpr; diff --git a/src/core/lombok/javac/handlers/HandleBuilder.java b/src/core/lombok/javac/handlers/HandleBuilder.java index c5c1e1ca..0f6e21d0 100644 --- a/src/core/lombok/javac/handlers/HandleBuilder.java +++ b/src/core/lombok/javac/handlers/HandleBuilder.java @@ -508,7 +508,7 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> { 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.<JCExpression>nil(), c, List.<JCExpression>of(maker.Ident(type.toName("this")))); + tgt[i] = maker.Apply(typeParameterNames(maker, typeParams), c, List.<JCExpression>of(maker.Ident(type.toName("this")))); } } else { for (int i = 0; i < tgt.length; i++) { 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<JCExpression> 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<JCExpression> invokeTypeArgs = createTypeArgs(agrumentsCount, false, builderType, data.getTypeArgs(), source); + List<JCExpression> invokeTypeArgs = createTypeArgs(argumentsCount, false, builderType, data.getTypeArgs(), source); empty = maker.Apply(invokeTypeArgs, emptyMethod, jceBlank); } diff --git a/test/transform/resource/after-delombok/BuilderSingularWildcardListsWithToBuilder.java b/test/transform/resource/after-delombok/BuilderSingularWildcardListsWithToBuilder.java new file mode 100644 index 00000000..509d0394 --- /dev/null +++ b/test/transform/resource/after-delombok/BuilderSingularWildcardListsWithToBuilder.java @@ -0,0 +1,94 @@ +import java.util.List; +import java.util.Collection; +class BuilderSingularWildcardListsWithToBuilder { + private List<?> objects; + private Collection<? extends Number> numbers; + @java.lang.SuppressWarnings("all") + BuilderSingularWildcardListsWithToBuilder(final List<?> objects, final Collection<? extends Number> numbers) { + this.objects = objects; + this.numbers = numbers; + } + @java.lang.SuppressWarnings("all") + public static class BuilderSingularWildcardListsWithToBuilderBuilder { + @java.lang.SuppressWarnings("all") + private java.util.ArrayList<java.lang.Object> objects; + @java.lang.SuppressWarnings("all") + private java.util.ArrayList<Number> numbers; + @java.lang.SuppressWarnings("all") + BuilderSingularWildcardListsWithToBuilderBuilder() { + } + @java.lang.SuppressWarnings("all") + public BuilderSingularWildcardListsWithToBuilderBuilder object(final java.lang.Object object) { + if (this.objects == null) this.objects = new java.util.ArrayList<java.lang.Object>(); + this.objects.add(object); + return this; + } + @java.lang.SuppressWarnings("all") + public BuilderSingularWildcardListsWithToBuilderBuilder objects(final java.util.Collection<?> objects) { + if (this.objects == null) this.objects = new java.util.ArrayList<java.lang.Object>(); + this.objects.addAll(objects); + return this; + } + @java.lang.SuppressWarnings("all") + public BuilderSingularWildcardListsWithToBuilderBuilder clearObjects() { + if (this.objects != null) this.objects.clear(); + return this; + } + @java.lang.SuppressWarnings("all") + public BuilderSingularWildcardListsWithToBuilderBuilder number(final Number number) { + if (this.numbers == null) this.numbers = new java.util.ArrayList<Number>(); + this.numbers.add(number); + return this; + } + @java.lang.SuppressWarnings("all") + public BuilderSingularWildcardListsWithToBuilderBuilder numbers(final java.util.Collection<? extends Number> numbers) { + if (this.numbers == null) this.numbers = new java.util.ArrayList<Number>(); + this.numbers.addAll(numbers); + return this; + } + @java.lang.SuppressWarnings("all") + public BuilderSingularWildcardListsWithToBuilderBuilder clearNumbers() { + if (this.numbers != null) this.numbers.clear(); + return this; + } + @java.lang.SuppressWarnings("all") + public BuilderSingularWildcardListsWithToBuilder build() { + java.util.List<java.lang.Object> 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<java.lang.Object>(this.objects)); + } + java.util.Collection<Number> 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<Number>(this.numbers)); + } + return new BuilderSingularWildcardListsWithToBuilder(objects, numbers); + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public java.lang.String toString() { + return "BuilderSingularWildcardListsWithToBuilder.BuilderSingularWildcardListsWithToBuilderBuilder(objects=" + this.objects + ", numbers=" + this.numbers + ")"; + } + } + @java.lang.SuppressWarnings("all") + public static BuilderSingularWildcardListsWithToBuilderBuilder builder() { + return new BuilderSingularWildcardListsWithToBuilderBuilder(); + } + @java.lang.SuppressWarnings("all") + public BuilderSingularWildcardListsWithToBuilderBuilder toBuilder() { + return new BuilderSingularWildcardListsWithToBuilderBuilder().objects(this.objects == null ? java.util.Collections.<java.lang.Object>emptyList() : this.objects).numbers(this.numbers == null ? java.util.Collections.<Number>emptyList() : this.numbers); + } +} 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<java.lang.Object> objects; + private @java.lang.SuppressWarnings("all") java.util.ArrayList<Number> 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<java.lang.Object>(); + 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<java.lang.Object>(); + 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<Number>(); + this.numbers.add(number); + return this; + } + public @java.lang.SuppressWarnings("all") BuilderSingularWildcardListsWithToBuilderBuilder numbers(final java.util.Collection<? extends Number> numbers) { + if ((this.numbers == null)) + this.numbers = new java.util.ArrayList<Number>(); + 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<java.lang.Object> 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<java.lang.Object>(this.objects)); + } + java.util.Collection<Number> 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<Number>(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<? extends Number> numbers; + @java.lang.SuppressWarnings("all") BuilderSingularWildcardListsWithToBuilder(final List<?> objects, final Collection<? extends Number> 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.<java.lang.Object>emptyList() : this.objects)).numbers(((this.numbers == null) ? java.util.Collections.<Number>emptyList() : this.numbers)); + } +}
\ No newline at end of file diff --git a/test/transform/resource/before/BuilderSingularWildcardListsWithToBuilder.java b/test/transform/resource/before/BuilderSingularWildcardListsWithToBuilder.java new file mode 100644 index 00000000..43fdceb1 --- /dev/null +++ b/test/transform/resource/before/BuilderSingularWildcardListsWithToBuilder.java @@ -0,0 +1,10 @@ +import java.util.List; +import java.util.Collection; + +import lombok.Singular; + +@lombok.Builder(toBuilder = true) +class BuilderSingularWildcardListsWithToBuilder { + @Singular private List<?> objects; + @Singular private Collection<? extends Number> numbers; +} |