From d3ae4d994880a1a087108275e101ab4fbb43f071 Mon Sep 17 00:00:00 2001 From: daliclass Date: Sun, 5 May 2019 22:28:48 +0100 Subject: [Feature] staticConstructor should use already defined private constructor if available --- .../lombok/eclipse/handlers/HandleConstructor.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'src/core/lombok/eclipse') diff --git a/src/core/lombok/eclipse/handlers/HandleConstructor.java b/src/core/lombok/eclipse/handlers/HandleConstructor.java index 660b9985..c6b51042 100755 --- a/src/core/lombok/eclipse/handlers/HandleConstructor.java +++ b/src/core/lombok/eclipse/handlers/HandleConstructor.java @@ -242,8 +242,7 @@ public class HandleConstructor { ASTNode source = sourceNode.get(); boolean staticConstrRequired = staticName != null && !staticName.equals(""); - - if (skipIfConstructorExists != SkipIfConstructorExists.NO && constructorExists(typeNode) != MemberExistsResult.NOT_EXISTS) return; + if (skipIfConstructorExists != SkipIfConstructorExists.NO) { for (EclipseNode child : typeNode.down()) { if (child.getKind() == Kind.ANNOTATION) { @@ -273,12 +272,18 @@ public class HandleConstructor { if (noArgs && noArgsConstructorExists(typeNode)) return; - ConstructorDeclaration constr = createConstructor( - staticConstrRequired ? AccessLevel.PRIVATE : level, typeNode, fieldsToParam, forceDefaults, - sourceNode, onConstructor); - injectMethod(typeNode, constr); + if (!(skipIfConstructorExists != SkipIfConstructorExists.NO && constructorExists(typeNode) != MemberExistsResult.NOT_EXISTS)) { + ConstructorDeclaration constr = createConstructor( + staticConstrRequired ? AccessLevel.PRIVATE : level, typeNode, fieldsToParam, forceDefaults, + sourceNode, onConstructor); + injectMethod(typeNode, constr); + } + generateStaticConstructor(staticConstrRequired, typeNode, staticName, level, fieldsToParam, source); + } + + private void generateStaticConstructor(boolean staticConstrRequired, EclipseNode typeNode, String staticName, AccessLevel level, Collection fields, ASTNode source) { if (staticConstrRequired) { - MethodDeclaration staticConstr = createStaticConstructor(level, staticName, typeNode, fieldsToParam, source); + MethodDeclaration staticConstr = createStaticConstructor(level, staticName, typeNode, fields, source); injectMethod(typeNode, staticConstr); } } -- cgit