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) --- .../eclipse/handlers/HandleSuperBuilder.java | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'src/core/lombok/eclipse/handlers/HandleSuperBuilder.java') diff --git a/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java b/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java index 558c6ec2..02403305 100644 --- a/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java +++ b/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java @@ -51,7 +51,6 @@ import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration; import org.eclipse.jdt.internal.compiler.ast.FieldReference; import org.eclipse.jdt.internal.compiler.ast.IfStatement; import org.eclipse.jdt.internal.compiler.ast.Initializer; -import org.eclipse.jdt.internal.compiler.ast.MarkerAnnotation; import org.eclipse.jdt.internal.compiler.ast.MessageSend; import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration; import org.eclipse.jdt.internal.compiler.ast.NullLiteral; @@ -1100,14 +1099,29 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler { if (td.fields != null) { for (FieldDeclaration field : td.fields) { if (field instanceof Initializer) continue; - char[][] typeName = field.type.getTypeName(); - if (typeName.length >= 1) // Add the first token, because only that can collide. - usedNames.add(String.valueOf(typeName[0])); + addFirstToken(usedNames, field.type); + } + } + + // 4. Add extends and implements clauses. + addFirstToken(usedNames, td.superclass); + if (td.superInterfaces != null) { + for (TypeReference typeReference : td.superInterfaces) { + addFirstToken(usedNames, typeReference); } } return usedNames; } + + private void addFirstToken(java.util.Set usedNames, TypeReference type) { + if (type == null) + return; + // Add the first token, because only that can collide. + char[][] typeName = type.getTypeName(); + if (typeName != null && typeName.length >= 1) + usedNames.add(String.valueOf(typeName[0])); + } private String generateNonclashingNameFor(String classGenericName, java.util.Set typeParamStrings) { if (!typeParamStrings.contains(classGenericName)) return classGenericName; -- cgit