Skip to content

Commit 3b68e39

Browse files
authored
Merge pull request #3697 from janrieke/superbuilder-fix-array-type-param
SuperBuilder: fix builder class extends clause for array type parameters
2 parents fdafa9a + ce2eda8 commit 3b68e39

File tree

5 files changed

+240
-1
lines changed

5 files changed

+240
-1
lines changed

doc/changelog.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Lombok Changelog
55
* PLATFORM: Added support for Eclipse 2024-06; you'd get some `NoSuchMethodError` traces in your logs if using `@Builder` or `@Singular` prior to this fix. [Issue #3638](https://github.com/projectlombok/lombok/issues/3638).
66
* IMPROBABLE BREAKING CHANGE: Lombok now adds `@lombok.Generated` by default to methods and types it generates. This may result in accidentally increasing your test coverage percentage. [Issue #3667](https://github.com/projectlombok/lombok/issues/3667).
77
* IMPROBABLE BREAKING CHANGE: When `lombok.config` contains `lombok.onX.flagUsage = WARNING`, from now on warnings will actually be generated if onX is used.[Issue #2848](https://github.com/projectlombok/lombok/issues/2848)
8+
* BUGFIX: When `@SuperBuilder` was used on a type with an generic array type, it would error `wrong number of type arguments`. [Issue #3694](https://github.com/projectlombok/lombok/issues/3694).
89

910
### v1.18.32 (March 20th, 2024)
1011
* PLATFORM: Initial JDK22 support added.

src/core/lombok/javac/handlers/HandleSuperBuilder.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import com.sun.tools.javac.code.Flags;
3737
import com.sun.tools.javac.tree.JCTree;
3838
import com.sun.tools.javac.tree.JCTree.JCAnnotation;
39+
import com.sun.tools.javac.tree.JCTree.JCArrayTypeTree;
3940
import com.sun.tools.javac.tree.JCTree.JCAssign;
4041
import com.sun.tools.javac.tree.JCTree.JCBlock;
4142
import com.sun.tools.javac.tree.JCTree.JCClassDecl;
@@ -63,9 +64,9 @@
6364
import lombok.Singular;
6465
import lombok.ToString;
6566
import lombok.core.AST.Kind;
66-
import lombok.core.configuration.CheckerFrameworkVersion;
6767
import lombok.core.AnnotationValues;
6868
import lombok.core.HandlerPriority;
69+
import lombok.core.configuration.CheckerFrameworkVersion;
6970
import lombok.core.handlers.HandlerUtil;
7071
import lombok.core.handlers.HandlerUtil.FieldAccess;
7172
import lombok.core.handlers.InclusionExclusionUtils.Included;
@@ -78,6 +79,7 @@
7879
import lombok.javac.handlers.HandleBuilder.BuilderFieldData;
7980
import lombok.javac.handlers.HandleBuilder.BuilderJob;
8081
import lombok.javac.handlers.JavacHandlerUtil.CopyJavadoc;
82+
import lombok.javac.handlers.JavacHandlerUtil.JCAnnotatedTypeReflect;
8183
import lombok.javac.handlers.JavacHandlerUtil.MemberExistsResult;
8284
import lombok.javac.handlers.JavacSingularsRecipes.ExpressionMaker;
8385
import lombok.javac.handlers.JavacSingularsRecipes.JavacSingularizer;
@@ -1108,6 +1110,8 @@ private ListBuffer<JCExpression> getTypeParamExpressions(List<? extends JCTree>
11081110
typeParamsForBuilderParameter.append(copySelect(maker, (JCFieldAccess) typeParam));
11091111
} else if (typeParam instanceof JCTypeApply) {
11101112
typeParamsForBuilderParameter.append(cloneType(maker, (JCTypeApply)typeParam, source));
1113+
} else if (typeParam instanceof JCArrayTypeTree) {
1114+
typeParamsForBuilderParameter.append(cloneType(maker, (JCArrayTypeTree)typeParam, source));
11111115
} else if (JCAnnotatedTypeReflect.is(typeParam)) {
11121116
typeParamsForBuilderParameter.append(cloneType(maker, (JCExpression)typeParam, source));
11131117
}
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
//version 8:
2+
public class SuperBuilderWithArrayTypeParam {
3+
public static class Parent<A> {
4+
A field1;
5+
@java.lang.SuppressWarnings("all")
6+
@lombok.Generated
7+
public static abstract class ParentBuilder<A, C extends SuperBuilderWithArrayTypeParam.Parent<A>, B extends SuperBuilderWithArrayTypeParam.Parent.ParentBuilder<A, C, B>> {
8+
@java.lang.SuppressWarnings("all")
9+
@lombok.Generated
10+
private A field1;
11+
/**
12+
* @return {@code this}.
13+
*/
14+
@java.lang.SuppressWarnings("all")
15+
@lombok.Generated
16+
public B field1(final A field1) {
17+
this.field1 = field1;
18+
return self();
19+
}
20+
@java.lang.SuppressWarnings("all")
21+
@lombok.Generated
22+
protected abstract B self();
23+
@java.lang.SuppressWarnings("all")
24+
@lombok.Generated
25+
public abstract C build();
26+
@java.lang.Override
27+
@java.lang.SuppressWarnings("all")
28+
@lombok.Generated
29+
public java.lang.String toString() {
30+
return "SuperBuilderWithArrayTypeParam.Parent.ParentBuilder(field1=" + this.field1 + ")";
31+
}
32+
}
33+
@java.lang.SuppressWarnings("all")
34+
@lombok.Generated
35+
private static final class ParentBuilderImpl<A> extends SuperBuilderWithArrayTypeParam.Parent.ParentBuilder<A, SuperBuilderWithArrayTypeParam.Parent<A>, SuperBuilderWithArrayTypeParam.Parent.ParentBuilderImpl<A>> {
36+
@java.lang.SuppressWarnings("all")
37+
@lombok.Generated
38+
private ParentBuilderImpl() {
39+
}
40+
@java.lang.Override
41+
@java.lang.SuppressWarnings("all")
42+
@lombok.Generated
43+
protected SuperBuilderWithArrayTypeParam.Parent.ParentBuilderImpl<A> self() {
44+
return this;
45+
}
46+
@java.lang.Override
47+
@java.lang.SuppressWarnings("all")
48+
@lombok.Generated
49+
public SuperBuilderWithArrayTypeParam.Parent<A> build() {
50+
return new SuperBuilderWithArrayTypeParam.Parent<A>(this);
51+
}
52+
}
53+
@java.lang.SuppressWarnings("all")
54+
@lombok.Generated
55+
protected Parent(final SuperBuilderWithArrayTypeParam.Parent.ParentBuilder<A, ?, ?> b) {
56+
this.field1 = b.field1;
57+
}
58+
@java.lang.SuppressWarnings("all")
59+
@lombok.Generated
60+
public static <A> SuperBuilderWithArrayTypeParam.Parent.ParentBuilder<A, ?, ?> builder() {
61+
return new SuperBuilderWithArrayTypeParam.Parent.ParentBuilderImpl<A>();
62+
}
63+
}
64+
public static class Child extends Parent<Integer[]> {
65+
double field3;
66+
@java.lang.SuppressWarnings("all")
67+
@lombok.Generated
68+
public static abstract class ChildBuilder<C extends SuperBuilderWithArrayTypeParam.Child, B extends SuperBuilderWithArrayTypeParam.Child.ChildBuilder<C, B>> extends Parent.ParentBuilder<Integer[], C, B> {
69+
@java.lang.SuppressWarnings("all")
70+
@lombok.Generated
71+
private double field3;
72+
/**
73+
* @return {@code this}.
74+
*/
75+
@java.lang.SuppressWarnings("all")
76+
@lombok.Generated
77+
public B field3(final double field3) {
78+
this.field3 = field3;
79+
return self();
80+
}
81+
@java.lang.Override
82+
@java.lang.SuppressWarnings("all")
83+
@lombok.Generated
84+
protected abstract B self();
85+
@java.lang.Override
86+
@java.lang.SuppressWarnings("all")
87+
@lombok.Generated
88+
public abstract C build();
89+
@java.lang.Override
90+
@java.lang.SuppressWarnings("all")
91+
@lombok.Generated
92+
public java.lang.String toString() {
93+
return "SuperBuilderWithArrayTypeParam.Child.ChildBuilder(super=" + super.toString() + ", field3=" + this.field3 + ")";
94+
}
95+
}
96+
@java.lang.SuppressWarnings("all")
97+
@lombok.Generated
98+
private static final class ChildBuilderImpl extends SuperBuilderWithArrayTypeParam.Child.ChildBuilder<SuperBuilderWithArrayTypeParam.Child, SuperBuilderWithArrayTypeParam.Child.ChildBuilderImpl> {
99+
@java.lang.SuppressWarnings("all")
100+
@lombok.Generated
101+
private ChildBuilderImpl() {
102+
}
103+
@java.lang.Override
104+
@java.lang.SuppressWarnings("all")
105+
@lombok.Generated
106+
protected SuperBuilderWithArrayTypeParam.Child.ChildBuilderImpl self() {
107+
return this;
108+
}
109+
@java.lang.Override
110+
@java.lang.SuppressWarnings("all")
111+
@lombok.Generated
112+
public SuperBuilderWithArrayTypeParam.Child build() {
113+
return new SuperBuilderWithArrayTypeParam.Child(this);
114+
}
115+
}
116+
@java.lang.SuppressWarnings("all")
117+
@lombok.Generated
118+
protected Child(final SuperBuilderWithArrayTypeParam.Child.ChildBuilder<?, ?> b) {
119+
super(b);
120+
this.field3 = b.field3;
121+
}
122+
@java.lang.SuppressWarnings("all")
123+
@lombok.Generated
124+
public static SuperBuilderWithArrayTypeParam.Child.ChildBuilder<?, ?> builder() {
125+
return new SuperBuilderWithArrayTypeParam.Child.ChildBuilderImpl();
126+
}
127+
}
128+
public static void test() {
129+
Child x = Child.builder().field3(0.0).field1(new Integer[] {2}).build();
130+
}
131+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
//version 8:
2+
public class SuperBuilderWithArrayTypeParam {
3+
public static @lombok.experimental.SuperBuilder class Parent<A> {
4+
public static abstract @java.lang.SuppressWarnings("all") @lombok.Generated class ParentBuilder<A, C extends SuperBuilderWithArrayTypeParam.Parent<A>, B extends SuperBuilderWithArrayTypeParam.Parent.ParentBuilder<A, C, B>> {
5+
private @java.lang.SuppressWarnings("all") @lombok.Generated A field1;
6+
public ParentBuilder() {
7+
super();
8+
}
9+
/**
10+
* @return {@code this}.
11+
*/
12+
public @java.lang.SuppressWarnings("all") @lombok.Generated B field1(final A field1) {
13+
this.field1 = field1;
14+
return self();
15+
}
16+
protected abstract @java.lang.SuppressWarnings("all") @lombok.Generated B self();
17+
public abstract @java.lang.SuppressWarnings("all") @lombok.Generated C build();
18+
public @java.lang.Override @java.lang.SuppressWarnings("all") @lombok.Generated java.lang.String toString() {
19+
return (("SuperBuilderWithArrayTypeParam.Parent.ParentBuilder(field1=" + this.field1) + ")");
20+
}
21+
}
22+
private static final @java.lang.SuppressWarnings("all") @lombok.Generated class ParentBuilderImpl<A> extends SuperBuilderWithArrayTypeParam.Parent.ParentBuilder<A, SuperBuilderWithArrayTypeParam.Parent<A>, SuperBuilderWithArrayTypeParam.Parent.ParentBuilderImpl<A>> {
23+
private ParentBuilderImpl() {
24+
super();
25+
}
26+
protected @java.lang.Override @java.lang.SuppressWarnings("all") @lombok.Generated SuperBuilderWithArrayTypeParam.Parent.ParentBuilderImpl<A> self() {
27+
return this;
28+
}
29+
public @java.lang.Override @java.lang.SuppressWarnings("all") @lombok.Generated SuperBuilderWithArrayTypeParam.Parent<A> build() {
30+
return new SuperBuilderWithArrayTypeParam.Parent<A>(this);
31+
}
32+
}
33+
A field1;
34+
protected @java.lang.SuppressWarnings("all") @lombok.Generated Parent(final SuperBuilderWithArrayTypeParam.Parent.ParentBuilder<A, ?, ?> b) {
35+
super();
36+
this.field1 = b.field1;
37+
}
38+
public static @java.lang.SuppressWarnings("all") @lombok.Generated <A>SuperBuilderWithArrayTypeParam.Parent.ParentBuilder<A, ?, ?> builder() {
39+
return new SuperBuilderWithArrayTypeParam.Parent.ParentBuilderImpl<A>();
40+
}
41+
}
42+
public static @lombok.experimental.SuperBuilder class Child extends Parent<Integer[]> {
43+
public static abstract @java.lang.SuppressWarnings("all") @lombok.Generated class ChildBuilder<C extends SuperBuilderWithArrayTypeParam.Child, B extends SuperBuilderWithArrayTypeParam.Child.ChildBuilder<C, B>> extends Parent.ParentBuilder<Integer[], C, B> {
44+
private @java.lang.SuppressWarnings("all") @lombok.Generated double field3;
45+
public ChildBuilder() {
46+
super();
47+
}
48+
/**
49+
* @return {@code this}.
50+
*/
51+
public @java.lang.SuppressWarnings("all") @lombok.Generated B field3(final double field3) {
52+
this.field3 = field3;
53+
return self();
54+
}
55+
protected abstract @java.lang.Override @java.lang.SuppressWarnings("all") @lombok.Generated B self();
56+
public abstract @java.lang.Override @java.lang.SuppressWarnings("all") @lombok.Generated C build();
57+
public @java.lang.Override @java.lang.SuppressWarnings("all") @lombok.Generated java.lang.String toString() {
58+
return (((("SuperBuilderWithArrayTypeParam.Child.ChildBuilder(super=" + super.toString()) + ", field3=") + this.field3) + ")");
59+
}
60+
}
61+
private static final @java.lang.SuppressWarnings("all") @lombok.Generated class ChildBuilderImpl extends SuperBuilderWithArrayTypeParam.Child.ChildBuilder<SuperBuilderWithArrayTypeParam.Child, SuperBuilderWithArrayTypeParam.Child.ChildBuilderImpl> {
62+
private ChildBuilderImpl() {
63+
super();
64+
}
65+
protected @java.lang.Override @java.lang.SuppressWarnings("all") @lombok.Generated SuperBuilderWithArrayTypeParam.Child.ChildBuilderImpl self() {
66+
return this;
67+
}
68+
public @java.lang.Override @java.lang.SuppressWarnings("all") @lombok.Generated SuperBuilderWithArrayTypeParam.Child build() {
69+
return new SuperBuilderWithArrayTypeParam.Child(this);
70+
}
71+
}
72+
double field3;
73+
protected @java.lang.SuppressWarnings("all") @lombok.Generated Child(final SuperBuilderWithArrayTypeParam.Child.ChildBuilder<?, ?> b) {
74+
super(b);
75+
this.field3 = b.field3;
76+
}
77+
public static @java.lang.SuppressWarnings("all") @lombok.Generated SuperBuilderWithArrayTypeParam.Child.ChildBuilder<?, ?> builder() {
78+
return new SuperBuilderWithArrayTypeParam.Child.ChildBuilderImpl();
79+
}
80+
}
81+
public SuperBuilderWithArrayTypeParam() {
82+
super();
83+
}
84+
public static void test() {
85+
Child x = Child.builder().field3(0.0).field1(new Integer[]{2}).build();
86+
}
87+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//version 8:
2+
public class SuperBuilderWithArrayTypeParam {
3+
@lombok.experimental.SuperBuilder
4+
public static class Parent<A> {
5+
A field1;
6+
}
7+
8+
@lombok.experimental.SuperBuilder
9+
public static class Child extends Parent<Integer[]> {
10+
double field3;
11+
}
12+
13+
public static void test() {
14+
Child x = Child.builder().field3(0.0).field1(new Integer[] {2}).build();
15+
}
16+
}

0 commit comments

Comments
 (0)