From 714be613cb29bb682d99d75abb97efc944042c50 Mon Sep 17 00:00:00 2001 From: Jan Rieke Date: Wed, 30 Dec 2020 14:15:08 +0100 Subject: [fixes #2647] consider lombok.builder.className for builder extends --- src/core/lombok/eclipse/handlers/HandleBuilder.java | 8 ++++++-- src/core/lombok/eclipse/handlers/HandleSuperBuilder.java | 12 +++++++----- src/core/lombok/javac/handlers/HandleBuilder.java | 8 ++++++-- src/core/lombok/javac/handlers/HandleSuperBuilder.java | 6 ++++-- 4 files changed, 23 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/core/lombok/eclipse/handlers/HandleBuilder.java b/src/core/lombok/eclipse/handlers/HandleBuilder.java index 189c5a69..59862f2c 100755 --- a/src/core/lombok/eclipse/handlers/HandleBuilder.java +++ b/src/core/lombok/eclipse/handlers/HandleBuilder.java @@ -202,8 +202,12 @@ public class HandleBuilder extends EclipseAnnotationHandler { } String replaceBuilderClassName(char[] name) { - if (builderClassName.indexOf('*') == -1) return builderClassName; - return builderClassName.replace("*", new String(name)); + return replaceBuilderClassName(name, builderClassName); + } + + String replaceBuilderClassName(char[] name, String template) { + if (template.indexOf('*') == -1) return template; + return template.replace("*", new String(name)); } String replaceBuilderClassName(String name) { diff --git a/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java b/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java index 8fdfd315..e489c258 100644 --- a/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java +++ b/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java @@ -272,8 +272,9 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler { }; if (extendsClause instanceof QualifiedTypeReference) { QualifiedTypeReference qualifiedTypeReference = (QualifiedTypeReference)extendsClause; - String superclassClassName = String.valueOf(qualifiedTypeReference.getLastToken()); - String superclassBuilderClassName = job.replaceBuilderClassName(superclassClassName); + char[] superclassClassName = qualifiedTypeReference.getLastToken(); + String builderClassNameTemplate = BuilderJob.fixBuilderClassName(annotationNode, ""); + String superclassBuilderClassName = job.replaceBuilderClassName(superclassClassName, builderClassNameTemplate); char[][] tokens = Arrays.copyOf(qualifiedTypeReference.tokens, qualifiedTypeReference.tokens.length + 1); tokens[tokens.length-1] = superclassBuilderClassName.toCharArray(); @@ -289,10 +290,11 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler { superclassBuilderClass = new ParameterizedQualifiedTypeReference(tokens, typeArgsForTokens, 0, poss); } else if (extendsClause != null) { - String superClass = String.valueOf(extendsClause.getTypeName()[0]); - String superclassBuilderClassName = superClass + "Builder"; + char[] superclassClassName = extendsClause.getTypeName()[0]; + String builderClassNameTemplate = BuilderJob.fixBuilderClassName(annotationNode, ""); + String superclassBuilderClassName = job.replaceBuilderClassName(superclassClassName, builderClassNameTemplate); - char[][] tokens = new char[][] {superClass.toCharArray(), superclassBuilderClassName.toCharArray()}; + char[][] tokens = new char[][] {superclassClassName, superclassBuilderClassName.toCharArray()}; long[] poss = new long[tokens.length]; Arrays.fill(poss, job.getPos()); diff --git a/src/core/lombok/javac/handlers/HandleBuilder.java b/src/core/lombok/javac/handlers/HandleBuilder.java index 867d6889..4ace3b68 100644 --- a/src/core/lombok/javac/handlers/HandleBuilder.java +++ b/src/core/lombok/javac/handlers/HandleBuilder.java @@ -148,8 +148,12 @@ public class HandleBuilder extends JavacAnnotationHandler { } String replaceBuilderClassName(Name name) { - if (builderClassName.indexOf('*') == -1) return builderClassName; - return builderClassName.replace("*", name.toString()); + return replaceBuilderClassName(name.toString(), builderClassName); + } + + String replaceBuilderClassName(String name, String template) { + if (template.indexOf('*') == -1) return template; + return template.replace("*", name); } JCExpression createBuilderParentTypeReference() { diff --git a/src/core/lombok/javac/handlers/HandleSuperBuilder.java b/src/core/lombok/javac/handlers/HandleSuperBuilder.java index 99f0ea6a..567e7816 100644 --- a/src/core/lombok/javac/handlers/HandleSuperBuilder.java +++ b/src/core/lombok/javac/handlers/HandleSuperBuilder.java @@ -257,10 +257,12 @@ public class HandleSuperBuilder extends JavacAnnotationHandler { } if (extendsClause instanceof JCFieldAccess) { Name superclassName = ((JCFieldAccess) extendsClause).getIdentifier(); - String superclassBuilderClassName = superclassName.toString() + "Builder"; + String builderClassNameTemplate = BuilderJob.fixBuilderClassName(annotationNode, ""); + String superclassBuilderClassName = job.replaceBuilderClassName(superclassName.toString(), builderClassNameTemplate); superclassBuilderClass = parent.getTreeMaker().Select((JCFieldAccess) extendsClause, parent.toName(superclassBuilderClassName)); } else if (extendsClause != null) { - String superclassBuilderClassName = extendsClause.toString() + "Builder"; + String builderClassNameTemplate = BuilderJob.fixBuilderClassName(annotationNode, ""); + String superclassBuilderClassName = job.replaceBuilderClassName(extendsClause.toString(), builderClassNameTemplate); superclassBuilderClass = chainDots(parent, extendsClause.toString(), superclassBuilderClassName); } -- cgit From 4ba962aae0de64c4063cb5313ed15fe25928e9ca Mon Sep 17 00:00:00 2001 From: Jan Rieke Date: Fri, 12 Mar 2021 10:34:48 +0100 Subject: rename method; use null instead of empty string --- src/core/lombok/eclipse/handlers/HandleSuperBuilder.java | 2 +- src/core/lombok/javac/handlers/HandleBuilder.java | 4 ++-- src/core/lombok/javac/handlers/HandleSuperBuilder.java | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java b/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java index e489c258..41ad77ab 100644 --- a/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java +++ b/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java @@ -273,7 +273,7 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler { if (extendsClause instanceof QualifiedTypeReference) { QualifiedTypeReference qualifiedTypeReference = (QualifiedTypeReference)extendsClause; char[] superclassClassName = qualifiedTypeReference.getLastToken(); - String builderClassNameTemplate = BuilderJob.fixBuilderClassName(annotationNode, ""); + String builderClassNameTemplate = BuilderJob.fixBuilderClassName(annotationNode, null); String superclassBuilderClassName = job.replaceBuilderClassName(superclassClassName, builderClassNameTemplate); char[][] tokens = Arrays.copyOf(qualifiedTypeReference.tokens, qualifiedTypeReference.tokens.length + 1); diff --git a/src/core/lombok/javac/handlers/HandleBuilder.java b/src/core/lombok/javac/handlers/HandleBuilder.java index 4ace3b68..c10e6071 100644 --- a/src/core/lombok/javac/handlers/HandleBuilder.java +++ b/src/core/lombok/javac/handlers/HandleBuilder.java @@ -132,7 +132,7 @@ public class HandleBuilder extends JavacAnnotationHandler { builderMethodName = ann.builderMethodName(); buildMethodName = ann.buildMethodName(); - builderClassName = fixBuilderClassName(node, ann.builderClassName()); + builderClassName = getBuilderClassNameTemplate(node, ann.builderClassName()); toBuilder = ann.toBuilder(); if (builderMethodName == null) builderMethodName = "builder"; @@ -140,7 +140,7 @@ public class HandleBuilder extends JavacAnnotationHandler { if (builderClassName == null) builderClassName = ""; } - static String fixBuilderClassName(JavacNode node, String override) { + static String getBuilderClassNameTemplate(JavacNode node, String override) { if (override != null && !override.isEmpty()) return override; override = node.getAst().readConfiguration(ConfigurationKeys.BUILDER_CLASS_NAME); if (override != null && !override.isEmpty()) return override; diff --git a/src/core/lombok/javac/handlers/HandleSuperBuilder.java b/src/core/lombok/javac/handlers/HandleSuperBuilder.java index 567e7816..b66df8cd 100644 --- a/src/core/lombok/javac/handlers/HandleSuperBuilder.java +++ b/src/core/lombok/javac/handlers/HandleSuperBuilder.java @@ -113,7 +113,7 @@ public class HandleSuperBuilder extends JavacAnnotationHandler { if (builderMethodName == null) builderMethodName = "builder"; if (buildMethodName == null) buildMethodName = "build"; - builderClassName = fixBuilderClassName(node, ""); + builderClassName = getBuilderClassNameTemplate(node, null); } void setBuilderToImpl() { @@ -257,11 +257,11 @@ public class HandleSuperBuilder extends JavacAnnotationHandler { } if (extendsClause instanceof JCFieldAccess) { Name superclassName = ((JCFieldAccess) extendsClause).getIdentifier(); - String builderClassNameTemplate = BuilderJob.fixBuilderClassName(annotationNode, ""); + String builderClassNameTemplate = BuilderJob.getBuilderClassNameTemplate(annotationNode, null); String superclassBuilderClassName = job.replaceBuilderClassName(superclassName.toString(), builderClassNameTemplate); superclassBuilderClass = parent.getTreeMaker().Select((JCFieldAccess) extendsClause, parent.toName(superclassBuilderClassName)); } else if (extendsClause != null) { - String builderClassNameTemplate = BuilderJob.fixBuilderClassName(annotationNode, ""); + String builderClassNameTemplate = BuilderJob.getBuilderClassNameTemplate(annotationNode, null); String superclassBuilderClassName = job.replaceBuilderClassName(extendsClause.toString(), builderClassNameTemplate); superclassBuilderClass = chainDots(parent, extendsClause.toString(), superclassBuilderClassName); } -- cgit From a6257f27f0831ed2c9971285a3bb29f73fabbb02 Mon Sep 17 00:00:00 2001 From: Jan Rieke Date: Fri, 12 Mar 2021 20:40:17 +0100 Subject: rename method; use null instead of empty string [eclipse] --- src/core/lombok/eclipse/handlers/HandleBuilder.java | 4 ++-- src/core/lombok/eclipse/handlers/HandleSuperBuilder.java | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/core/lombok/eclipse/handlers/HandleBuilder.java b/src/core/lombok/eclipse/handlers/HandleBuilder.java index 59862f2c..dfb8eab0 100755 --- a/src/core/lombok/eclipse/handlers/HandleBuilder.java +++ b/src/core/lombok/eclipse/handlers/HandleBuilder.java @@ -183,14 +183,14 @@ public class HandleBuilder extends EclipseAnnotationHandler { builderMethodName = ann.builderMethodName(); buildMethodName = ann.buildMethodName(); - setBuilderClassName(fixBuilderClassName(node, ann.builderClassName())); + setBuilderClassName(getBuilderClassNameTemplate(node, ann.builderClassName())); toBuilder = ann.toBuilder(); if (builderMethodName == null) builderMethodName = "builder"; if (buildMethodName == null) buildMethodName = "build"; } - static String fixBuilderClassName(EclipseNode node, String override) { + static String getBuilderClassNameTemplate(EclipseNode node, String override) { if (override != null && !override.isEmpty()) return override; override = node.getAst().readConfiguration(ConfigurationKeys.BUILDER_CLASS_NAME); if (override != null && !override.isEmpty()) return override; diff --git a/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java b/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java index 41ad77ab..ad7d3fd6 100644 --- a/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java +++ b/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java @@ -123,7 +123,7 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler { if (builderMethodName == null) builderMethodName = "builder"; if (buildMethodName == null) buildMethodName = "build"; - builderClassName = fixBuilderClassName(node, ""); + builderClassName = getBuilderClassNameTemplate(node, null); } EclipseNode builderAbstractType; @@ -273,7 +273,7 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler { if (extendsClause instanceof QualifiedTypeReference) { QualifiedTypeReference qualifiedTypeReference = (QualifiedTypeReference)extendsClause; char[] superclassClassName = qualifiedTypeReference.getLastToken(); - String builderClassNameTemplate = BuilderJob.fixBuilderClassName(annotationNode, null); + String builderClassNameTemplate = BuilderJob.getBuilderClassNameTemplate(annotationNode, null); String superclassBuilderClassName = job.replaceBuilderClassName(superclassClassName, builderClassNameTemplate); char[][] tokens = Arrays.copyOf(qualifiedTypeReference.tokens, qualifiedTypeReference.tokens.length + 1); @@ -291,7 +291,7 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler { superclassBuilderClass = new ParameterizedQualifiedTypeReference(tokens, typeArgsForTokens, 0, poss); } else if (extendsClause != null) { char[] superclassClassName = extendsClause.getTypeName()[0]; - String builderClassNameTemplate = BuilderJob.fixBuilderClassName(annotationNode, ""); + String builderClassNameTemplate = BuilderJob.getBuilderClassNameTemplate(annotationNode, null); String superclassBuilderClassName = job.replaceBuilderClassName(superclassClassName, builderClassNameTemplate); char[][] tokens = new char[][] {superclassClassName, superclassBuilderClassName.toCharArray()}; -- cgit