aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok/javac/handlers
diff options
context:
space:
mode:
authorReinier Zwitserloot <r.zwitserloot@projectlombok.org>2019-03-25 23:40:29 +0100
committerReinier Zwitserloot <r.zwitserloot@projectlombok.org>2019-03-26 01:25:18 +0100
commit33281d857891b24cb1c40233807620769a158bbf (patch)
tree2fff30e5f0e619c6c246af4adbecc2d148a26bd6 /src/core/lombok/javac/handlers
parent5d4066ed48a092ad89cb9013bcb6958c093bc9e0 (diff)
downloadlombok-33281d857891b24cb1c40233807620769a158bbf.tar.gz
lombok-33281d857891b24cb1c40233807620769a158bbf.tar.bz2
lombok-33281d857891b24cb1c40233807620769a158bbf.zip
[#2046] Extend suppress builder feature to `@SuperBuilder`
Diffstat (limited to 'src/core/lombok/javac/handlers')
-rw-r--r--src/core/lombok/javac/handlers/HandleSuperBuilder.java23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/core/lombok/javac/handlers/HandleSuperBuilder.java b/src/core/lombok/javac/handlers/HandleSuperBuilder.java
index 7ef6b658..7eb9873b 100644
--- a/src/core/lombok/javac/handlers/HandleSuperBuilder.java
+++ b/src/core/lombok/javac/handlers/HandleSuperBuilder.java
@@ -103,7 +103,14 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> {
if (builderMethodName == null) builderMethodName = "builder";
if (buildMethodName == null) buildMethodName = "build";
- if (!checkName("builderMethodName", builderMethodName, annotationNode)) return;
+ boolean generateBuilderMethod;
+ if (builderMethodName.isEmpty()) {
+ generateBuilderMethod = false;
+ } else if (!checkName("builderMethodName", builderMethodName, annotationNode)) {
+ return;
+ } else {
+ generateBuilderMethod = true;
+ }
if (!checkName("buildMethodName", buildMethodName, annotationNode)) return;
boolean toBuilder = superbuilderAnnotation.toBuilder();
@@ -125,6 +132,8 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> {
// Gather all fields of the class that should be set by the builder.
JCClassDecl td = (JCClassDecl) tdParent.get();
ListBuffer<JavacNode> allFields = new ListBuffer<JavacNode>();
+ ArrayList<JavacNode> nonFinalNonDefaultedFields = null;
+
boolean valuePresent = (hasAnnotation(lombok.Value.class, tdParent) || hasAnnotation("lombok.experimental.Value", tdParent));
for (JavacNode fieldNode : HandleConstructor.findAllFields(tdParent, true)) {
JCVariableDecl fd = (JCVariableDecl) fieldNode.get();
@@ -150,7 +159,8 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> {
if (fd.init != null && isDefault == null) {
if (isFinal) continue;
- fieldNode.addWarning("@SuperBuilder will ignore the initializing expression entirely. If you want the initializing expression to serve as default, add @Builder.Default. If it is not supposed to be settable during building, make the field final.");
+ if (nonFinalNonDefaultedFields == null) nonFinalNonDefaultedFields = new ArrayList<JavacNode>();
+ nonFinalNonDefaultedFields.add(fieldNode);
}
if (isDefault != null) {
@@ -347,7 +357,8 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> {
// Add the builder() method to the annotated class.
// Allow users to specify their own builder() methods, e.g., to provide default values.
- if (methodExists(builderMethodName, tdParent, -1) == MemberExistsResult.NOT_EXISTS) {
+ if (generateBuilderMethod && methodExists(builderMethodName, tdParent, -1) != MemberExistsResult.NOT_EXISTS) generateBuilderMethod = false;
+ if (generateBuilderMethod) {
JCMethodDecl builderMethod = generateBuilderMethod(builderMethodName, builderClassName, builderImplClassName, annotationNode, tdParent, typeParams);
recursiveSetGeneratedBy(builderMethod, ast, annotationNode.getContext());
if (builderMethod != null) injectMethod(tdParent, builderMethod);
@@ -369,6 +380,12 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> {
// Should not happen.
}
}
+
+ if (nonFinalNonDefaultedFields != null && generateBuilderMethod) {
+ for (JavacNode fieldNode : nonFinalNonDefaultedFields) {
+ fieldNode.addWarning("@SuperBuilder will ignore the initializing expression entirely. If you want the initializing expression to serve as default, add @Builder.Default. If it is not supposed to be settable during building, make the field final.");
+ }
+ }
}
/**