aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok/eclipse
diff options
context:
space:
mode:
authorJan Rieke <it@janrieke.de>2020-05-01 23:56:17 +0200
committerRoel Spilker <r.spilker@gmail.com>2020-05-28 21:18:35 +0200
commit48b1f17f7ef0e0b3d90dee74ee1b490a02cacff2 (patch)
tree1e7d52d4a53b3e9e9b8ba73edc99421a03102d24 /src/core/lombok/eclipse
parentfaa70bd21d2872e8354574cc98c7aa82ab996bcd (diff)
downloadlombok-48b1f17f7ef0e0b3d90dee74ee1b490a02cacff2.tar.gz
lombok-48b1f17f7ef0e0b3d90dee74ee1b490a02cacff2.tar.bz2
lombok-48b1f17f7ef0e0b3d90dee74ee1b490a02cacff2.zip
[SuperBuilder] allow constructor customization
Diffstat (limited to 'src/core/lombok/eclipse')
-rw-r--r--src/core/lombok/eclipse/handlers/HandleSuperBuilder.java28
1 files changed, 26 insertions, 2 deletions
diff --git a/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java b/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java
index a49c20a4..455d40ed 100644
--- a/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java
+++ b/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java
@@ -274,8 +274,10 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler<SuperBuilder> {
// If there is no superclass, superclassBuilderClassExpression is still == null at this point.
// You can use it to check whether to inherit or not.
- generateBuilderBasedConstructor(cfv, tdParent, typeParams, builderFields, annotationNode, builderClassName,
- superclassBuilderClass != null);
+ if (!constructorExists(tdParent, builderClassName)) {
+ generateBuilderBasedConstructor(cfv, tdParent, typeParams, builderFields, annotationNode, builderClassName,
+ superclassBuilderClass != null);
+ }
// Create the abstract builder class, or reuse an existing one.
EclipseNode builderType = findInnerClass(tdParent, builderClassName);
@@ -1159,4 +1161,26 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler<SuperBuilder> {
System.arraycopy(name, 0, out, prefix.length, name.length);
return out;
}
+
+ private boolean constructorExists(EclipseNode type, String builderClassName) {
+ if (type != null && type.get() instanceof TypeDeclaration) {
+ TypeDeclaration typeDecl = (TypeDeclaration)type.get();
+ if (typeDecl.methods != null) for (AbstractMethodDeclaration def : typeDecl.methods) {
+ if (def instanceof ConstructorDeclaration) {
+ if ((def.bits & ASTNode.IsDefaultConstructor) != 0) continue;
+ if (!def.isConstructor()) continue;
+ if (isTolerate(type, def)) continue;
+ if (def.arguments.length != 1) continue;
+
+ // 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;
+ }
+ }
+ }
+
+ return false;
+ }
}