From ab36d2f8797ca34f3eefeb2008233985a856f0e4 Mon Sep 17 00:00:00 2001 From: Jan Rieke Date: Fri, 17 Jun 2022 11:13:22 +0200 Subject: (fixes #3202) check extends/implements for collisions (SuperBuilder) --- .../after-delombok/SuperBuilderNameClashes.java | 42 ++++++++++++++++++++++ .../after-ecj/SuperBuilderNameClashes.java | 31 ++++++++++++++++ .../resource/before/SuperBuilderNameClashes.java | 7 ++++ 3 files changed, 80 insertions(+) (limited to 'test/transform') diff --git a/test/transform/resource/after-delombok/SuperBuilderNameClashes.java b/test/transform/resource/after-delombok/SuperBuilderNameClashes.java index 8cef4e11..2a2d0899 100644 --- a/test/transform/resource/after-delombok/SuperBuilderNameClashes.java +++ b/test/transform/resource/after-delombok/SuperBuilderNameClashes.java @@ -124,4 +124,46 @@ public class SuperBuilderNameClashes { return new SuperBuilderNameClashes.C.CBuilderImpl(); } } + interface B2 { + } + public static class ExtendsClauseCollision extends B implements B2 { + @java.lang.SuppressWarnings("all") + public static abstract class ExtendsClauseCollisionBuilder> extends B.BBuilder { + @java.lang.Override + @java.lang.SuppressWarnings("all") + protected abstract B3 self(); + @java.lang.Override + @java.lang.SuppressWarnings("all") + public abstract C build(); + @java.lang.Override + @java.lang.SuppressWarnings("all") + public java.lang.String toString() { + return "SuperBuilderNameClashes.ExtendsClauseCollision.ExtendsClauseCollisionBuilder(super=" + super.toString() + ")"; + } + } + @java.lang.SuppressWarnings("all") + private static final class ExtendsClauseCollisionBuilderImpl extends SuperBuilderNameClashes.ExtendsClauseCollision.ExtendsClauseCollisionBuilder { + @java.lang.SuppressWarnings("all") + private ExtendsClauseCollisionBuilderImpl() { + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + protected SuperBuilderNameClashes.ExtendsClauseCollision.ExtendsClauseCollisionBuilderImpl self() { + return this; + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public SuperBuilderNameClashes.ExtendsClauseCollision build() { + return new SuperBuilderNameClashes.ExtendsClauseCollision(this); + } + } + @java.lang.SuppressWarnings("all") + protected ExtendsClauseCollision(final SuperBuilderNameClashes.ExtendsClauseCollision.ExtendsClauseCollisionBuilder b) { + super(b); + } + @java.lang.SuppressWarnings("all") + public static SuperBuilderNameClashes.ExtendsClauseCollision.ExtendsClauseCollisionBuilder builder() { + return new SuperBuilderNameClashes.ExtendsClauseCollision.ExtendsClauseCollisionBuilderImpl(); + } + } } diff --git a/test/transform/resource/after-ecj/SuperBuilderNameClashes.java b/test/transform/resource/after-ecj/SuperBuilderNameClashes.java index 44d3db92..8ad62aa2 100644 --- a/test/transform/resource/after-ecj/SuperBuilderNameClashes.java +++ b/test/transform/resource/after-ecj/SuperBuilderNameClashes.java @@ -101,6 +101,37 @@ public class SuperBuilderNameClashes { return new SuperBuilderNameClashes.C.CBuilderImpl(); } } + interface B2 { + } + public static @lombok.experimental.SuperBuilder class ExtendsClauseCollision extends B implements B2 { + public static abstract @java.lang.SuppressWarnings("all") class ExtendsClauseCollisionBuilder> extends B.BBuilder { + public ExtendsClauseCollisionBuilder() { + super(); + } + protected abstract @java.lang.Override @java.lang.SuppressWarnings("all") B3 self(); + public abstract @java.lang.Override @java.lang.SuppressWarnings("all") C build(); + public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + return (("SuperBuilderNameClashes.ExtendsClauseCollision.ExtendsClauseCollisionBuilder(super=" + super.toString()) + ")"); + } + } + private static final @java.lang.SuppressWarnings("all") class ExtendsClauseCollisionBuilderImpl extends SuperBuilderNameClashes.ExtendsClauseCollision.ExtendsClauseCollisionBuilder { + private ExtendsClauseCollisionBuilderImpl() { + super(); + } + protected @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderNameClashes.ExtendsClauseCollision.ExtendsClauseCollisionBuilderImpl self() { + return this; + } + public @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderNameClashes.ExtendsClauseCollision build() { + return new SuperBuilderNameClashes.ExtendsClauseCollision(this); + } + } + protected @java.lang.SuppressWarnings("all") ExtendsClauseCollision(final SuperBuilderNameClashes.ExtendsClauseCollision.ExtendsClauseCollisionBuilder b) { + super(b); + } + public static @java.lang.SuppressWarnings("all") SuperBuilderNameClashes.ExtendsClauseCollision.ExtendsClauseCollisionBuilder builder() { + return new SuperBuilderNameClashes.ExtendsClauseCollision.ExtendsClauseCollisionBuilderImpl(); + } + } public SuperBuilderNameClashes() { super(); } diff --git a/test/transform/resource/before/SuperBuilderNameClashes.java b/test/transform/resource/before/SuperBuilderNameClashes.java index a0b58452..a8e719bf 100644 --- a/test/transform/resource/before/SuperBuilderNameClashes.java +++ b/test/transform/resource/before/SuperBuilderNameClashes.java @@ -14,4 +14,11 @@ public class SuperBuilderNameClashes { public static class C { C2 c2; } + + interface B2 { + } + + @lombok.experimental.SuperBuilder + public static class ExtendsClauseCollision extends B implements B2 { + } } -- cgit From 0fcb446265348753c2b448f98f2ad020d6d07d13 Mon Sep 17 00:00:00 2001 From: Jan Rieke Date: Fri, 17 Jun 2022 23:30:25 +0200 Subject: (SuperBuilder) fix javac type params on conflicting names --- src/core/lombok/javac/handlers/HandleSuperBuilder.java | 3 +++ .../resource/after-delombok/SuperBuilderNameClashes.java | 10 +++++++--- test/transform/resource/after-ecj/SuperBuilderNameClashes.java | 10 +++++++--- test/transform/resource/before/SuperBuilderNameClashes.java | 7 ++++++- 4 files changed, 23 insertions(+), 7 deletions(-) (limited to 'test/transform') diff --git a/src/core/lombok/javac/handlers/HandleSuperBuilder.java b/src/core/lombok/javac/handlers/HandleSuperBuilder.java index 967141cd..3b66f076 100644 --- a/src/core/lombok/javac/handlers/HandleSuperBuilder.java +++ b/src/core/lombok/javac/handlers/HandleSuperBuilder.java @@ -1063,6 +1063,9 @@ public class HandleSuperBuilder extends JavacAnnotationHandler { private void addFirstToken(java.util.Set usedNames, JCTree type) { if (type == null) return; + if (type instanceof JCTypeApply) { + type = ((JCTypeApply)type).clazz; + } while (type instanceof JCFieldAccess && ((JCFieldAccess)type).selected != null) { // Add the first token, because only that can collide. type = ((JCFieldAccess)type).selected; diff --git a/test/transform/resource/after-delombok/SuperBuilderNameClashes.java b/test/transform/resource/after-delombok/SuperBuilderNameClashes.java index 2a2d0899..37372e41 100644 --- a/test/transform/resource/after-delombok/SuperBuilderNameClashes.java +++ b/test/transform/resource/after-delombok/SuperBuilderNameClashes.java @@ -125,13 +125,17 @@ public class SuperBuilderNameClashes { } } interface B2 { + interface B4 { + } + } + interface B3 { } - public static class ExtendsClauseCollision extends B implements B2 { + public static class ExtendsClauseCollision extends B implements B2.B4, B3 { @java.lang.SuppressWarnings("all") - public static abstract class ExtendsClauseCollisionBuilder> extends B.BBuilder { + public static abstract class ExtendsClauseCollisionBuilder> extends B.BBuilder { @java.lang.Override @java.lang.SuppressWarnings("all") - protected abstract B3 self(); + protected abstract B4 self(); @java.lang.Override @java.lang.SuppressWarnings("all") public abstract C build(); diff --git a/test/transform/resource/after-ecj/SuperBuilderNameClashes.java b/test/transform/resource/after-ecj/SuperBuilderNameClashes.java index 8ad62aa2..6d1b82e2 100644 --- a/test/transform/resource/after-ecj/SuperBuilderNameClashes.java +++ b/test/transform/resource/after-ecj/SuperBuilderNameClashes.java @@ -102,13 +102,17 @@ public class SuperBuilderNameClashes { } } interface B2 { + interface B4 { + } + } + interface B3 { } - public static @lombok.experimental.SuperBuilder class ExtendsClauseCollision extends B implements B2 { - public static abstract @java.lang.SuppressWarnings("all") class ExtendsClauseCollisionBuilder> extends B.BBuilder { + public static @lombok.experimental.SuperBuilder class ExtendsClauseCollision extends B implements B2.B4, B3 { + public static abstract @java.lang.SuppressWarnings("all") class ExtendsClauseCollisionBuilder> extends B.BBuilder { public ExtendsClauseCollisionBuilder() { super(); } - protected abstract @java.lang.Override @java.lang.SuppressWarnings("all") B3 self(); + protected abstract @java.lang.Override @java.lang.SuppressWarnings("all") B4 self(); public abstract @java.lang.Override @java.lang.SuppressWarnings("all") C build(); public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { return (("SuperBuilderNameClashes.ExtendsClauseCollision.ExtendsClauseCollisionBuilder(super=" + super.toString()) + ")"); diff --git a/test/transform/resource/before/SuperBuilderNameClashes.java b/test/transform/resource/before/SuperBuilderNameClashes.java index a8e719bf..ec3afbb8 100644 --- a/test/transform/resource/before/SuperBuilderNameClashes.java +++ b/test/transform/resource/before/SuperBuilderNameClashes.java @@ -16,9 +16,14 @@ public class SuperBuilderNameClashes { } interface B2 { + interface B4 { + } + } + + interface B3 { } @lombok.experimental.SuperBuilder - public static class ExtendsClauseCollision extends B implements B2 { + public static class ExtendsClauseCollision extends B implements B2.B4, B3 { } } -- cgit