aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok/eclipse/handlers
diff options
context:
space:
mode:
authorReinier Zwitserloot <r.zwitserloot@projectlombok.org>2019-03-25 23:11:48 +0100
committerReinier Zwitserloot <r.zwitserloot@projectlombok.org>2019-03-25 23:11:48 +0100
commit228e99fe5203e92c7297325fec69a82abc1a4bd7 (patch)
treed3176a94f672a58f9c9927d812d048323080f363 /src/core/lombok/eclipse/handlers
parent535e20972c56e65b598df0d0849a25daa7a69e8d (diff)
downloadlombok-228e99fe5203e92c7297325fec69a82abc1a4bd7.tar.gz
lombok-228e99fe5203e92c7297325fec69a82abc1a4bd7.tar.bz2
lombok-228e99fe5203e92c7297325fec69a82abc1a4bd7.zip
[fixes #2046] you can now suppress the builder() method, useful if you only want toBuilder(). Also suppresses the warnings about any missing Builder.Default annotations.
Diffstat (limited to 'src/core/lombok/eclipse/handlers')
-rwxr-xr-xsrc/core/lombok/eclipse/handlers/HandleBuilder.java24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/core/lombok/eclipse/handlers/HandleBuilder.java b/src/core/lombok/eclipse/handlers/HandleBuilder.java
index 3391b99d..3adbc27c 100755
--- a/src/core/lombok/eclipse/handlers/HandleBuilder.java
+++ b/src/core/lombok/eclipse/handlers/HandleBuilder.java
@@ -173,7 +173,15 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> {
if (buildMethodName == null) builderMethodName = "build";
if (builderClassName == null) builderClassName = "";
- 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;
if (!builderClassName.isEmpty()) {
if (!checkName("builderClassName", builderClassName, annotationNode)) return;
@@ -192,6 +200,8 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> {
boolean addCleaning = false;
boolean isStatic = true;
+ List<EclipseNode> nonFinalNonDefaultedFields = null;
+
if (parent.get() instanceof TypeDeclaration) {
tdParent = parent;
TypeDeclaration td = (TypeDeclaration) tdParent.get();
@@ -225,7 +235,8 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> {
if (fd.initialization != null && isDefault == null) {
if (isFinal) continue;
- fieldNode.addWarning("@Builder 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<EclipseNode>();
+ nonFinalNonDefaultedFields.add(fieldNode);
}
if (isDefault != null) {
@@ -486,7 +497,8 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> {
if (cleanMethod != null) injectMethod(builderType, cleanMethod);
}
- if (methodExists(builderMethodName, tdParent, -1) == MemberExistsResult.NOT_EXISTS) {
+ if (generateBuilderMethod && methodExists(builderMethodName, tdParent, -1) != MemberExistsResult.NOT_EXISTS) generateBuilderMethod = false;
+ if (generateBuilderMethod) {
MethodDeclaration md = generateBuilderMethod(isStatic, builderMethodName, builderClassName, tdParent, typeParams, ast);
if (md != null) injectMethod(tdParent, md);
}
@@ -508,6 +520,12 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> {
if (md != null) injectMethod(tdParent, md);
}
+
+ if (nonFinalNonDefaultedFields != null && generateBuilderMethod) {
+ for (EclipseNode fieldNode : nonFinalNonDefaultedFields) {
+ fieldNode.addWarning("@Builder 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.");
+ }
+ }
}
private static final char[] BUILDER_TEMP_VAR = {'b', 'u', 'i', 'l', 'd', 'e', 'r'};