aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@zwitserloot.com>2018-04-04 23:26:01 +0200
committerReinier Zwitserloot <reinier@zwitserloot.com>2018-04-04 23:26:20 +0200
commit3eea3b958946dd813197f00a1292b7a72380878a (patch)
tree9f8e16f6d1544e28be713d1c57f3666f1ced9494 /test
parent6b0b1a6a7ba73a2c43bb8ab413375505d61aacc6 (diff)
downloadlombok-3eea3b958946dd813197f00a1292b7a72380878a.tar.gz
lombok-3eea3b958946dd813197f00a1292b7a72380878a.tar.bz2
lombok-3eea3b958946dd813197f00a1292b7a72380878a.zip
introduction of `@SuperBuilder` and a testcase.
Diffstat (limited to 'test')
-rw-r--r--test/transform/resource/after-delombok/SuperBuilderBasic.java112
-rw-r--r--test/transform/resource/before/SuperBuilderBasic.java (renamed from test/transform/resource/before/BuilderWithInherit.java)8
2 files changed, 116 insertions, 4 deletions
diff --git a/test/transform/resource/after-delombok/SuperBuilderBasic.java b/test/transform/resource/after-delombok/SuperBuilderBasic.java
new file mode 100644
index 00000000..ffb56e0e
--- /dev/null
+++ b/test/transform/resource/after-delombok/SuperBuilderBasic.java
@@ -0,0 +1,112 @@
+import java.util.List;
+
+public class SuperBuilderBasic {
+ public static class Parent {
+ int field1;
+ List<String> items;
+ protected Parent(final ParentBuilder<?, ?> b) {
+ this.field1 = b.field1;
+ java.util.List<String> 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<String>(b.items));
+ }
+ this.items = items;
+ }
+ private static class ParentBuilderImpl extends ParentBuilder<Parent, ParentBuilderImpl> {
+ @Override
+ public Parent build() {
+ return new Parent(this);
+ }
+
+ @Override
+ public ParentBuilderImpl self() {
+ return this;
+ }
+ }
+ public abstract static class ParentBuilder<C extends Parent, B extends ParentBuilder<C, B>> {
+ @java.lang.SuppressWarnings("all")
+ private int field1;
+ @java.lang.SuppressWarnings("all")
+ private java.util.ArrayList<String> items;
+ @java.lang.SuppressWarnings("all")
+ ParentBuilder() {
+ }
+ @java.lang.SuppressWarnings("all")
+ public B field1(final int field1) {
+ this.field1 = field1;
+ 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);
+ return self();
+ }
+ @java.lang.SuppressWarnings("all")
+ public B items(final java.util.Collection<? extends String> items) {
+ if (this.items == null) this.items = new java.util.ArrayList<String>();
+ this.items.addAll(items);
+ return self();
+ }
+ @java.lang.SuppressWarnings("all")
+ public B clearItems() {
+ if (this.items != null) this.items.clear();
+ return self();
+ }
+ @java.lang.SuppressWarnings("all")
+ protected abstract B self();
+ @java.lang.SuppressWarnings("all")
+ public abstract C build();
+ }
+ public static ParentBuilder<?, ?> builder() {
+ return new ParentBuilderImpl();
+ }
+ }
+ public static class Child extends Parent {
+ double field3;
+ protected Child(ChildBuilder<?, ?> b) {
+ super(b);
+ this.field3 = b.field3;
+ }
+ private static class ChildBuilderImpl extends ChildBuilder<Child, ChildBuilderImpl> {
+ @Override
+ public Child build() {
+ return new Child(this);
+ }
+
+ @Override
+ public ChildBuilderImpl self() {
+ return this;
+ }
+ }
+ public abstract static class ChildBuilder<C extends Child, B extends ChildBuilder<C, B>> extends Parent.ParentBuilder<Child, B> {
+ @java.lang.SuppressWarnings("all")
+ private double field3;
+ @java.lang.SuppressWarnings("all")
+ ChildBuilder() {
+ }
+ @java.lang.SuppressWarnings("all")
+ public B field3(final double field3) {
+ this.field3 = field3;
+ return self();
+ }
+ @java.lang.SuppressWarnings("all")
+ protected abstract B self();
+ @java.lang.SuppressWarnings("all")
+ public abstract C build();
+ }
+ public static ChildBuilder<?, ?> builder() {
+ return new ChildBuilderImpl();
+ }
+ }
+ public static void test() {
+ Child x = Child.builder().field3(0.0).field1(5).item("").build();
+ }
+}
diff --git a/test/transform/resource/before/BuilderWithInherit.java b/test/transform/resource/before/SuperBuilderBasic.java
index dcc7b5ad..bf3eea64 100644
--- a/test/transform/resource/before/BuilderWithInherit.java
+++ b/test/transform/resource/before/SuperBuilderBasic.java
@@ -1,15 +1,15 @@
-import lombok.Builder;
+import lombok.experimental.SuperBuilder;
import lombok.Singular;
import java.util.List;
-public class BuilderWithInherit {
- @Builder(extensible = true)
+public class SuperBuilderBasic {
+ @SuperBuilder
public static class Parent {
int field1;
@Singular List<String> items;
}
- @Builder(inherit = true)
+ @SuperBuilder
public static class Child extends Parent {
double field3;
}