diff options
author | Jan Rieke <it@janrieke.de> | 2018-09-11 20:37:16 +0200 |
---|---|---|
committer | Jan Rieke <it@janrieke.de> | 2018-09-11 20:44:19 +0200 |
commit | a2b884c71194c780d37ccbd84561abd6a0f63741 (patch) | |
tree | 53c91b1c713c8db0523999bb28592ef8f40d7e08 | |
parent | da59d2d6375afcfcf6cb43288adba61cb99a49e8 (diff) | |
download | lombok-a2b884c71194c780d37ccbd84561abd6a0f63741.tar.gz lombok-a2b884c71194c780d37ccbd84561abd6a0f63741.tar.bz2 lombok-a2b884c71194c780d37ccbd84561abd6a0f63741.zip |
SuperBuilder: fixed ObtainVia
4 files changed, 84 insertions, 5 deletions
diff --git a/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java b/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java index 1bbc514e..bb78e82a 100644 --- a/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java +++ b/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java @@ -646,9 +646,9 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler<SuperBuilder> { 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); + obtainExpr.receiver = obtainIsStatic ? new SingleNameReference(type.getName().toCharArray(), 0) : new SingleNameReference(instanceVariableName.toCharArray(), 0); obtainExpr.selector = obtainName.toCharArray(); - if (obtainIsStatic) obtainExpr.arguments = new Expression[] {new ThisReference(0, 0)}; + if (obtainIsStatic) obtainExpr.arguments = new Expression[] {new SingleNameReference(instanceVariableName.toCharArray(), 0)}; tgt[i] = obtainExpr; } } 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<String> items;
+ int method() {
+ return 2;
+ }
+ private static String staticMethod(Parent instance) {
+ return "staticMethod";
+ }
@java.lang.SuppressWarnings("all")
public static abstract class ParentBuilder<C extends Parent, B extends ParentBuilder<C, B>> {
@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<String> 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<String>();
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<String> 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<C extends Parent, B extends ParentBuilder<C, B>> {
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<String> 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<String>();
@@ -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<Parent, ParentBuilderImpl> {
@@ -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<String> 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<String> 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<String> items; + + int method() { + return 2; + } + + private static String staticMethod(Parent instance) { + return "staticMethod"; + } } @lombok.experimental.SuperBuilder(toBuilder=true) |