aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/lombok/Builder.java2
-rw-r--r--src/core/lombok/NoArgsConstructor.java2
-rwxr-xr-xsrc/core/lombok/eclipse/handlers/HandleBuilder.java2
-rw-r--r--src/core/lombok/eclipse/handlers/HandleExtensionMethod.java4
-rw-r--r--src/core/lombok/eclipse/handlers/HandleFieldDefaults.java2
-rw-r--r--src/core/lombok/eclipse/handlers/HandleSuperBuilder.java34
-rw-r--r--src/core/lombok/experimental/SuperBuilder.java2
-rw-r--r--src/core/lombok/extern/jackson/Jacksonized.java2
-rw-r--r--src/core/lombok/javac/handlers/HandleExtensionMethod.java6
-rw-r--r--src/core/lombok/javac/handlers/HandleFieldDefaults.java2
-rw-r--r--src/core/lombok/javac/handlers/HandleSuperBuilder.java29
-rw-r--r--src/core/lombok/javac/handlers/JavacHandlerUtil.java4
12 files changed, 64 insertions, 27 deletions
diff --git a/src/core/lombok/Builder.java b/src/core/lombok/Builder.java
index 64294e4b..06ca3853 100644
--- a/src/core/lombok/Builder.java
+++ b/src/core/lombok/Builder.java
@@ -160,7 +160,7 @@ public @interface Builder {
* For example, a method normally generated as {@code someField(String someField)} would instead be
* generated as {@code withSomeField(String someField)} if using {@code @Builder(setterPrefix = "with")}.
*
- * Note that using "with" to prefix builder setter methods is strongly discouraged as as "with" normally
+ * Note that using "with" to prefix builder setter methods is strongly discouraged as "with" normally
* suggests immutable data structures, and builders by definition are mutable objects.
*
* For {@code @Singular} fields, the generated methods are called {@code withName}, {@code withNames}, and {@code clearNames}, instead of
diff --git a/src/core/lombok/NoArgsConstructor.java b/src/core/lombok/NoArgsConstructor.java
index 672cd1c2..ce4df9a2 100644
--- a/src/core/lombok/NoArgsConstructor.java
+++ b/src/core/lombok/NoArgsConstructor.java
@@ -75,7 +75,7 @@ public @interface NoArgsConstructor {
* If {@code true}, initializes all final fields to 0 / null / false.
* Otherwise, a compile time error occurs.
*
- * @return Return {@code} true to force generation of a no-args constructor, picking defaults if necessary to assign required fields.
+ * @return {@code} true to force generation of a no-args constructor, picking defaults if necessary to assign required fields.
*/
boolean force() default false;
diff --git a/src/core/lombok/eclipse/handlers/HandleBuilder.java b/src/core/lombok/eclipse/handlers/HandleBuilder.java
index a2dd5057..bb9b6dda 100755
--- a/src/core/lombok/eclipse/handlers/HandleBuilder.java
+++ b/src/core/lombok/eclipse/handlers/HandleBuilder.java
@@ -983,7 +983,7 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> {
}
if (field == null) {
- FieldDeclaration fd = new FieldDeclaration(bfd.builderFieldName, 0, 0);
+ FieldDeclaration fd = new FieldDeclaration(bfd.builderFieldName.clone(), 0, 0);
fd.bits |= Eclipse.ECLIPSE_DO_NOT_TOUCH_FLAG;
fd.modifiers = ClassFileConstants.AccPrivate;
fd.type = copyType(bfd.type);
diff --git a/src/core/lombok/eclipse/handlers/HandleExtensionMethod.java b/src/core/lombok/eclipse/handlers/HandleExtensionMethod.java
index 5857780c..b84018c6 100644
--- a/src/core/lombok/eclipse/handlers/HandleExtensionMethod.java
+++ b/src/core/lombok/eclipse/handlers/HandleExtensionMethod.java
@@ -50,10 +50,10 @@ public class HandleExtensionMethod extends EclipseAnnotationHandler<ExtensionMet
int modifiers = typeDecl == null ? 0 : typeDecl.modifiers;
boolean notAClass = (modifiers &
- (ClassFileConstants.AccInterface | ClassFileConstants.AccAnnotation)) != 0;
+ (ClassFileConstants.AccAnnotation)) != 0;
if (typeDecl == null || notAClass) {
- annotationNode.addError("@ExtensionMethod is legal only on classes and enums.");
+ annotationNode.addError("@ExtensionMethod is legal only on classes and enums and interfaces.");
return;
}
diff --git a/src/core/lombok/eclipse/handlers/HandleFieldDefaults.java b/src/core/lombok/eclipse/handlers/HandleFieldDefaults.java
index 3297ba06..fd36454d 100644
--- a/src/core/lombok/eclipse/handlers/HandleFieldDefaults.java
+++ b/src/core/lombok/eclipse/handlers/HandleFieldDefaults.java
@@ -160,7 +160,7 @@ public class HandleFieldDefaults extends EclipseASTAdapter {
boolean defaultToFinal = makeFinalIsExplicit ? false : Boolean.TRUE.equals(typeNode.getAst().readConfiguration(ConfigurationKeys.FIELD_DEFAULTS_FINAL_EVERYWHERE));
if (!defaultToPrivate && !defaultToFinal && fieldDefaults == null) return;
- // Do not apply field defaults to records if set using the the config system
+ // Do not apply field defaults to records if set using the config system
if (fieldDefaults == null && !isClassOrEnum(typeNode)) return;
AccessLevel fdAccessLevel = (fieldDefaults != null && levelIsExplicit) ? fd.level() : defaultToPrivate ? AccessLevel.PRIVATE : null;
boolean fdToFinal = (fieldDefaults != null && makeFinalIsExplicit) ? fd.makeFinal() : defaultToFinal;
diff --git a/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java b/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java
index 558c6ec2..e91478e0 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;
@@ -387,16 +386,16 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler<SuperBuilder> {
injectMethod(job.builderType, generateStaticFillValuesMethod(job, annInstance.setterPrefix()));
}
- // Generate abstract self() and build() methods in the abstract builder.
- injectMethod(job.builderType, generateAbstractSelfMethod(job, superclassBuilderClass != null, builderGenericName));
- job.setBuilderToAbstract();
- injectMethod(job.builderType, generateAbstractBuildMethod(job, superclassBuilderClass != null, classGenericName));
-
// Create the setter methods in the abstract builder.
for (BuilderFieldData bfd : job.builderFields) {
generateSetterMethodsForBuilder(job, bfd, builderGenericName, annInstance.setterPrefix());
}
+ // Generate abstract self() and build() methods in the abstract builder.
+ injectMethod(job.builderType, generateAbstractSelfMethod(job, superclassBuilderClass != null, builderGenericName));
+ job.setBuilderToAbstract();
+ injectMethod(job.builderType, generateAbstractBuildMethod(job, superclassBuilderClass != null, classGenericName));
+
// Create the toString() method for the abstract builder.
if (methodExists("toString", job.builderType, 0) == MemberExistsResult.NOT_EXISTS) {
List<Included<EclipseNode, ToString.Include>> fieldNodes = new ArrayList<Included<EclipseNode, ToString.Include>>();
@@ -948,7 +947,7 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler<SuperBuilder> {
}
if (field == null) {
- FieldDeclaration fd = new FieldDeclaration(bfd.builderFieldName, 0, 0);
+ FieldDeclaration fd = new FieldDeclaration(bfd.builderFieldName.clone(), 0, 0);
fd.bits |= Eclipse.ECLIPSE_DO_NOT_TOUCH_FLAG;
fd.modifiers = ClassFileConstants.AccPrivate;
fd.type = copyType(bfd.type);
@@ -1100,14 +1099,29 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler<SuperBuilder> {
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<String> 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<String> typeParamStrings) {
if (!typeParamStrings.contains(classGenericName)) return classGenericName;
diff --git a/src/core/lombok/experimental/SuperBuilder.java b/src/core/lombok/experimental/SuperBuilder.java
index 0733a616..193bda0f 100644
--- a/src/core/lombok/experimental/SuperBuilder.java
+++ b/src/core/lombok/experimental/SuperBuilder.java
@@ -69,7 +69,7 @@ public @interface SuperBuilder {
* For example, a method normally generated as {@code someField(String someField)} would instead be
* generated as {@code withSomeField(String someField)} if using {@code @SuperBuilder(setterPrefix = "with")}.
*
- * Note that using "with" to prefix builder setter methods is strongly discouraged as as "with" normally
+ * Note that using "with" to prefix builder setter methods is strongly discouraged as "with" normally
* suggests immutable data structures, and builders by definition are mutable objects.
*
* For {@code @Singular} fields, the generated methods are called {@code withName}, {@code withNames}, and {@code clearNames}, instead of
diff --git a/src/core/lombok/extern/jackson/Jacksonized.java b/src/core/lombok/extern/jackson/Jacksonized.java
index cf6678da..801ddbcb 100644
--- a/src/core/lombok/extern/jackson/Jacksonized.java
+++ b/src/core/lombok/extern/jackson/Jacksonized.java
@@ -49,7 +49,7 @@ import lombok.experimental.SuperBuilder;
* <li>Insert {@code @JsonPOJOBuilder(withPrefix="")} on the generated builder
* class to override Jackson's default prefix "with". If you configured a
* different prefix in lombok using {@code setterPrefix}, this value is used. If
- * you changed the name of the {@code build()} method using using
+ * you changed the name of the {@code build()} method using
* {@code buildMethodName}, this is also made known to Jackson.</li>
* <li>For {@code @SuperBuilder}, make the builder implementation class
* package-private.</li>
diff --git a/src/core/lombok/javac/handlers/HandleExtensionMethod.java b/src/core/lombok/javac/handlers/HandleExtensionMethod.java
index dd565f72..98b000c2 100644
--- a/src/core/lombok/javac/handlers/HandleExtensionMethod.java
+++ b/src/core/lombok/javac/handlers/HandleExtensionMethod.java
@@ -73,10 +73,10 @@ public class HandleExtensionMethod extends JavacAnnotationHandler<ExtensionMetho
deleteAnnotationIfNeccessary(annotationNode, ExtensionMethod.class);
JavacNode typeNode = annotationNode.up();
- boolean isClassOrEnum = isClassOrEnum(typeNode);
+ boolean isClassOrEnumOrInterface = isClassOrEnumOrInterface(typeNode);
- if (!isClassOrEnum) {
- annotationNode.addError("@ExtensionMethod can only be used on a class or an enum");
+ if (!isClassOrEnumOrInterface) {
+ annotationNode.addError("@ExtensionMethod can only be used on a class or an enum or an interface");
return;
}
diff --git a/src/core/lombok/javac/handlers/HandleFieldDefaults.java b/src/core/lombok/javac/handlers/HandleFieldDefaults.java
index 9a6632dd..b373d1df 100644
--- a/src/core/lombok/javac/handlers/HandleFieldDefaults.java
+++ b/src/core/lombok/javac/handlers/HandleFieldDefaults.java
@@ -140,7 +140,7 @@ public class HandleFieldDefaults extends JavacASTAdapter {
boolean defaultToFinal = makeFinalIsExplicit ? false : Boolean.TRUE.equals(typeNode.getAst().readConfiguration(ConfigurationKeys.FIELD_DEFAULTS_FINAL_EVERYWHERE));
if (!defaultToPrivate && !defaultToFinal && fieldDefaults == null) return;
- // Do not apply field defaults to records if set using the the config system
+ // Do not apply field defaults to records if set using the config system
if (fieldDefaults == null && !isClassOrEnum(typeNode)) return;
AccessLevel fdAccessLevel = (fieldDefaults != null && levelIsExplicit) ? fd.level() : defaultToPrivate ? AccessLevel.PRIVATE : null;
boolean fdToFinal = (fieldDefaults != null && makeFinalIsExplicit) ? fd.makeFinal() : defaultToFinal;
diff --git a/src/core/lombok/javac/handlers/HandleSuperBuilder.java b/src/core/lombok/javac/handlers/HandleSuperBuilder.java
index 7418ac87..913f838c 100644
--- a/src/core/lombok/javac/handlers/HandleSuperBuilder.java
+++ b/src/core/lombok/javac/handlers/HandleSuperBuilder.java
@@ -336,6 +336,11 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> {
injectMethod(job.builderType, sfvm);
}
+ // Create the setter methods in the abstract builder.
+ for (BuilderFieldData bfd : job.builderFields) {
+ generateSetterMethodsForBuilder(job, bfd, builderGenericName, annInstance.setterPrefix());
+ }
+
// Generate abstract self() and build() methods in the abstract builder.
JCMethodDecl asm = generateAbstractSelfMethod(job, superclassBuilderClass != null, builderGenericName);
recursiveSetGeneratedBy(asm, annotationNode);
@@ -344,11 +349,6 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> {
recursiveSetGeneratedBy(abm, annotationNode);
injectMethod(job.builderType, abm);
- // Create the setter methods in the abstract builder.
- for (BuilderFieldData bfd : job.builderFields) {
- generateSetterMethodsForBuilder(job, bfd, builderGenericName, annInstance.setterPrefix());
- }
-
// Create the toString() method for the abstract builder.
java.util.List<Included<JavacNode, ToString.Include>> fieldNodes = new ArrayList<Included<JavacNode, ToString.Include>>();
for (BuilderFieldData bfd : job.builderFields) {
@@ -1051,9 +1051,28 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> {
}
}
+ // 4. Add extends and implements clauses.
+ addFirstToken(usedNames, Javac.getExtendsClause(td));
+ for (JCExpression impl : td.getImplementsClause()) {
+ addFirstToken(usedNames, impl);
+ }
+
return usedNames;
}
+ private void addFirstToken(java.util.Set<String> 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;
+ }
+ usedNames.add(type.toString());
+ }
+
private String generateNonclashingNameFor(String classGenericName, java.util.HashSet<String> typeParamStrings) {
if (!typeParamStrings.contains(classGenericName)) return classGenericName;
int counter = 2;
diff --git a/src/core/lombok/javac/handlers/JavacHandlerUtil.java b/src/core/lombok/javac/handlers/JavacHandlerUtil.java
index b17e34d8..9d153a72 100644
--- a/src/core/lombok/javac/handlers/JavacHandlerUtil.java
+++ b/src/core/lombok/javac/handlers/JavacHandlerUtil.java
@@ -2069,6 +2069,10 @@ public class JavacHandlerUtil {
return isClassAndDoesNotHaveFlags(typeNode, Flags.INTERFACE | Flags.ANNOTATION | RECORD);
}
+ public static boolean isClassOrEnumOrInterface(JavacNode typeNode) {
+ return isClassAndDoesNotHaveFlags(typeNode, Flags.ANNOTATION | RECORD);
+ }
+
/**
* Returns {@code true} if the provided node is an actual class, an enum or a record and not some other type declaration (so, not an annotation definition or interface).
*/