From 2001aa12b54b2fa49ac3156fcdaa36f91e9b023e Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Fri, 23 May 2025 02:49:37 +0200 Subject: [PATCH] [trivial][style] --- src/core/lombok/ConfigurationKeys.java | 6 +- .../eclipse/handlers/EclipseHandlerUtil.java | 4 +- .../lombok/eclipse/handlers/HandleGetter.java | 2 +- .../eclipse/handlers/HandleJacksonized.java | 45 ++++++-------- .../eclipse/handlers/HandleSuperBuilder.java | 46 ++++++--------- .../javac/handlers/HandleJacksonized.java | 59 ++++++++----------- .../javac/handlers/HandleSuperBuilder.java | 57 ++++++++---------- 7 files changed, 89 insertions(+), 130 deletions(-) diff --git a/src/core/lombok/ConfigurationKeys.java b/src/core/lombok/ConfigurationKeys.java index d2381807..5459b1eb 100644 --- a/src/core/lombok/ConfigurationKeys.java +++ b/src/core/lombok/ConfigurationKeys.java @@ -721,7 +721,7 @@ public class ConfigurationKeys { * If set to {@code true}, no further {@code lombok.config} files will be checked. */ public static final ConfigurationKey STOP_BUBBLING = new ConfigurationKey("config.stopBubbling", "Tell the configuration system it should stop looking for other configuration files (default: false).") {}; - + /** * lombok configuration: {@code lombok.copyableAnnotations} += <TypeName: fully-qualified annotation class name>. * @@ -737,14 +737,14 @@ public class ConfigurationKeys { * checkerframework.org version will be generated. */ public static final ConfigurationKey CHECKER_FRAMEWORK = new ConfigurationKey("checkerframework", "If set with the version of checkerframework.org (in major.minor, or just 'true' for the latest supported version), create relevant checkerframework.org annotations for code lombok generates (default: false).") {}; - + /** * lombok configuration: {@code lombok.standardException.flagUsage} = {@code WARNING} | {@code ERROR}. * * If set, any usage of {@code @StandardException} results in a warning / error. */ public static final ConfigurationKey STANDARD_EXCEPTION_FLAG_USAGE = new ConfigurationKey("lombok.standardException.flagUsage", "Emit a warning or error if @StandardException is used.") {}; - + /** * lombok configuration: {@code lombok.copyJacksonAnnotationsToAccessors} = {@code true} | {@code false}. * diff --git a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java index 78e0bf73..c45d95a1 100644 --- a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java +++ b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java @@ -831,7 +831,7 @@ public class EclipseHandlerUtil { } return findAnnotationsInList(node, JACKSON_COPY_TO_GETTER_ANNOTATIONS); } - + /** * Searches the given field node for annotations that are specifically intended to be copied to the setter. * @@ -844,7 +844,7 @@ public class EclipseHandlerUtil { } return findAnnotationsInList(node, JACKSON_COPY_TO_SETTER_ANNOTATIONS); } - + /** * Searches the given field node for annotations that are specifically intended to be copied to the builder's singular method. */ diff --git a/src/core/lombok/eclipse/handlers/HandleGetter.java b/src/core/lombok/eclipse/handlers/HandleGetter.java index ad528929..88d5fe24 100644 --- a/src/core/lombok/eclipse/handlers/HandleGetter.java +++ b/src/core/lombok/eclipse/handlers/HandleGetter.java @@ -83,7 +83,7 @@ import org.eclipse.jdt.internal.compiler.lookup.TypeConstants; public class HandleGetter extends EclipseAnnotationHandler { private static final Annotation[] EMPTY_ANNOTATIONS_ARRAY = new Annotation[0]; private static final String GETTER_NODE_NOT_SUPPORTED_ERR = "@Getter is only supported on a class, an enum, or a field."; - + public boolean generateGetterForType(EclipseNode typeNode, EclipseNode pos, AccessLevel level, boolean checkForTypeLevelGetter, List onMethod) { if (checkForTypeLevelGetter) { if (hasAnnotation(Getter.class, typeNode)) { diff --git a/src/core/lombok/eclipse/handlers/HandleJacksonized.java b/src/core/lombok/eclipse/handlers/HandleJacksonized.java index a8ff2faa..ee0108d7 100644 --- a/src/core/lombok/eclipse/handlers/HandleJacksonized.java +++ b/src/core/lombok/eclipse/handlers/HandleJacksonized.java @@ -65,23 +65,21 @@ public class HandleJacksonized extends EclipseAnnotationHandler { private static final char[][] JSON_POJO_BUILDER_ANNOTATION = Eclipse.fromQualifiedName("com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder"); private static final char[][] JSON_DESERIALIZE_ANNOTATION = Eclipse.fromQualifiedName("com.fasterxml.jackson.databind.annotation.JsonDeserialize"); private static final char[][] JSON_PROPERTY_ANNOTATION = Eclipse.fromQualifiedName("com.fasterxml.jackson.annotation.JsonProperty"); - + @Override public void handle(AnnotationValues annotation, Annotation ast, EclipseNode annotationNode) { handleExperimentalFlagUsage(annotationNode, ConfigurationKeys.JACKSONIZED_FLAG_USAGE, "@Jacksonized"); - + EclipseNode annotatedNode = annotationNode.up(); EclipseNode tdNode; - if (annotatedNode.getKind() != Kind.TYPE) - tdNode = annotatedNode.up(); // @Jacksonized on a constructor or a static factory method. - else - tdNode = annotatedNode; // @Jacksonized on the class. + if (annotatedNode.getKind() != Kind.TYPE) tdNode = annotatedNode.up(); // @Jacksonized on a constructor or a static factory method. + else tdNode = annotatedNode; // @Jacksonized on the class. TypeDeclaration td = (TypeDeclaration) tdNode.get(); EclipseNode builderAnnotationNode = findAnnotation(Builder.class, annotatedNode); EclipseNode superBuilderAnnotationNode = findAnnotation(SuperBuilder.class, annotatedNode); EclipseNode accessorsAnnotationNode = (annotatedNode.getKind() == Kind.TYPE) ? findAnnotation(Accessors.class, annotatedNode) : null; - + if (builderAnnotationNode == null && superBuilderAnnotationNode == null && accessorsAnnotationNode == null) { annotationNode.addWarning("@Jacksonized requires @Builder, @SuperBuilder, or @Accessors for it to mean anything."); return; @@ -96,13 +94,12 @@ public class HandleJacksonized extends EclipseAnnotationHandler { if (jacksonizedBuilder) { handleJacksonizedBuilder(ast, annotationNode, annotatedNode, tdNode, td, builderAnnotationNode, superBuilderAnnotationNode); } - + if (accessorsAnnotationNode != null) { handleJacksonizedAccessors(ast, annotationNode, annotatedNode, tdNode, td, accessorsAnnotationNode, jacksonizedBuilder); } - } - + private void handleJacksonizedBuilder(Annotation ast, EclipseNode annotationNode, EclipseNode annotatedNode, EclipseNode tdNode, TypeDeclaration td, EclipseNode builderAnnotationNode, EclipseNode superBuilderAnnotationNode) { boolean isAbstract = (td.modifiers & ClassFileConstants.AccAbstract) != 0; if (isAbstract) { @@ -163,8 +160,7 @@ public class HandleJacksonized extends EclipseAnnotationHandler { private void handleJacksonizedAccessors(Annotation ast, EclipseNode annotationNode, EclipseNode annotatedNode, EclipseNode tdNode, TypeDeclaration td, EclipseNode accessorsAnnotationNode, boolean jacksonizedBuilder) { AnnotationValues accessorsAnnotation = accessorsAnnotationNode != null ? - createAnnotation(Accessors.class, accessorsAnnotationNode) : - null; + createAnnotation(Accessors.class, accessorsAnnotationNode) : null; boolean fluent = accessorsAnnotation != null && accessorsAnnotation.getInstance().fluent(); if (!fluent) { @@ -183,28 +179,24 @@ public class HandleJacksonized extends EclipseAnnotationHandler { } tdNode.rebuild(); } - + private void createJsonPropertyForField(EclipseNode fieldNode, EclipseNode annotationNode) { - if (hasAnnotation("com.fasterxml.jackson.annotation.JsonProperty", fieldNode)) { - return; - } + if (hasAnnotation("com.fasterxml.jackson.annotation.JsonProperty", fieldNode)) return; ASTNode astNode = fieldNode.get(); if (astNode instanceof FieldDeclaration) { FieldDeclaration fd = (FieldDeclaration)astNode; StringLiteral fieldName = new StringLiteral(fd.name, 0, 0, 0); - ((FieldDeclaration)astNode).annotations = addAnnotation(fieldNode.get(), fd.annotations, JSON_PROPERTY_ANNOTATION, fieldName); + ((FieldDeclaration) astNode).annotations = addAnnotation(fieldNode.get(), fd.annotations, JSON_PROPERTY_ANNOTATION, fieldName); } } - private String getBuilderClassName(Annotation ast, EclipseNode annotationNode, EclipseNode annotatedNode, TypeDeclaration td, AnnotationValues builderAnnotation) { String builderClassName = builderAnnotation != null ? builderAnnotation.getInstance().builderClassName() : null; if (builderClassName == null || builderClassName.isEmpty()) { builderClassName = annotationNode.getAst().readConfiguration(ConfigurationKeys.BUILDER_CLASS_NAME); - if (builderClassName == null || builderClassName.isEmpty()) - builderClassName = "*Builder"; - + if (builderClassName == null || builderClassName.isEmpty()) builderClassName = "*Builder"; + MethodDeclaration fillParametersFrom = annotatedNode.get() instanceof MethodDeclaration ? (MethodDeclaration) annotatedNode.get() : null; char[] replacement; if (fillParametersFrom != null) { @@ -216,23 +208,22 @@ public class HandleJacksonized extends EclipseAnnotationHandler { } builderClassName = builderClassName.replace("*", new String(replacement)); } - - if (builderAnnotation == null) - builderClassName += "Impl"; // For @SuperBuilder, all Jackson annotations must be put on the BuilderImpl class. + + if (builderAnnotation == null) builderClassName += "Impl"; // For @SuperBuilder, all Jackson annotations must be put on the BuilderImpl class. return builderClassName; } private static final Annotation[] EMPTY_ANNOTATIONS_ARRAY = new Annotation[0]; - + private static Annotation[] findJacksonAnnotationsOnClass(TypeDeclaration td, EclipseNode node) { if (td.annotations == null) return EMPTY_ANNOTATIONS_ARRAY; - + List result = new ArrayList(); for (Annotation annotation : td.annotations) { TypeReference typeRef = annotation.type; if (typeRef != null && typeRef.getTypeName() != null) { - for (String bn : HandlerUtil.JACKSON_COPY_TO_BUILDER_ANNOTATIONS) { + for (String bn : HandlerUtil.JACKSON_COPY_TO_BUILDER_ANNOTATIONS) { if (typeMatches(bn, node, typeRef)) { result.add(annotation); break; diff --git a/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java b/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java index 4712af65..d2741a13 100644 --- a/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java +++ b/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java @@ -162,13 +162,9 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler { job.init(annotation, annInstance, annotationNode); boolean generateBuilderMethod; - if (job.builderMethodName.isEmpty()) { - generateBuilderMethod = false; - } else if (!checkName("builderMethodName", job.builderMethodName, annotationNode)) { - return; - } else { - generateBuilderMethod = true; - } + if (job.builderMethodName.isEmpty()) generateBuilderMethod = false; + else if (!checkName("builderMethodName", job.builderMethodName, annotationNode)) return; + else generateBuilderMethod = true; if (!checkName("buildMethodName", job.buildMethodName, annotationNode)) return; @@ -343,9 +339,7 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler { if (sd == null) continue; EclipseSingularizer singularizer = sd.getSingularizer(); if (singularizer == null) continue; - if (singularizer.checkForAlreadyExistingNodesAndGenerateError(job.builderAbstractType, sd)) { - bfd.singularData = null; - } + if (singularizer.checkForAlreadyExistingNodesAndGenerateError(job.builderAbstractType, sd)) bfd.singularData = null; } } @@ -407,9 +401,7 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler { } // Let toString() call super.toString() if there is a superclass, so that it also shows fields from the superclass' builder. MethodDeclaration md = HandleToString.createToString(job.builderType, fieldNodes, true, superclassBuilderClass != null, ast, FieldAccess.ALWAYS_FIELD); - if (md != null) { - injectMethod(job.builderType, md); - } + if (md != null) injectMethod(job.builderType, md); } if (addCleaning) { @@ -593,7 +585,7 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler { char[][] setVariableInBuilder = new char[][] {BUILDER_VARIABLE_NAME, fieldNode.nameOfSetFlag}; long[] positions = new long[] {p, p}; QualifiedNameReference setVariableInBuilderRef = new QualifiedNameReference(setVariableInBuilder, positions, s, e); - + MessageSend defaultMethodCall = new MessageSend(); defaultMethodCall.sourceStart = job.source.sourceStart; defaultMethodCall.sourceEnd = job.source.sourceEnd; @@ -696,7 +688,7 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler { out.traverse(new SetGeneratedByVisitor(job.source), ((TypeDeclaration) job.parentType.get()).scope); return out; } - + /** * Generates a {@code $fillValuesFrom()} method in the abstract builder class. * It looks like: @@ -718,9 +710,9 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler { TypeReference builderType = new SingleTypeReference(classGenericName.toCharArray(), 0); out.arguments = new Argument[] {new Argument(INSTANCE_VARIABLE_NAME, 0, builderType, Modifier.FINAL)}; - + List body = new ArrayList(); - + if (inherited) { // Call super. MessageSend callToSuper = new MessageSend(); @@ -729,14 +721,14 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler { callToSuper.arguments = new Expression[] {new SingleNameReference(INSTANCE_VARIABLE_NAME, 0)}; body.add(callToSuper); } - + // Call the builder implemention's helper method that actually fills the values from the instance. MessageSend callStaticFillValuesMethod = new MessageSend(); callStaticFillValuesMethod.receiver = generateNameReference(job.parentType, job.builderAbstractClassNameArr, 0); callStaticFillValuesMethod.selector = FILL_VALUES_STATIC_METHOD_NAME; callStaticFillValuesMethod.arguments = new Expression[] {new SingleNameReference(INSTANCE_VARIABLE_NAME, 0), new ThisReference(0, 0)}; body.add(callStaticFillValuesMethod); - + // Return self(). MessageSend returnCall = new MessageSend(); returnCall.receiver = ThisReference.implicitThis(); @@ -747,7 +739,7 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler { return out; } - + /** * Generates a {@code $fillValuesFromInstanceIntoBuilder()} method in * the builder implementation class that copies all fields from the instance @@ -1095,8 +1087,7 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler { java.util.HashSet usedNames = new HashSet(); // 1. Add type parameter names. - for (TypeParameter typeParam : typeParams) - usedNames.add(typeParam.toString()); + for (TypeParameter typeParam : typeParams) usedNames.add(typeParam.toString()); // 2. Add class name. usedNames.add(String.valueOf(td.name)); @@ -1119,14 +1110,12 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler { return usedNames; } - + private void addFirstToken(java.util.Set usedNames, TypeReference type) { - if (type == null) - return; + 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])); + if (typeName != null && typeName.length >= 1) usedNames.add(String.valueOf(typeName[0])); } private String generateNonclashingNameFor(String classGenericName, java.util.Set typeParamStrings) { @@ -1227,8 +1216,7 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler { // Cannot use typeMatches() here, because the parameter could be fully-qualified, partially-qualified, or not qualified. // A string-compare of the last part should work. If it's a false-positive, users could still @Tolerate it. char[] typeName = def.arguments[0].type.getLastToken(); - if (builderClassName.equals(String.valueOf(typeName))) - return true; + if (builderClassName.equals(String.valueOf(typeName))) return true; } } } diff --git a/src/core/lombok/javac/handlers/HandleJacksonized.java b/src/core/lombok/javac/handlers/HandleJacksonized.java index c0cff164..d0988ad7 100644 --- a/src/core/lombok/javac/handlers/HandleJacksonized.java +++ b/src/core/lombok/javac/handlers/HandleJacksonized.java @@ -62,17 +62,15 @@ public class HandleJacksonized extends JavacAnnotationHandler { @Override public void handle(AnnotationValues annotation, JCAnnotation ast, JavacNode annotationNode) { handleExperimentalFlagUsage(annotationNode, ConfigurationKeys.JACKSONIZED_FLAG_USAGE, "@Jacksonized"); - + JavacNode annotatedNode = annotationNode.up(); deleteAnnotationIfNeccessary(annotationNode, Jacksonized.class); JavacNode tdNode; - if (annotatedNode.getKind() != Kind.TYPE) - tdNode = annotatedNode.up(); // @Jacksonized on a constructor or a static factory method. - else - tdNode = annotatedNode; // @Jacksonized on the class. + if (annotatedNode.getKind() != Kind.TYPE) tdNode = annotatedNode.up(); // @Jacksonized on a constructor or a static factory method. + else tdNode = annotatedNode; // @Jacksonized on the class. JCClassDecl td = (JCClassDecl) tdNode.get(); - + JavacNode builderAnnotationNode = findAnnotation(Builder.class, annotatedNode); JavacNode superBuilderAnnotationNode = findAnnotation(SuperBuilder.class, annotatedNode); JavacNode accessorsAnnotationNode = findAnnotation(Accessors.class, annotatedNode); @@ -88,12 +86,11 @@ public class HandleJacksonized extends JavacAnnotationHandler { if (accessorsAnnotationNode != null) { handleJacksonizedAccessors(annotationNode, annotatedNode, tdNode, td, accessorsAnnotationNode, builderAnnotationNode != null || superBuilderAnnotationNode != null); } - } - + } + private void handleJacksonizedAccessors(JavacNode annotationNode, JavacNode annotatedNode, JavacNode tdNode, JCClassDecl td, JavacNode accessorsAnnotationNode, boolean jacksonizedBuilder) { AnnotationValues accessorsAnnotation = accessorsAnnotationNode != null ? - createAnnotation(Accessors.class, accessorsAnnotationNode) : - null; + createAnnotation(Accessors.class, accessorsAnnotationNode) : null; boolean fluent = accessorsAnnotation != null && accessorsAnnotation.getInstance().fluent(); if (!fluent) { @@ -110,7 +107,7 @@ public class HandleJacksonized extends JavacAnnotationHandler { } } } - + private void createJsonPropertyForField(JavacNode fieldNode, JavacNode annotationNode) { if (hasAnnotation("com.fasterxml.jackson.annotation.JsonProperty", fieldNode)) { return; @@ -123,13 +120,13 @@ public class HandleJacksonized extends JavacAnnotationHandler { JCVariableDecl fieldDecl = ((JCVariableDecl)fieldNode.get()); fieldDecl.mods.annotations = fieldDecl.mods.annotations.append(annotationJsonProperty); } - + private void handleJacksonizedBuilder(JavacNode annotationNode, JavacNode annotatedNode, JavacNode tdNode, JCClassDecl td, JavacNode builderAnnotationNode, JavacNode superBuilderAnnotationNode) { if (builderAnnotationNode != null && superBuilderAnnotationNode != null) { annotationNode.addError("@Jacksonized cannot process both @Builder and @SuperBuilder on the same class."); return; } - + boolean isAbstract = (td.mods.flags & Flags.ABSTRACT) != 0; if (isAbstract) { annotationNode.addError("Builders on abstract classes cannot be @Jacksonized (the builder would never be used)."); @@ -137,24 +134,22 @@ public class HandleJacksonized extends JavacAnnotationHandler { } AnnotationValues builderAnnotation = builderAnnotationNode != null ? - createAnnotation(Builder.class, builderAnnotationNode) : - null; + createAnnotation(Builder.class, builderAnnotationNode) : null; AnnotationValues superBuilderAnnotation = superBuilderAnnotationNode != null ? - createAnnotation(SuperBuilder.class, superBuilderAnnotationNode) : - null; + createAnnotation(SuperBuilder.class, superBuilderAnnotationNode) : null; String setPrefix = builderAnnotation != null ? builderAnnotation.getInstance().setterPrefix() : - superBuilderAnnotation.getInstance().setterPrefix(); + superBuilderAnnotation.getInstance().setterPrefix(); String buildMethodName = builderAnnotation != null ? builderAnnotation.getInstance().buildMethodName() : - superBuilderAnnotation.getInstance().buildMethodName(); + superBuilderAnnotation.getInstance().buildMethodName(); JavacTreeMaker maker = annotatedNode.getTreeMaker(); - + // Now lets find the generated builder class. String builderClassName = getBuilderClassName(annotationNode, annotatedNode, td, builderAnnotation, maker); - + JCClassDecl builderClass = null; for (JCTree member : td.getMembers()) { if (member instanceof JCClassDecl && ((JCClassDecl) member).getSimpleName().contentEquals(builderClassName)) { @@ -196,20 +191,17 @@ public class HandleJacksonized extends JavacAnnotationHandler { JCAnnotation annotationJsonPOJOBuilder = maker.Annotation(jsonPOJOBuilderType, List.of(withPrefixExpr, buildMethodNameExpr)); recursiveSetGeneratedBy(annotationJsonPOJOBuilder, annotatedNode); builderClass.mods.annotations = builderClass.mods.annotations.append(annotationJsonPOJOBuilder); - + // @SuperBuilder? Make it package-private! - if (superBuilderAnnotationNode != null) - builderClass.mods.flags = builderClass.mods.flags & ~Flags.PRIVATE; + if (superBuilderAnnotationNode != null) builderClass.mods.flags = builderClass.mods.flags & ~Flags.PRIVATE; } - + private String getBuilderClassName(JavacNode annotationNode, JavacNode annotatedNode, JCClassDecl td, AnnotationValues builderAnnotation, JavacTreeMaker maker) { - String builderClassName = builderAnnotation != null ? - builderAnnotation.getInstance().builderClassName() : null; + String builderClassName = builderAnnotation != null ? builderAnnotation.getInstance().builderClassName() : null; if (builderClassName == null || builderClassName.isEmpty()) { builderClassName = annotationNode.getAst().readConfiguration(ConfigurationKeys.BUILDER_CLASS_NAME); - if (builderClassName == null || builderClassName.isEmpty()) - builderClassName = "*Builder"; - + if (builderClassName == null || builderClassName.isEmpty()) builderClassName = "*Builder"; + JCMethodDecl fillParametersFrom = annotatedNode.get() instanceof JCMethodDecl ? (JCMethodDecl)annotatedNode.get() : null; String replacement; if (fillParametersFrom != null && !fillParametersFrom.getName().toString().equals("")) { @@ -226,9 +218,8 @@ public class HandleJacksonized extends JavacAnnotationHandler { } builderClassName = builderClassName.replace("*", replacement); } - - if (builderAnnotation == null) - builderClassName += "Impl"; // For @SuperBuilder, all Jackson annotations must be put on the BuilderImpl class. + + if (builderAnnotation == null) builderClassName += "Impl"; // For @SuperBuilder, all Jackson annotations must be put on the BuilderImpl class. return builderClassName; } @@ -238,7 +229,7 @@ public class HandleJacksonized extends JavacAnnotationHandler { for (JavacNode child : node.down()) { if (child.getKind() == Kind.ANNOTATION) { JCAnnotation annotation = (JCAnnotation) child.get(); - for (String bn : HandlerUtil.JACKSON_COPY_TO_BUILDER_ANNOTATIONS) { + for (String bn : HandlerUtil.JACKSON_COPY_TO_BUILDER_ANNOTATIONS) { if (typeMatches(bn, node, annotation.annotationType)) { result.append(annotation); break; diff --git a/src/core/lombok/javac/handlers/HandleSuperBuilder.java b/src/core/lombok/javac/handlers/HandleSuperBuilder.java index ffcbe21f..08a16b92 100644 --- a/src/core/lombok/javac/handlers/HandleSuperBuilder.java +++ b/src/core/lombok/javac/handlers/HandleSuperBuilder.java @@ -143,13 +143,10 @@ public class HandleSuperBuilder extends JavacAnnotationHandler { job.init(annotation, annInstance, annotationNode); boolean generateBuilderMethod; - if (job.builderMethodName.isEmpty()) { - generateBuilderMethod = false; - } else if (!checkName("builderMethodName", job.builderMethodName, annotationNode)) { - return; - } else { - generateBuilderMethod = true; - } + if (job.builderMethodName.isEmpty()) generateBuilderMethod = false; + else if (!checkName("builderMethodName", job.builderMethodName, annotationNode)) return; + else generateBuilderMethod = true; + if (!checkName("buildMethodName", job.buildMethodName, annotationNode)) return; // Do not delete the SuperBuilder annotation here, we need it for @Jacksonized. @@ -313,9 +310,7 @@ public class HandleSuperBuilder extends JavacAnnotationHandler { if (sd == null) continue; JavacSingularizer singularizer = sd.getSingularizer(); if (singularizer == null) continue; - if (singularizer.checkForAlreadyExistingNodesAndGenerateError(job.builderAbstractType, sd)) { - bfd.singularData = null; - } + if (singularizer.checkForAlreadyExistingNodesAndGenerateError(job.builderAbstractType, sd)) bfd.singularData = null; } } @@ -389,7 +384,7 @@ public class HandleSuperBuilder extends JavacAnnotationHandler { } sanityCheckForMethodGeneratingAnnotationsOnBuilderClass(job.builderImplType, annotationNode); } - + // Create a simple constructor for the BuilderImpl class. JCMethodDecl cd = HandleConstructor.createConstructor(AccessLevel.PRIVATE, List.nil(), job.builderImplType, List.nil(), false, annotationNode); if (cd != null) injectMethod(job.builderImplType, cd); @@ -515,7 +510,7 @@ public class HandleSuperBuilder extends JavacAnnotationHandler { recursiveSetGeneratedBy(builder, job.sourceNode); return injectType(job.parentType, builder); } - + /** * Generates a constructor that has a builder as the only parameter. * The values from the builder are used to initialize the fields of new instances. @@ -582,8 +577,8 @@ public class HandleSuperBuilder extends JavacAnnotationHandler { if (callBuilderBasedSuperConstructor) { // The first statement must be the call to the super constructor. JCMethodInvocation callToSuperConstructor = maker.Apply(List.nil(), - maker.Ident(job.toName("super")), - List.of(maker.Ident(builderVariableName))); + maker.Ident(job.toName("super")), + List.of(maker.Ident(builderVariableName))); statements.prepend(maker.Exec(callToSuperConstructor)); } @@ -659,7 +654,7 @@ public class HandleSuperBuilder extends JavacAnnotationHandler { createRelevantNonNullAnnotation(job.parentType, methodDef); return methodDef; } - + /** * Generates a {@code $fillValuesFrom()} method in the abstract builder class. * @@ -685,7 +680,7 @@ public class HandleSuperBuilder extends JavacAnnotationHandler { JCExpression classGenericNameExpr = maker.Ident(job.toName(classGenericName)); JCVariableDecl param = maker.VarDef(maker.Modifiers(Flags.PARAMETER | Flags.FINAL), job.toName(INSTANCE_VARIABLE_NAME), classGenericNameExpr, null); - + ListBuffer body = new ListBuffer(); if (inherited) { @@ -709,7 +704,7 @@ public class HandleSuperBuilder extends JavacAnnotationHandler { return maker.MethodDef(modifiers, name, returnType, List.nil(), List.of(param), List.nil(), bodyBlock, null); } - + /** * Generates a {@code $fillValuesFromInstanceIntoBuilder()} method in * the builder implementation class that copies all fields from the instance @@ -731,7 +726,7 @@ public class HandleSuperBuilder extends JavacAnnotationHandler { // 1st parameter: "Foobar instance" JCVariableDecl paramInstance = maker.VarDef(maker.Modifiers(Flags.PARAMETER | Flags.FINAL), job.toName(INSTANCE_VARIABLE_NAME), cloneSelfType(job.parentType), null); - + // 2nd parameter: "FoobarBuilder b" (plus generics on the annotated type) // First add all generics that are present on the parent type. ListBuffer typeParamsForBuilderParameter = getTypeParamExpressions(job.typeParams, maker, job.sourceNode); @@ -804,7 +799,7 @@ public class HandleSuperBuilder extends JavacAnnotationHandler { Name name = job.toName(SELF_METHOD); JCExpression returnType = maker.Ident(job.toName(builderGenericName)); returnType = addCheckerFrameworkReturnsReceiver(returnType, maker, job.builderType, job.checkerFramework); - + return maker.MethodDef(modifiers, name, returnType, List.nil(), List.nil(), List.nil(), null, null); } @@ -1050,8 +1045,7 @@ public class HandleSuperBuilder extends JavacAnnotationHandler { java.util.HashSet usedNames = new HashSet(); // 1. Add type parameter names. - for (JCTypeParameter typeParam : typeParams) - usedNames.add(typeParam.getName().toString()); + for (JCTypeParameter typeParam : typeParams) usedNames.add(typeParam.getName().toString()); // 2. Add class name. usedNames.add(td.name.toString()); @@ -1060,16 +1054,13 @@ public class HandleSuperBuilder extends JavacAnnotationHandler { for (JCTree member : td.getMembers()) { if (member.getKind() == com.sun.source.tree.Tree.Kind.VARIABLE && member instanceof JCVariableDecl) { JCTree type = ((JCVariableDecl)member).getType(); - if (type instanceof JCIdent) - usedNames.add(((JCIdent)type).getName().toString()); + if (type instanceof JCIdent) usedNames.add(((JCIdent)type).getName().toString()); } } // 4. Add extends and implements clauses. addFirstToken(usedNames, Javac.getExtendsClause(td)); - for (JCExpression impl : td.getImplementsClause()) { - addFirstToken(usedNames, impl); - } + for (JCExpression impl : td.getImplementsClause()) addFirstToken(usedNames, impl); return usedNames; } @@ -1082,7 +1073,7 @@ public class HandleSuperBuilder extends JavacAnnotationHandler { } while (type instanceof JCFieldAccess && ((JCFieldAccess)type).selected != null) { // Add the first token, because only that can collide. - type = ((JCFieldAccess)type).selected; + type = ((JCFieldAccess) type).selected; } usedNames.add(type.toString()); } @@ -1122,7 +1113,7 @@ public class HandleSuperBuilder extends JavacAnnotationHandler { } return typeParamsForBuilderParameter; } - + private JCExpression copySelect(JavacTreeMaker maker, JCFieldAccess typeParam) { java.util.List chainNames = new ArrayList(); JCExpression expression = typeParam; @@ -1135,7 +1126,7 @@ public class HandleSuperBuilder extends JavacAnnotationHandler { expression = null; } } - + Collections.reverse(chainNames); JCExpression typeParameter = null; for (Name name : chainNames) { @@ -1158,18 +1149,16 @@ public class HandleSuperBuilder extends JavacAnnotationHandler { JCMethodDecl md = (JCMethodDecl) def; String name = md.name.toString(); boolean matches = name.equals(""); - if (isTolerate(type, md)) - continue; + if (isTolerate(type, md)) continue; if (matches && md.params != null && md.params.length() == 1) { // Cannot use typeMatches() here, because the parameter could be fully-qualified, partially-qualified, or not qualified. // A string-compare of the last part should work. If it's a false-positive, users could still @Tolerate it. String typeName = md.params.get(0).getType().toString(); int lastIndexOfDot = typeName.lastIndexOf('.'); if (lastIndexOfDot >= 0) { - typeName = typeName.substring(lastIndexOfDot+1); + typeName = typeName.substring(lastIndexOfDot + 1); } - if ((builderClassName+"").equals(typeName)) - return true; + if ((builderClassName+"").equals(typeName)) return true; } } }