From 2335f251665d43b4c8cebe00b980f07ef33bdb17 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Wed, 1 May 2019 05:45:10 +0200 Subject: [fixes #2104] superbuilder + non-list-singulars wouldn’t work due to hardcoded call to emptyList. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SuperBuilderWithGenericsAndToBuilder.java | 53 ++++++++++++++-------- 1 file changed, 35 insertions(+), 18 deletions(-) (limited to 'test/transform/resource/after-delombok/SuperBuilderWithGenericsAndToBuilder.java') diff --git a/test/transform/resource/after-delombok/SuperBuilderWithGenericsAndToBuilder.java b/test/transform/resource/after-delombok/SuperBuilderWithGenericsAndToBuilder.java index deb5a223..af67e900 100644 --- a/test/transform/resource/after-delombok/SuperBuilderWithGenericsAndToBuilder.java +++ b/test/transform/resource/after-delombok/SuperBuilderWithGenericsAndToBuilder.java @@ -1,14 +1,16 @@ -import java.util.List; +import java.util.Map; public class SuperBuilderWithGenericsAndToBuilder { public static class Parent { A field1; - List items; + Map items; @java.lang.SuppressWarnings("all") public static abstract class ParentBuilder, B extends ParentBuilder> { @java.lang.SuppressWarnings("all") private A field1; @java.lang.SuppressWarnings("all") - private java.util.ArrayList items; + private java.util.ArrayList items$key; + @java.lang.SuppressWarnings("all") + private java.util.ArrayList items$value; @java.lang.SuppressWarnings("all") protected B $fillValuesFrom(final C instance) { ParentBuilder.$fillValuesFromInstanceIntoBuilder(instance, this); @@ -17,7 +19,7 @@ public class SuperBuilderWithGenericsAndToBuilder { @java.lang.SuppressWarnings("all") private static void $fillValuesFromInstanceIntoBuilder(final Parent instance, final ParentBuilder b) { b.field1(instance.field1); - b.items(instance.items == null ? java.util.Collections.emptyList() : instance.items); + b.items(instance.items == null ? java.util.Collections.emptyMap() : instance.items); } @java.lang.SuppressWarnings("all") protected abstract B self(); @@ -29,26 +31,39 @@ public class SuperBuilderWithGenericsAndToBuilder { 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); + public B item(final Integer itemKey, final String itemValue) { + if (this.items$key == null) { + this.items$key = new java.util.ArrayList(); + this.items$value = new java.util.ArrayList(); + } + this.items$key.add(itemKey); + this.items$value.add(itemValue); 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); + public B items(final java.util.Map items) { + if (this.items$key == null) { + this.items$key = new java.util.ArrayList(); + this.items$value = new java.util.ArrayList(); + } + for (final java.util.Map.Entry $lombokEntry : items.entrySet()) { + this.items$key.add($lombokEntry.getKey()); + this.items$value.add($lombokEntry.getValue()); + } return self(); } @java.lang.SuppressWarnings("all") public B clearItems() { - if (this.items != null) this.items.clear(); + if (this.items$key != null) { + this.items$key.clear(); + this.items$value.clear(); + } return self(); } @java.lang.Override @java.lang.SuppressWarnings("all") public java.lang.String toString() { - return "SuperBuilderWithGenericsAndToBuilder.Parent.ParentBuilder(field1=" + this.field1 + ", items=" + this.items + ")"; + return "SuperBuilderWithGenericsAndToBuilder.Parent.ParentBuilder(field1=" + this.field1 + ", items$key=" + this.items$key + ", items$value=" + this.items$value + ")"; } } @java.lang.SuppressWarnings("all") @@ -70,16 +85,18 @@ public class SuperBuilderWithGenericsAndToBuilder { @java.lang.SuppressWarnings("all") protected Parent(final ParentBuilder b) { this.field1 = b.field1; - java.util.List items; - switch (b.items == null ? 0 : b.items.size()) { + java.util.Map items; + switch (b.items$key == null ? 0 : b.items$key.size()) { case 0: - items = java.util.Collections.emptyList(); + items = java.util.Collections.emptyMap(); break; case 1: - items = java.util.Collections.singletonList(b.items.get(0)); + items = java.util.Collections.singletonMap(b.items$key.get(0), b.items$value.get(0)); break; default: - items = java.util.Collections.unmodifiableList(new java.util.ArrayList(b.items)); + items = new java.util.LinkedHashMap(b.items$key.size() < 1073741824 ? 1 + b.items$key.size() + (b.items$key.size() - 3) / 3 : java.lang.Integer.MAX_VALUE); + for (int $i = 0; $i < b.items$key.size(); $i++) items.put(b.items$key.get($i), (String) b.items$value.get($i)); + items = java.util.Collections.unmodifiableMap(items); } this.items = items; } @@ -157,6 +174,6 @@ public class SuperBuilderWithGenericsAndToBuilder { } } public static void test() { - Child x = Child.builder().field3(0.0).field1(5).item("").build().toBuilder().build(); + Child x = Child.builder().field3(0.0).field1(5).item(5, "").build().toBuilder().build(); } } -- cgit