Skip to content

Commit

Permalink
feat: allow generics with SuperBuilder customization
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathaniel Troutman committed Apr 1, 2024
1 parent 9dc7e7f commit cf064e3
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/core/lombok/javac/handlers/HandleSuperBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -1160,7 +1160,7 @@ private boolean constructorExists(JavacNode type, String builderClassName) {
if (lastIndexOfDot >= 0) {
typeName = typeName.substring(lastIndexOfDot+1);
}
if ((builderClassName+"<?, ?>").equals(typeName))
if (typeName.startsWith(builderClassName) && typeName.endsWith("?, ?>"))
return true;
}
}
Expand Down
22 changes: 11 additions & 11 deletions test/transform/resource/after-delombok/SuperBuilderCustomized.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import java.util.List;
public class SuperBuilderCustomized {
public static class Parent {
public static abstract class ParentBuilder<C extends Parent, B extends ParentBuilder<C, B>> {
public static class Parent<T> {
public static abstract class ParentBuilder<T, C extends Parent<T>, B extends ParentBuilder<T, C, B>> {
@java.lang.SuppressWarnings("all")
private int field1;
public B resetToDefault() {
Expand All @@ -23,31 +23,31 @@ public java.lang.String toString() {
}
}
int field1;
protected Parent(ParentBuilder<?, ?> b) {
protected Parent(ParentBuilder<?, ?, ?> b) {
if (b.field1 == 0) throw new IllegalArgumentException("field1 must be != 0");
this.field1 = b.field1;
}
public static SuperBuilderCustomized.Parent.ParentBuilder<?, ?> builder(int field1) {
return new SuperBuilderCustomized.Parent.ParentBuilderImpl().field1(field1);
public static <T> SuperBuilderCustomized.Parent.ParentBuilder<T, ?, ?> builder(int field1) {
return new SuperBuilderCustomized.Parent.ParentBuilderImpl<T>().field1(field1);
}
@java.lang.SuppressWarnings("all")
private static final class ParentBuilderImpl extends SuperBuilderCustomized.Parent.ParentBuilder<SuperBuilderCustomized.Parent, SuperBuilderCustomized.Parent.ParentBuilderImpl> {
private static final class ParentBuilderImpl<T> extends SuperBuilderCustomized.Parent.ParentBuilder<T, SuperBuilderCustomized.Parent<T>, SuperBuilderCustomized.Parent.ParentBuilderImpl<T>> {
@java.lang.SuppressWarnings("all")
private ParentBuilderImpl() {
}
@java.lang.Override
@java.lang.SuppressWarnings("all")
protected SuperBuilderCustomized.Parent.ParentBuilderImpl self() {
protected SuperBuilderCustomized.Parent.ParentBuilderImpl<T> self() {
return this;
}
@java.lang.Override
@java.lang.SuppressWarnings("all")
public SuperBuilderCustomized.Parent build() {
return new SuperBuilderCustomized.Parent(this);
public SuperBuilderCustomized.Parent<T> build() {
return new SuperBuilderCustomized.Parent<T>(this);
}
}
}
public static class Child extends Parent {
public static class Child extends Parent<String> {
private static final class ChildBuilderImpl extends ChildBuilder<Child, ChildBuilderImpl> {
@Override
public Child build() {
Expand All @@ -68,7 +68,7 @@ protected SuperBuilderCustomized.Child.ChildBuilderImpl self() {
return new ChildBuilderImpl().field2(10.0);
}
@java.lang.SuppressWarnings("all")
public static abstract class ChildBuilder<C extends SuperBuilderCustomized.Child, B extends SuperBuilderCustomized.Child.ChildBuilder<C, B>> extends Parent.ParentBuilder<C, B> {
public static abstract class ChildBuilder<C extends SuperBuilderCustomized.Child, B extends SuperBuilderCustomized.Child.ChildBuilder<C, B>> extends Parent.ParentBuilder<String, C, B> {
@java.lang.SuppressWarnings("all")
private double field2;
/**
Expand Down
22 changes: 11 additions & 11 deletions test/transform/resource/after-ecj/SuperBuilderCustomized.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import java.util.List;
public class SuperBuilderCustomized {
public static @lombok.experimental.SuperBuilder class Parent {
public static abstract class ParentBuilder<C extends Parent, B extends ParentBuilder<C, B>> {
public static @lombok.experimental.SuperBuilder class Parent<T> {
public static abstract class ParentBuilder<T, C extends Parent<T>, B extends ParentBuilder<T, C, B>> {
private @java.lang.SuppressWarnings("all") int field1;
public ParentBuilder() {
super();
Expand All @@ -20,29 +20,29 @@ public B field1(int field1) {
return (("SuperBuilderCustomized.Parent.ParentBuilder(field1=" + this.field1) + ")");
}
}
private static final @java.lang.SuppressWarnings("all") class ParentBuilderImpl extends SuperBuilderCustomized.Parent.ParentBuilder<SuperBuilderCustomized.Parent, SuperBuilderCustomized.Parent.ParentBuilderImpl> {
private static final @java.lang.SuppressWarnings("all") class ParentBuilderImpl<T> extends SuperBuilderCustomized.Parent.ParentBuilder<T, SuperBuilderCustomized.Parent<T>, SuperBuilderCustomized.Parent.ParentBuilderImpl<T>> {
private ParentBuilderImpl() {
super();
}
protected @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderCustomized.Parent.ParentBuilderImpl self() {
protected @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderCustomized.Parent.ParentBuilderImpl<T> self() {
return this;
}
public @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderCustomized.Parent build() {
return new SuperBuilderCustomized.Parent(this);
public @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderCustomized.Parent<T> build() {
return new SuperBuilderCustomized.Parent<T>(this);
}
}
int field1;
protected Parent(ParentBuilder<?, ?> b) {
protected Parent(ParentBuilder<?, ?, ?> b) {
super();
if ((b.field1 == 0))
throw new IllegalArgumentException("field1 must be != 0");
this.field1 = b.field1;
}
public static SuperBuilderCustomized.Parent.ParentBuilder<?, ?> builder(int field1) {
return new SuperBuilderCustomized.Parent.ParentBuilderImpl().field1(field1);
public static <T>SuperBuilderCustomized.Parent.ParentBuilder<T, ?, ?> builder(int field1) {
return new SuperBuilderCustomized.Parent.ParentBuilderImpl<T>().field1(field1);
}
}
public static @lombok.experimental.SuperBuilder class Child extends Parent {
public static @lombok.experimental.SuperBuilder class Child extends Parent<String> {
private static final class ChildBuilderImpl extends ChildBuilder<Child, ChildBuilderImpl> {
private ChildBuilderImpl() {
super();
Expand All @@ -55,7 +55,7 @@ private ChildBuilderImpl() {
return this;
}
}
public static abstract @java.lang.SuppressWarnings("all") class ChildBuilder<C extends SuperBuilderCustomized.Child, B extends SuperBuilderCustomized.Child.ChildBuilder<C, B>> extends Parent.ParentBuilder<C, B> {
public static abstract @java.lang.SuppressWarnings("all") class ChildBuilder<C extends SuperBuilderCustomized.Child, B extends SuperBuilderCustomized.Child.ChildBuilder<C, B>> extends Parent.ParentBuilder<String, C, B> {
private @java.lang.SuppressWarnings("all") double field2;
public ChildBuilder() {
super();
Expand Down
12 changes: 6 additions & 6 deletions test/transform/resource/before/SuperBuilderCustomized.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

public class SuperBuilderCustomized {
@lombok.experimental.SuperBuilder
public static class Parent {
public static abstract class ParentBuilder<C extends Parent, B extends ParentBuilder<C, B>> {
public static class Parent<T> {
public static abstract class ParentBuilder<T, C extends Parent<T>, B extends ParentBuilder<T, C, B>> {
public B resetToDefault() {
field1 = 0;
return self();
Expand All @@ -16,19 +16,19 @@ public B field1(int field1) {
}
int field1;

protected Parent(ParentBuilder<?, ?> b) {
protected Parent(ParentBuilder<?, ?, ?> b) {
if (b.field1 == 0)
throw new IllegalArgumentException("field1 must be != 0");
this.field1 = b.field1;
}

public static SuperBuilderCustomized.Parent.ParentBuilder<?, ?> builder(int field1) {
return new SuperBuilderCustomized.Parent.ParentBuilderImpl().field1(field1);
public static <T> SuperBuilderCustomized.Parent.ParentBuilder<T, ?, ?> builder(int field1) {
return new SuperBuilderCustomized.Parent.ParentBuilderImpl<T>().field1(field1);
}
}

@lombok.experimental.SuperBuilder
public static class Child extends Parent {
public static class Child extends Parent<String> {
private static final class ChildBuilderImpl extends ChildBuilder<Child, ChildBuilderImpl> {
@Override
public Child build() {
Expand Down

0 comments on commit cf064e3

Please sign in to comment.