From a2b884c71194c780d37ccbd84561abd6a0f63741 Mon Sep 17 00:00:00 2001 From: Jan Rieke Date: Tue, 11 Sep 2018 20:37:16 +0200 Subject: SuperBuilder: fixed ObtainVia --- .../after-delombok/SuperBuilderBasicToBuilder.java | 38 +++++++++++++++++++++- .../after-ecj/SuperBuilderBasicToBuilder.java | 33 +++++++++++++++++-- .../before/SuperBuilderBasicToBuilder.java | 14 ++++++++ 3 files changed, 82 insertions(+), 3 deletions(-) (limited to 'test/transform') diff --git a/test/transform/resource/after-delombok/SuperBuilderBasicToBuilder.java b/test/transform/resource/after-delombok/SuperBuilderBasicToBuilder.java index 404984b9..7d34d28a 100644 --- a/test/transform/resource/after-delombok/SuperBuilderBasicToBuilder.java +++ b/test/transform/resource/after-delombok/SuperBuilderBasicToBuilder.java @@ -2,16 +2,34 @@ import java.util.List; public class SuperBuilderBasicToBuilder { public static class Parent { int field1; + int obtainViaField; + int obtainViaMethod; + String obtainViaStaticMethod; List items; + int method() { + return 2; + } + private static String staticMethod(Parent instance) { + return "staticMethod"; + } @java.lang.SuppressWarnings("all") public static abstract class ParentBuilder> { @java.lang.SuppressWarnings("all") private int field1; @java.lang.SuppressWarnings("all") + private int obtainViaField; + @java.lang.SuppressWarnings("all") + private int obtainViaMethod; + @java.lang.SuppressWarnings("all") + private String obtainViaStaticMethod; + @java.lang.SuppressWarnings("all") private java.util.ArrayList items; @java.lang.SuppressWarnings("all") protected B $fillValuesFrom(final C instance) { this.field1(instance.field1); + this.obtainViaField(instance.field1); + this.obtainViaMethod(instance.method()); + this.obtainViaStaticMethod(Parent.staticMethod(instance)); this.items(instance.items == null ? java.util.Collections.emptyList() : instance.items); return self(); } @@ -25,6 +43,21 @@ public class SuperBuilderBasicToBuilder { return self(); } @java.lang.SuppressWarnings("all") + public B obtainViaField(final int obtainViaField) { + this.obtainViaField = obtainViaField; + return self(); + } + @java.lang.SuppressWarnings("all") + public B obtainViaMethod(final int obtainViaMethod) { + this.obtainViaMethod = obtainViaMethod; + return self(); + } + @java.lang.SuppressWarnings("all") + public B obtainViaStaticMethod(final String obtainViaStaticMethod) { + this.obtainViaStaticMethod = obtainViaStaticMethod; + 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); @@ -44,7 +77,7 @@ public class SuperBuilderBasicToBuilder { @java.lang.Override @java.lang.SuppressWarnings("all") public java.lang.String toString() { - return "SuperBuilderBasicToBuilder.Parent.ParentBuilder(field1=" + this.field1 + ", items=" + this.items + ")"; + return "SuperBuilderBasicToBuilder.Parent.ParentBuilder(field1=" + this.field1 + ", obtainViaField=" + this.obtainViaField + ", obtainViaMethod=" + this.obtainViaMethod + ", obtainViaStaticMethod=" + this.obtainViaStaticMethod + ", items=" + this.items + ")"; } } @java.lang.SuppressWarnings("all") @@ -66,6 +99,9 @@ public class SuperBuilderBasicToBuilder { @java.lang.SuppressWarnings("all") protected Parent(final ParentBuilder b) { this.field1 = b.field1; + this.obtainViaField = b.obtainViaField; + this.obtainViaMethod = b.obtainViaMethod; + this.obtainViaStaticMethod = b.obtainViaStaticMethod; java.util.List items; switch (b.items == null ? 0 : b.items.size()) { case 0: diff --git a/test/transform/resource/after-ecj/SuperBuilderBasicToBuilder.java b/test/transform/resource/after-ecj/SuperBuilderBasicToBuilder.java index 2b294d65..974d933d 100644 --- a/test/transform/resource/after-ecj/SuperBuilderBasicToBuilder.java +++ b/test/transform/resource/after-ecj/SuperBuilderBasicToBuilder.java @@ -1,15 +1,20 @@ import java.util.List; - public class SuperBuilderBasicToBuilder { public static @lombok.experimental.SuperBuilder(toBuilder = true) class Parent { public static abstract @java.lang.SuppressWarnings("all") class ParentBuilder> { private @java.lang.SuppressWarnings("all") int field1; + private @java.lang.SuppressWarnings("all") int obtainViaField; + private @java.lang.SuppressWarnings("all") int obtainViaMethod; + private @java.lang.SuppressWarnings("all") String obtainViaStaticMethod; private @java.lang.SuppressWarnings("all") java.util.ArrayList items; public ParentBuilder() { super(); } protected @java.lang.SuppressWarnings("all") B $fillValuesFrom(final C instance) { field1(instance.field1); + obtainViaField(instance.field1); + obtainViaMethod(instance.method()); + obtainViaStaticMethod(Parent.staticMethod(instance)); items(((instance.items == null) ? java.util.Collections.emptyList() : instance.items)); return self(); } @@ -19,6 +24,18 @@ public class SuperBuilderBasicToBuilder { this.field1 = field1; return self(); } + public @java.lang.SuppressWarnings("all") B obtainViaField(final int obtainViaField) { + this.obtainViaField = obtainViaField; + return self(); + } + public @java.lang.SuppressWarnings("all") B obtainViaMethod(final int obtainViaMethod) { + this.obtainViaMethod = obtainViaMethod; + return self(); + } + public @java.lang.SuppressWarnings("all") B obtainViaStaticMethod(final String obtainViaStaticMethod) { + this.obtainViaStaticMethod = obtainViaStaticMethod; + return self(); + } public @java.lang.SuppressWarnings("all") B item(String item) { if ((this.items == null)) this.items = new java.util.ArrayList(); @@ -37,7 +54,7 @@ public class SuperBuilderBasicToBuilder { return self(); } public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { - return (((("SuperBuilderBasicToBuilder.Parent.ParentBuilder(field1=" + this.field1) + ", items=") + this.items) + ")"); + return (((((((((("SuperBuilderBasicToBuilder.Parent.ParentBuilder(field1=" + this.field1) + ", obtainViaField=") + this.obtainViaField) + ", obtainViaMethod=") + this.obtainViaMethod) + ", obtainViaStaticMethod=") + this.obtainViaStaticMethod) + ", items=") + this.items) + ")"); } } private static final @java.lang.SuppressWarnings("all") class ParentBuilderImpl extends ParentBuilder { @@ -52,10 +69,22 @@ public class SuperBuilderBasicToBuilder { } } int field1; + @lombok.Builder.ObtainVia(field = "field1") int obtainViaField; + @lombok.Builder.ObtainVia(method = "method") int obtainViaMethod; + @lombok.Builder.ObtainVia(method = "staticMethod",isStatic = true) String obtainViaStaticMethod; @lombok.Singular List items; + int method() { + return 2; + } + private static String staticMethod(Parent instance) { + return "staticMethod"; + } protected @java.lang.SuppressWarnings("all") Parent(final ParentBuilder b) { super(); this.field1 = b.field1; + this.obtainViaField = b.obtainViaField; + this.obtainViaMethod = b.obtainViaMethod; + this.obtainViaStaticMethod = b.obtainViaStaticMethod; java.util.List items; switch (((b.items == null) ? 0 : b.items.size())) { case 0 : diff --git a/test/transform/resource/before/SuperBuilderBasicToBuilder.java b/test/transform/resource/before/SuperBuilderBasicToBuilder.java index bc3578f5..4dfac613 100644 --- a/test/transform/resource/before/SuperBuilderBasicToBuilder.java +++ b/test/transform/resource/before/SuperBuilderBasicToBuilder.java @@ -4,7 +4,21 @@ public class SuperBuilderBasicToBuilder { @lombok.experimental.SuperBuilder(toBuilder=true) public static class Parent { int field1; + @lombok.Builder.ObtainVia(field="field1") + int obtainViaField; + @lombok.Builder.ObtainVia(method="method") + int obtainViaMethod; + @lombok.Builder.ObtainVia(method = "staticMethod", isStatic = true) + String obtainViaStaticMethod; @lombok.Singular List items; + + int method() { + return 2; + } + + private static String staticMethod(Parent instance) { + return "staticMethod"; + } } @lombok.experimental.SuperBuilder(toBuilder=true) -- cgit