From 074f23621b03e0368bccad5791704b5f04de4d98 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 | 20 +++++++++---------- .../after-ecj/SuperBuilderCustomized.java | 16 +++++++-------- .../before/SuperBuilderCustomized.java | 10 +++++----- 4 files changed, 24 insertions(+), 24 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..649600007b 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) { + 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..ac9fe1ca2f 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,25 +20,25 @@ 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) { + public static SuperBuilderCustomized.Parent.ParentBuilder builder(int field1) { return new SuperBuilderCustomized.Parent.ParentBuilderImpl().field1(field1); } } diff --git a/test/transform/resource/before/SuperBuilderCustomized.java b/test/transform/resource/before/SuperBuilderCustomized.java index 652d086540..97a177015d 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) { + 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() {