From ce0a09177e577c0b4f42379c5cc7ce364f26c905 Mon Sep 17 00:00:00 2001 From: Bulgakov Alexander Date: Fri, 26 Apr 2019 22:10:34 +0300 Subject: #1976. A handlers' order has been changed. The javac's HandleDelegate generates code before the HandleVal. --- .../after-delombok/ValDelegateMethodReference.java | 65 ++++++++++++++++++++++ .../after-ecj/ValDelegateMethodReference.java | 58 +++++++++++++++++++ .../before/ValDelegateMethodReference.java | 35 ++++++++++++ 3 files changed, 158 insertions(+) create mode 100644 test/transform/resource/after-delombok/ValDelegateMethodReference.java create mode 100644 test/transform/resource/after-ecj/ValDelegateMethodReference.java create mode 100644 test/transform/resource/before/ValDelegateMethodReference.java (limited to 'test/transform') diff --git a/test/transform/resource/after-delombok/ValDelegateMethodReference.java b/test/transform/resource/after-delombok/ValDelegateMethodReference.java new file mode 100644 index 00000000..186e2aaa --- /dev/null +++ b/test/transform/resource/after-delombok/ValDelegateMethodReference.java @@ -0,0 +1,65 @@ +import java.util.function.Function; + +public class ValDelegateMethodReference { + public void config() { + final Column column = createColumn(Entity::getValue); + } + + private Column createColumn(Function func) { + return new Column<>(func); + } +} + +class Column { + public Column(Function vp) { + } +} + +class Entity { + private MyDelegate innerDelegate; + + @java.lang.SuppressWarnings("all") + public java.lang.String getValue() { + return this.innerDelegate.getValue(); + } + + @java.lang.SuppressWarnings("all") + public java.lang.Boolean getABoolean() { + return this.innerDelegate.getABoolean(); + } + + @java.lang.SuppressWarnings("all") + public void setValue(final java.lang.String value) { + this.innerDelegate.setValue(value); + } + + @java.lang.SuppressWarnings("all") + public void setABoolean(final java.lang.Boolean aBoolean) { + this.innerDelegate.setABoolean(aBoolean); + } +} + +class MyDelegate { + private String value; + private Boolean aBoolean; + + @java.lang.SuppressWarnings("all") + public String getValue() { + return this.value; + } + + @java.lang.SuppressWarnings("all") + public Boolean getABoolean() { + return this.aBoolean; + } + + @java.lang.SuppressWarnings("all") + public void setValue(final String value) { + this.value = value; + } + + @java.lang.SuppressWarnings("all") + public void setABoolean(final Boolean aBoolean) { + this.aBoolean = aBoolean; + } +} \ No newline at end of file diff --git a/test/transform/resource/after-ecj/ValDelegateMethodReference.java b/test/transform/resource/after-ecj/ValDelegateMethodReference.java new file mode 100644 index 00000000..cfd0dab2 --- /dev/null +++ b/test/transform/resource/after-ecj/ValDelegateMethodReference.java @@ -0,0 +1,58 @@ +import lombok.Getter; +import lombok.Setter; +import lombok.experimental.Delegate; +import lombok.val; +import java.util.function.Function; +public class ValDelegateMethodReference { + public ValDelegateMethodReference() { + super(); + } + public void config() { + final @val Column column = createColumn(Entity::getValue); + } + private Column createColumn(Function func) { + return new Column<>(func); + } +} +class Column { + public Column(Function vp) { + super(); + } +} +class Entity { + private @Delegate MyDelegate innerDelegate; + Entity() { + super(); + } + public @java.lang.SuppressWarnings("all") java.lang.Boolean getABoolean() { + return this.innerDelegate.getABoolean(); + } + public @java.lang.SuppressWarnings("all") java.lang.String getValue() { + return this.innerDelegate.getValue(); + } + public @java.lang.SuppressWarnings("all") void setABoolean(final java.lang.Boolean aBoolean) { + this.innerDelegate.setABoolean(aBoolean); + } + public @java.lang.SuppressWarnings("all") void setValue(final java.lang.String value) { + this.innerDelegate.setValue(value); + } +} +@Getter @Setter class MyDelegate { + private String value; + private Boolean aBoolean; + MyDelegate() { + super(); + } + public @java.lang.SuppressWarnings("all") String getValue() { + return this.value; + } + public @java.lang.SuppressWarnings("all") Boolean getABoolean() { + return this.aBoolean; + } + public @java.lang.SuppressWarnings("all") void setValue(final String value) { + this.value = value; + } + public @java.lang.SuppressWarnings("all") void setABoolean(final Boolean aBoolean) { + this.aBoolean = aBoolean; + } +} diff --git a/test/transform/resource/before/ValDelegateMethodReference.java b/test/transform/resource/before/ValDelegateMethodReference.java new file mode 100644 index 00000000..7adc402a --- /dev/null +++ b/test/transform/resource/before/ValDelegateMethodReference.java @@ -0,0 +1,35 @@ + +import lombok.Getter; +import lombok.Setter; +import lombok.experimental.Delegate; +import lombok.val; + +import java.util.function.Function; + +public class ValDelegateMethodReference { + + public void config() { + val column = createColumn(Entity::getValue); + } + + private Column createColumn(Function func) { + return new Column<>(func); + } + +} + +class Column { + public Column(Function vp) {} +} + +class Entity { + @Delegate + private MyDelegate innerDelegate; +} + +@Getter +@Setter +class MyDelegate { + private String value; + private Boolean aBoolean; +} \ No newline at end of file -- cgit From a3180298305ff64e9f671b51d663b750ba7c8efa Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Wed, 1 May 2019 00:41:32 +0200 Subject: [fixes #2083] adds feature ‘access level’ to `@Builder` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/transform/resource/after-delombok/BuilderSimple.java | 4 ++-- test/transform/resource/after-ecj/BuilderSimple.java | 6 +++--- test/transform/resource/before/BuilderSimple.java | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'test/transform') diff --git a/test/transform/resource/after-delombok/BuilderSimple.java b/test/transform/resource/after-delombok/BuilderSimple.java index e3821c9a..4cd20b23 100644 --- a/test/transform/resource/after-delombok/BuilderSimple.java +++ b/test/transform/resource/after-delombok/BuilderSimple.java @@ -10,7 +10,7 @@ class BuilderSimple { this.also = also; } @java.lang.SuppressWarnings("all") - public static class BuilderSimpleBuilder { + protected static class BuilderSimpleBuilder { @java.lang.SuppressWarnings("all") private int yes; @java.lang.SuppressWarnings("all") @@ -39,7 +39,7 @@ class BuilderSimple { } } @java.lang.SuppressWarnings("all") - public static BuilderSimpleBuilder builder() { + protected static BuilderSimpleBuilder builder() { return new BuilderSimpleBuilder(); } } diff --git a/test/transform/resource/after-ecj/BuilderSimple.java b/test/transform/resource/after-ecj/BuilderSimple.java index bc0ff186..9d9fb7f3 100644 --- a/test/transform/resource/after-ecj/BuilderSimple.java +++ b/test/transform/resource/after-ecj/BuilderSimple.java @@ -1,6 +1,6 @@ import java.util.List; -@lombok.Builder class BuilderSimple { - public static @java.lang.SuppressWarnings("all") class BuilderSimpleBuilder { +@lombok.Builder(access = lombok.AccessLevel.PROTECTED) class BuilderSimple { + protected static @java.lang.SuppressWarnings("all") class BuilderSimpleBuilder { private @java.lang.SuppressWarnings("all") int yes; private @java.lang.SuppressWarnings("all") List also; @java.lang.SuppressWarnings("all") BuilderSimpleBuilder() { @@ -30,7 +30,7 @@ import java.util.List; this.yes = yes; this.also = also; } - public static @java.lang.SuppressWarnings("all") BuilderSimpleBuilder builder() { + protected static @java.lang.SuppressWarnings("all") BuilderSimpleBuilder builder() { return new BuilderSimpleBuilder(); } } diff --git a/test/transform/resource/before/BuilderSimple.java b/test/transform/resource/before/BuilderSimple.java index 83c89713..d0a786db 100644 --- a/test/transform/resource/before/BuilderSimple.java +++ b/test/transform/resource/before/BuilderSimple.java @@ -1,6 +1,6 @@ import java.util.List; -@lombok.Builder +@lombok.Builder(access = lombok.AccessLevel.PROTECTED) class BuilderSimple { private final int noshow = 0; private final int yes; -- cgit From bf0499263b05e11fdd43886df3dc5663c8fee5f4 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Wed, 1 May 2019 01:33:57 +0200 Subject: [issue #2092] Add an uppercase option to FieldNameConstants --- .../FieldNameConstantsUppercased.java | 12 +++++++++++ .../after-ecj/FieldNameConstantsUppercased.java | 23 ++++++++++++++++++++++ .../before/FieldNameConstantsUppercased.java | 12 +++++++++++ 3 files changed, 47 insertions(+) create mode 100644 test/transform/resource/after-delombok/FieldNameConstantsUppercased.java create mode 100644 test/transform/resource/after-ecj/FieldNameConstantsUppercased.java create mode 100644 test/transform/resource/before/FieldNameConstantsUppercased.java (limited to 'test/transform') diff --git a/test/transform/resource/after-delombok/FieldNameConstantsUppercased.java b/test/transform/resource/after-delombok/FieldNameConstantsUppercased.java new file mode 100644 index 00000000..dd7de86a --- /dev/null +++ b/test/transform/resource/after-delombok/FieldNameConstantsUppercased.java @@ -0,0 +1,12 @@ +public class FieldNameConstantsUppercased { + String iAmADvdPlayer; + int $skipMe; + static double skipMeToo; + int andMe; + String butPrintMePlease; + @java.lang.SuppressWarnings("all") + static final class Fields { + public static final java.lang.String I_AM_A_DVD_PLAYER = "iAmADvdPlayer"; + public static final java.lang.String BUT_PRINT_ME_PLEASE = "butPrintMePlease"; + } +} diff --git a/test/transform/resource/after-ecj/FieldNameConstantsUppercased.java b/test/transform/resource/after-ecj/FieldNameConstantsUppercased.java new file mode 100644 index 00000000..a858b91f --- /dev/null +++ b/test/transform/resource/after-ecj/FieldNameConstantsUppercased.java @@ -0,0 +1,23 @@ +import lombok.experimental.FieldNameConstants; +import lombok.AccessLevel; +public @FieldNameConstants(level = AccessLevel.PACKAGE) class FieldNameConstantsUppercased { + static final @java.lang.SuppressWarnings("all") class Fields { + public static final java.lang.String I_AM_A_DVD_PLAYER = "iAmADvdPlayer"; + public static final java.lang.String BUT_PRINT_ME_PLEASE = "butPrintMePlease"; + () { + } + private @java.lang.SuppressWarnings("all") Fields() { + super(); + } + } + String iAmADvdPlayer; + int $skipMe; + static double skipMeToo; + @FieldNameConstants.Exclude int andMe; + String butPrintMePlease; + () { + } + public FieldNameConstantsUppercased() { + super(); + } +} \ No newline at end of file diff --git a/test/transform/resource/before/FieldNameConstantsUppercased.java b/test/transform/resource/before/FieldNameConstantsUppercased.java new file mode 100644 index 00000000..674cb7f1 --- /dev/null +++ b/test/transform/resource/before/FieldNameConstantsUppercased.java @@ -0,0 +1,12 @@ +//CONF: lombok.fieldNameConstants.uppercase = true +import lombok.experimental.FieldNameConstants; +import lombok.AccessLevel; + +@FieldNameConstants(level = AccessLevel.PACKAGE) +public class FieldNameConstantsUppercased { + String iAmADvdPlayer; + int $skipMe; + static double skipMeToo; + @FieldNameConstants.Exclude int andMe; + String butPrintMePlease; +} -- cgit 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 ++++++++++++------- .../SuperBuilderWithGenericsAndToBuilder.java | 60 ++++++++++++++-------- .../SuperBuilderWithGenericsAndToBuilder.java | 6 +-- 3 files changed, 77 insertions(+), 42 deletions(-) (limited to 'test/transform') 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(); } } diff --git a/test/transform/resource/after-ecj/SuperBuilderWithGenericsAndToBuilder.java b/test/transform/resource/after-ecj/SuperBuilderWithGenericsAndToBuilder.java index 107ee362..ce960d61 100644 --- a/test/transform/resource/after-ecj/SuperBuilderWithGenericsAndToBuilder.java +++ b/test/transform/resource/after-ecj/SuperBuilderWithGenericsAndToBuilder.java @@ -1,9 +1,10 @@ -import java.util.List; +import java.util.Map; public class SuperBuilderWithGenericsAndToBuilder { public static @lombok.experimental.SuperBuilder(toBuilder = true) class Parent { public static abstract @java.lang.SuppressWarnings("all") class ParentBuilder, B extends ParentBuilder> { private @java.lang.SuppressWarnings("all") A field1; - private @java.lang.SuppressWarnings("all") java.util.ArrayList items; + private @java.lang.SuppressWarnings("all") java.util.ArrayList items$key; + private @java.lang.SuppressWarnings("all") java.util.ArrayList items$value; public ParentBuilder() { super(); } @@ -13,7 +14,7 @@ public class SuperBuilderWithGenericsAndToBuilder { } private static @java.lang.SuppressWarnings("all") 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)); } protected abstract @java.lang.SuppressWarnings("all") B self(); public abstract @java.lang.SuppressWarnings("all") C build(); @@ -21,25 +22,39 @@ public class SuperBuilderWithGenericsAndToBuilder { this.field1 = field1; return self(); } - public @java.lang.SuppressWarnings("all") B item(final String item) { - if ((this.items == null)) - this.items = new java.util.ArrayList(); - this.items.add(item); + public @java.lang.SuppressWarnings("all") 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(); } - public @java.lang.SuppressWarnings("all") B items(final java.util.Collection items) { - if ((this.items == null)) - this.items = new java.util.ArrayList(); - this.items.addAll(items); + public @java.lang.SuppressWarnings("all") 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 (java.util.Map.Entry $lombokEntry : items.entrySet()) + { + this.items$key.add($lombokEntry.getKey()); + this.items$value.add($lombokEntry.getValue()); + } return self(); } public @java.lang.SuppressWarnings("all") B clearItems() { - if ((this.items != null)) - this.items.clear(); + if ((this.items$key != null)) + { + this.items$key.clear(); + this.items$value.clear(); + } return self(); } public @java.lang.Override @java.lang.SuppressWarnings("all") 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) + ")"); } } private static final @java.lang.SuppressWarnings("all") class ParentBuilderImpl extends ParentBuilder, ParentBuilderImpl> { @@ -54,20 +69,23 @@ public class SuperBuilderWithGenericsAndToBuilder { } } A field1; - @lombok.Singular List items; + @lombok.Singular Map items; protected @java.lang.SuppressWarnings("all") Parent(final ParentBuilder b) { super(); 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() < 0x40000000) ? ((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), b.items$value.get($i)); + items = java.util.Collections.unmodifiableMap(items); } this.items = items; } @@ -129,6 +147,6 @@ public class SuperBuilderWithGenericsAndToBuilder { super(); } 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(); } } diff --git a/test/transform/resource/before/SuperBuilderWithGenericsAndToBuilder.java b/test/transform/resource/before/SuperBuilderWithGenericsAndToBuilder.java index dae68034..1f2caf6d 100644 --- a/test/transform/resource/before/SuperBuilderWithGenericsAndToBuilder.java +++ b/test/transform/resource/before/SuperBuilderWithGenericsAndToBuilder.java @@ -1,10 +1,10 @@ -import java.util.List; +import java.util.Map; public class SuperBuilderWithGenericsAndToBuilder { @lombok.experimental.SuperBuilder(toBuilder = true) public static class Parent { A field1; - @lombok.Singular List items; + @lombok.Singular Map items; } @lombok.experimental.SuperBuilder(toBuilder = true) @@ -13,6 +13,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