[trivial][style]

This commit is contained in:
Reinier Zwitserloot committed 2025-05-23 02:50:25 +02:00
1 parent aa13671e40
commit 2001aa12b5
7 files changed
+89 -130

No files matched your search

+3 -3
View File
@@ -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<Boolean> STOP_BUBBLING = new ConfigurationKey<Boolean>("config.stopBubbling", "Tell the configuration system it should stop looking for other configuration files (default: false).") {};
/**
* lombok configuration: {@code lombok.copyableAnnotations} += &lt;TypeName: fully-qualified annotation class name&gt;.
*
@@ -737,14 +737,14 @@ public class ConfigurationKeys {
* checkerframework.org version will be generated.
*/
public static final ConfigurationKey<CheckerFrameworkVersion> CHECKER_FRAMEWORK = new ConfigurationKey<CheckerFrameworkVersion>("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, <em>any</em> usage of {@code @StandardException} results in a warning / error.
*/
public static final ConfigurationKey<FlagUsageType> STANDARD_EXCEPTION_FLAG_USAGE = new ConfigurationKey<FlagUsageType>("lombok.standardException.flagUsage", "Emit a warning or error if @StandardException is used.") {};
/**
* lombok configuration: {@code lombok.copyJacksonAnnotationsToAccessors} = {@code true} | {@code false}.
*
@@ -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.
*/
@@ -83,7 +83,7 @@ import org.eclipse.jdt.internal.compiler.lookup.TypeConstants;
public class HandleGetter extends EclipseAnnotationHandler<Getter> {
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<Annotation> onMethod) {
if (checkForTypeLevelGetter) {
if (hasAnnotation(Getter.class, typeNode)) {
@@ -65,23 +65,21 @@ public class HandleJacksonized extends EclipseAnnotationHandler<Jacksonized> {
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<Jacksonized> 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<Jacksonized> {
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<Jacksonized> {
private void handleJacksonizedAccessors(Annotation ast, EclipseNode annotationNode, EclipseNode annotatedNode, EclipseNode tdNode, TypeDeclaration td, EclipseNode accessorsAnnotationNode, boolean jacksonizedBuilder) {
AnnotationValues<Accessors> 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<Jacksonized> {
}
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<Builder> 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<Jacksonized> {
}
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<Annotation> result = new ArrayList<Annotation>();
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;
@@ -162,13 +162,9 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler<SuperBuilder> {
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<SuperBuilder> {
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<SuperBuilder> {
}
// 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<SuperBuilder> {
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<SuperBuilder> {
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<SuperBuilder> {
TypeReference builderType = new SingleTypeReference(classGenericName.toCharArray(), 0);
out.arguments = new Argument[] {new Argument(INSTANCE_VARIABLE_NAME, 0, builderType, Modifier.FINAL)};
List<Statement> body = new ArrayList<Statement>();
if (inherited) {
// Call super.
MessageSend callToSuper = new MessageSend();
@@ -729,14 +721,14 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler<SuperBuilder> {
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<SuperBuilder> {
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<SuperBuilder> {
java.util.HashSet<String> usedNames = new HashSet<String>();
// 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<SuperBuilder> {
return usedNames;
}
private void addFirstToken(java.util.Set<String> 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<String> typeParamStrings) {
@@ -1227,8 +1216,7 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler<SuperBuilder> {
// 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;
}
}
}
@@ -62,17 +62,15 @@ public class HandleJacksonized extends JavacAnnotationHandler<Jacksonized> {
@Override public void handle(AnnotationValues<Jacksonized> 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<Jacksonized> {
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<Accessors> 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<Jacksonized> {
}
}
}
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<Jacksonized> {
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<Jacksonized> {
}
AnnotationValues<Builder> builderAnnotation = builderAnnotationNode != null ?
createAnnotation(Builder.class, builderAnnotationNode) :
null;
createAnnotation(Builder.class, builderAnnotationNode) : null;
AnnotationValues<SuperBuilder> 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<Jacksonized> {
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<Builder> 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("<init>")) {
@@ -226,9 +218,8 @@ public class HandleJacksonized extends JavacAnnotationHandler<Jacksonized> {
}
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<Jacksonized> {
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;
@@ -143,13 +143,10 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> {
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<SuperBuilder> {
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<SuperBuilder> {
}
sanityCheckForMethodGeneratingAnnotationsOnBuilderClass(job.builderImplType, annotationNode);
}
// Create a simple constructor for the BuilderImpl class.
JCMethodDecl cd = HandleConstructor.createConstructor(AccessLevel.PRIVATE, List.<JCAnnotation>nil(), job.builderImplType, List.<JavacNode>nil(), false, annotationNode);
if (cd != null) injectMethod(job.builderImplType, cd);
@@ -515,7 +510,7 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> {
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<SuperBuilder> {
if (callBuilderBasedSuperConstructor) {
// The first statement must be the call to the super constructor.
JCMethodInvocation callToSuperConstructor = maker.Apply(List.<JCExpression>nil(),
maker.Ident(job.toName("super")),
List.<JCExpression>of(maker.Ident(builderVariableName)));
maker.Ident(job.toName("super")),
List.<JCExpression>of(maker.Ident(builderVariableName)));
statements.prepend(maker.Exec(callToSuperConstructor));
}
@@ -659,7 +654,7 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> {
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<SuperBuilder> {
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<JCStatement> body = new ListBuffer<JCStatement>();
if (inherited) {
@@ -709,7 +704,7 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> {
return maker.MethodDef(modifiers, name, returnType, List.<JCTypeParameter>nil(), List.of(param), List.<JCExpression>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<SuperBuilder> {
// 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<JCExpression> typeParamsForBuilderParameter = getTypeParamExpressions(job.typeParams, maker, job.sourceNode);
@@ -804,7 +799,7 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> {
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.<JCTypeParameter>nil(), List.<JCVariableDecl>nil(), List.<JCExpression>nil(), null, null);
}
@@ -1050,8 +1045,7 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> {
java.util.HashSet<String> usedNames = new HashSet<String>();
// 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<SuperBuilder> {
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<SuperBuilder> {
}
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<SuperBuilder> {
}
return typeParamsForBuilderParameter;
}
private JCExpression copySelect(JavacTreeMaker maker, JCFieldAccess typeParam) {
java.util.List<Name> chainNames = new ArrayList<Name>();
JCExpression expression = typeParam;
@@ -1135,7 +1126,7 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> {
expression = null;
}
}
Collections.reverse(chainNames);
JCExpression typeParameter = null;
for (Name name : chainNames) {
@@ -1158,18 +1149,16 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> {
JCMethodDecl md = (JCMethodDecl) def;
String name = md.name.toString();
boolean matches = name.equals("<init>");
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;
}
}
}