From ef90e2ec2dcea35a22959f2c1295517edf090133 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Tue, 28 Aug 2018 00:37:38 +0200 Subject: [fixes #1836] superbuilder didn’t play ball with field prefixes, at least in javac. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SuperBuilderWithCustomBuilderMethod.java | 4 +- .../after-delombok/SuperBuilderWithDefaults.java | 2 +- .../after-delombok/SuperBuilderWithPrefixes.java | 87 ++++++++++++++++++++++ .../SuperBuilderWithCustomBuilderMethod.java | 4 +- .../after-ecj/SuperBuilderWithDefaults.java | 2 +- .../after-ecj/SuperBuilderWithPrefixes.java | 74 ++++++++++++++++++ .../resource/before/SuperBuilderWithPrefixes.java | 8 ++ 7 files changed, 175 insertions(+), 6 deletions(-) create mode 100644 test/transform/resource/after-delombok/SuperBuilderWithPrefixes.java create mode 100644 test/transform/resource/after-ecj/SuperBuilderWithPrefixes.java create mode 100644 test/transform/resource/before/SuperBuilderWithPrefixes.java (limited to 'test/transform/resource') diff --git a/test/transform/resource/after-delombok/SuperBuilderWithCustomBuilderMethod.java b/test/transform/resource/after-delombok/SuperBuilderWithCustomBuilderMethod.java index 21a9db07..fc303583 100644 --- a/test/transform/resource/after-delombok/SuperBuilderWithCustomBuilderMethod.java +++ b/test/transform/resource/after-delombok/SuperBuilderWithCustomBuilderMethod.java @@ -48,7 +48,7 @@ public class SuperBuilderWithCustomBuilderMethod { } @java.lang.Override @java.lang.SuppressWarnings("all") - protected ParentBuilderImpl self() { + protected ParentBuilderImpl self() { return this; } @java.lang.Override @@ -111,7 +111,7 @@ public class SuperBuilderWithCustomBuilderMethod { } @java.lang.Override @java.lang.SuppressWarnings("all") - protected ChildBuilderImpl self() { + protected ChildBuilderImpl self() { return this; } @java.lang.Override diff --git a/test/transform/resource/after-delombok/SuperBuilderWithDefaults.java b/test/transform/resource/after-delombok/SuperBuilderWithDefaults.java index 17707bf5..842b7e55 100644 --- a/test/transform/resource/after-delombok/SuperBuilderWithDefaults.java +++ b/test/transform/resource/after-delombok/SuperBuilderWithDefaults.java @@ -50,7 +50,7 @@ public class SuperBuilderWithDefaults { } @java.lang.Override @java.lang.SuppressWarnings("all") - protected ParentBuilderImpl self() { + protected ParentBuilderImpl self() { return this; } @java.lang.Override diff --git a/test/transform/resource/after-delombok/SuperBuilderWithPrefixes.java b/test/transform/resource/after-delombok/SuperBuilderWithPrefixes.java new file mode 100644 index 00000000..2fb2dcca --- /dev/null +++ b/test/transform/resource/after-delombok/SuperBuilderWithPrefixes.java @@ -0,0 +1,87 @@ +class SuperBuilderWithPrefixes { + int mField; + int xOtherField; + java.util.List mItems; + @java.lang.SuppressWarnings("all") + public static abstract class SuperBuilderWithPrefixesBuilder> { + @java.lang.SuppressWarnings("all") + private int field; + @java.lang.SuppressWarnings("all") + private int otherField; + @java.lang.SuppressWarnings("all") + private java.util.ArrayList items; + @java.lang.SuppressWarnings("all") + protected abstract B self(); + @java.lang.SuppressWarnings("all") + public abstract C build(); + @java.lang.SuppressWarnings("all") + public B field(final int field) { + this.field = field; + return self(); + } + @java.lang.SuppressWarnings("all") + public B otherField(final int otherField) { + this.otherField = otherField; + return self(); + } + @java.lang.SuppressWarnings("all") + public B item(final String item) { + if (this.items == null) this.items = new java.util.ArrayList(); + this.items.add(item); + return self(); + } + @java.lang.SuppressWarnings("all") + public B items(final java.util.Collection items) { + if (this.items == null) this.items = new java.util.ArrayList(); + this.items.addAll(items); + return self(); + } + @java.lang.SuppressWarnings("all") + public B clearItems() { + if (this.items != null) this.items.clear(); + return self(); + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public java.lang.String toString() { + return "SuperBuilderWithPrefixes.SuperBuilderWithPrefixesBuilder(field=" + this.field + ", otherField=" + this.otherField + ", items=" + this.items + ")"; + } + } + @java.lang.SuppressWarnings("all") + private static final class SuperBuilderWithPrefixesBuilderImpl extends SuperBuilderWithPrefixesBuilder { + @java.lang.SuppressWarnings("all") + private SuperBuilderWithPrefixesBuilderImpl() { + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + protected SuperBuilderWithPrefixesBuilderImpl self() { + return this; + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public SuperBuilderWithPrefixes build() { + return new SuperBuilderWithPrefixes(this); + } + } + @java.lang.SuppressWarnings("all") + protected SuperBuilderWithPrefixes(final SuperBuilderWithPrefixesBuilder b) { + this.mField = b.field; + this.xOtherField = b.otherField; + java.util.List items; + switch (b.items == null ? 0 : b.items.size()) { + case 0: + items = java.util.Collections.emptyList(); + break; + case 1: + items = java.util.Collections.singletonList(b.items.get(0)); + break; + default: + items = java.util.Collections.unmodifiableList(new java.util.ArrayList(b.items)); + } + this.mItems = items; + } + @java.lang.SuppressWarnings("all") + public static SuperBuilderWithPrefixesBuilder builder() { + return new SuperBuilderWithPrefixesBuilderImpl(); + } +} \ No newline at end of file diff --git a/test/transform/resource/after-ecj/SuperBuilderWithCustomBuilderMethod.java b/test/transform/resource/after-ecj/SuperBuilderWithCustomBuilderMethod.java index fe4938bf..ed0655c7 100644 --- a/test/transform/resource/after-ecj/SuperBuilderWithCustomBuilderMethod.java +++ b/test/transform/resource/after-ecj/SuperBuilderWithCustomBuilderMethod.java @@ -38,7 +38,7 @@ public class SuperBuilderWithCustomBuilderMethod { private ParentBuilderImpl() { super(); } - protected @java.lang.Override @java.lang.SuppressWarnings("all") ParentBuilderImpl self() { + protected @java.lang.Override @java.lang.SuppressWarnings("all") ParentBuilderImpl self() { return this; } public @java.lang.Override @java.lang.SuppressWarnings("all") Parent build() { @@ -87,7 +87,7 @@ public class SuperBuilderWithCustomBuilderMethod { private ChildBuilderImpl() { super(); } - protected @java.lang.Override @java.lang.SuppressWarnings("all") ChildBuilderImpl self() { + protected @java.lang.Override @java.lang.SuppressWarnings("all") ChildBuilderImpl self() { return this; } public @java.lang.Override @java.lang.SuppressWarnings("all") Child build() { diff --git a/test/transform/resource/after-ecj/SuperBuilderWithDefaults.java b/test/transform/resource/after-ecj/SuperBuilderWithDefaults.java index ef0713c5..e259b68d 100644 --- a/test/transform/resource/after-ecj/SuperBuilderWithDefaults.java +++ b/test/transform/resource/after-ecj/SuperBuilderWithDefaults.java @@ -29,7 +29,7 @@ public class SuperBuilderWithDefaults { private ParentBuilderImpl() { super(); } - protected @java.lang.Override @java.lang.SuppressWarnings("all") ParentBuilderImpl self() { + protected @java.lang.Override @java.lang.SuppressWarnings("all") ParentBuilderImpl self() { return this; } public @java.lang.Override @java.lang.SuppressWarnings("all") Parent build() { diff --git a/test/transform/resource/after-ecj/SuperBuilderWithPrefixes.java b/test/transform/resource/after-ecj/SuperBuilderWithPrefixes.java new file mode 100644 index 00000000..33400b3c --- /dev/null +++ b/test/transform/resource/after-ecj/SuperBuilderWithPrefixes.java @@ -0,0 +1,74 @@ +@lombok.experimental.SuperBuilder class SuperBuilderWithPrefixes { + public static abstract @java.lang.SuppressWarnings("all") class SuperBuilderWithPrefixesBuilder> { + private @java.lang.SuppressWarnings("all") int field; + private @java.lang.SuppressWarnings("all") int otherField; + private @java.lang.SuppressWarnings("all") java.util.ArrayList items; + public SuperBuilderWithPrefixesBuilder() { + super(); + } + protected abstract @java.lang.SuppressWarnings("all") B self(); + public abstract @java.lang.SuppressWarnings("all") C build(); + public @java.lang.SuppressWarnings("all") B field(final int field) { + this.field = field; + return self(); + } + public @java.lang.SuppressWarnings("all") B otherField(final int otherField) { + this.otherField = otherField; + return self(); + } + public @java.lang.SuppressWarnings("all") B item(String item) { + if ((this.items == null)) + this.items = new java.util.ArrayList(); + this.items.add(item); + return self(); + } + public @java.lang.SuppressWarnings("all") B items(java.util.Collection items) { + if ((this.items == null)) + this.items = new java.util.ArrayList(); + this.items.addAll(items); + return self(); + } + public @java.lang.SuppressWarnings("all") B clearItems() { + if ((this.items != null)) + this.items.clear(); + return self(); + } + public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + return (((((("SuperBuilderWithPrefixes.SuperBuilderWithPrefixesBuilder(field=" + this.field) + ", otherField=") + this.otherField) + ", items=") + this.items) + ")"); + } + } + private static final @java.lang.SuppressWarnings("all") class SuperBuilderWithPrefixesBuilderImpl extends SuperBuilderWithPrefixesBuilder { + private SuperBuilderWithPrefixesBuilderImpl() { + super(); + } + protected @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderWithPrefixesBuilderImpl self() { + return this; + } + public @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderWithPrefixes build() { + return new SuperBuilderWithPrefixes(this); + } + } + int mField; + int xOtherField; + @lombok.Singular java.util.List mItems; + protected @java.lang.SuppressWarnings("all") SuperBuilderWithPrefixes(final SuperBuilderWithPrefixesBuilder b) { + super(); + this.mField = b.field; + this.xOtherField = b.otherField; + java.util.List items; + switch (((b.items == null) ? 0 : b.items.size())) { + case 0 : + items = java.util.Collections.emptyList(); + break; + case 1 : + items = java.util.Collections.singletonList(b.items.get(0)); + break; + default : + items = java.util.Collections.unmodifiableList(new java.util.ArrayList(b.items)); + } + this.mItems = items; + } + public static @java.lang.SuppressWarnings("all") SuperBuilderWithPrefixesBuilder builder() { + return new SuperBuilderWithPrefixesBuilderImpl(); + } +} diff --git a/test/transform/resource/before/SuperBuilderWithPrefixes.java b/test/transform/resource/before/SuperBuilderWithPrefixes.java new file mode 100644 index 00000000..b15c9607 --- /dev/null +++ b/test/transform/resource/before/SuperBuilderWithPrefixes.java @@ -0,0 +1,8 @@ +//CONF: lombok.accessors.prefix += m +//CONF: lombok.accessors.prefix += x +@lombok.experimental.SuperBuilder +class SuperBuilderWithPrefixes { + int mField; + int xOtherField; + @lombok.Singular java.util.List mItems; +} -- cgit