From cf064e3faf17dd8bcf694c3525c0fc350489fad5 Mon Sep 17 00:00:00 2001 From: Nathaniel Troutman Date: Mon, 1 Apr 2024 11:19:23 -0700 Subject: [PATCH] feat: allow generics with SuperBuilder customization --- .../javac/handlers/HandleSuperBuilder.java | 2 +- .../SuperBuilderCustomized.java | 22 +++++++++---------- .../after-ecj/SuperBuilderCustomized.java | 22 +++++++++---------- .../before/SuperBuilderCustomized.java | 12 +++++----- 4 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/core/lombok/javac/handlers/HandleSuperBuilder.java b/src/core/lombok/javac/handlers/HandleSuperBuilder.java index d64daf385a..48ec642e22 100644 --- a/src/core/lombok/javac/handlers/HandleSuperBuilder.java +++ b/src/core/lombok/javac/handlers/HandleSuperBuilder.java @@ -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; } } diff --git a/test/transform/resource/after-delombok/SuperBuilderCustomized.java b/test/transform/resource/after-delombok/SuperBuilderCustomized.java index 5f41cdde9e..637c9c590e 100644 --- a/test/transform/resource/after-delombok/SuperBuilderCustomized.java +++ b/test/transform/resource/after-delombok/SuperBuilderCustomized.java @@ -1,7 +1,7 @@ import java.util.List; public class SuperBuilderCustomized { - public static class Parent { - public static abstract class ParentBuilder> { + public static class Parent { + public static abstract class ParentBuilder, B extends ParentBuilder> { @java.lang.SuppressWarnings("all") private int field1; public B resetToDefault() { @@ -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 SuperBuilderCustomized.Parent.ParentBuilder builder(int field1) { + return new SuperBuilderCustomized.Parent.ParentBuilderImpl().field1(field1); } @java.lang.SuppressWarnings("all") - private static final class ParentBuilderImpl extends SuperBuilderCustomized.Parent.ParentBuilder { + private static final class ParentBuilderImpl extends SuperBuilderCustomized.Parent.ParentBuilder, SuperBuilderCustomized.Parent.ParentBuilderImpl> { @java.lang.SuppressWarnings("all") private ParentBuilderImpl() { } @java.lang.Override @java.lang.SuppressWarnings("all") - protected SuperBuilderCustomized.Parent.ParentBuilderImpl self() { + protected SuperBuilderCustomized.Parent.ParentBuilderImpl self() { return this; } @java.lang.Override @java.lang.SuppressWarnings("all") - public SuperBuilderCustomized.Parent build() { - return new SuperBuilderCustomized.Parent(this); + public SuperBuilderCustomized.Parent build() { + return new SuperBuilderCustomized.Parent(this); } } } - public static class Child extends Parent { + public static class Child extends Parent { private static final class ChildBuilderImpl extends ChildBuilder { @Override public Child build() { @@ -68,7 +68,7 @@ protected SuperBuilderCustomized.Child.ChildBuilderImpl self() { return new ChildBuilderImpl().field2(10.0); } @java.lang.SuppressWarnings("all") - public static abstract class ChildBuilder> extends Parent.ParentBuilder { + public static abstract class ChildBuilder> extends Parent.ParentBuilder { @java.lang.SuppressWarnings("all") private double field2; /** diff --git a/test/transform/resource/after-ecj/SuperBuilderCustomized.java b/test/transform/resource/after-ecj/SuperBuilderCustomized.java index e84ffe144c..fe547e3a86 100644 --- a/test/transform/resource/after-ecj/SuperBuilderCustomized.java +++ b/test/transform/resource/after-ecj/SuperBuilderCustomized.java @@ -1,7 +1,7 @@ import java.util.List; public class SuperBuilderCustomized { - public static @lombok.experimental.SuperBuilder class Parent { - public static abstract class ParentBuilder> { + public static @lombok.experimental.SuperBuilder class Parent { + public static abstract class ParentBuilder, B extends ParentBuilder> { private @java.lang.SuppressWarnings("all") int field1; public ParentBuilder() { super(); @@ -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 { + private static final @java.lang.SuppressWarnings("all") class ParentBuilderImpl extends SuperBuilderCustomized.Parent.ParentBuilder, SuperBuilderCustomized.Parent.ParentBuilderImpl> { 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 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 build() { + return new SuperBuilderCustomized.Parent(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 SuperBuilderCustomized.Parent.ParentBuilder builder(int field1) { + return new SuperBuilderCustomized.Parent.ParentBuilderImpl().field1(field1); } } - public static @lombok.experimental.SuperBuilder class Child extends Parent { + public static @lombok.experimental.SuperBuilder class Child extends Parent { private static final class ChildBuilderImpl extends ChildBuilder { private ChildBuilderImpl() { super(); @@ -55,7 +55,7 @@ private ChildBuilderImpl() { return this; } } - public static abstract @java.lang.SuppressWarnings("all") class ChildBuilder> extends Parent.ParentBuilder { + public static abstract @java.lang.SuppressWarnings("all") class ChildBuilder> extends Parent.ParentBuilder { private @java.lang.SuppressWarnings("all") double field2; public ChildBuilder() { super(); diff --git a/test/transform/resource/before/SuperBuilderCustomized.java b/test/transform/resource/before/SuperBuilderCustomized.java index 652d086540..9a4b60bc3f 100644 --- a/test/transform/resource/before/SuperBuilderCustomized.java +++ b/test/transform/resource/before/SuperBuilderCustomized.java @@ -3,8 +3,8 @@ public class SuperBuilderCustomized { @lombok.experimental.SuperBuilder - public static class Parent { - public static abstract class ParentBuilder> { + public static class Parent { + public static abstract class ParentBuilder, B extends ParentBuilder> { public B resetToDefault() { field1 = 0; return self(); @@ -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 SuperBuilderCustomized.Parent.ParentBuilder builder(int field1) { + return new SuperBuilderCustomized.Parent.ParentBuilderImpl().field1(field1); } } @lombok.experimental.SuperBuilder - public static class Child extends Parent { + public static class Child extends Parent { private static final class ChildBuilderImpl extends ChildBuilder { @Override public Child build() {