diff options
4 files changed, 12 insertions, 21 deletions
diff --git a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java index d5ac5abb..ad8f978a 100644 --- a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java +++ b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java @@ -281,6 +281,15 @@ public class JavacSingularsRecipes { return maker.Exec(invokeAdd); } + protected void finishAndInjectSingularMethod(JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent, JCModifiers mods, ListBuffer<JCStatement> statements, List<JCVariableDecl> params, String addMethodName) { + if (returnStatement != null) statements.append(returnStatement); + JCBlock body = maker.Block(0, statements.toList()); + Name name = data.getSingularName(); + if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName(addMethodName, name.toString())); + + finishAndInjectMethod(maker, returnType, builderType, source, mods, body, name, params); + } + protected abstract void generatePluralMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent); public abstract void appendBuildCode(SingularData data, JavacNode builderType, JCTree source, ListBuffer<JCStatement> statements, Name targetVariableName, String builderVariable); diff --git a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java index 25fc8751..e79f626c 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java @@ -108,13 +108,7 @@ abstract class JavacGuavaSingularizer extends JavacSingularizer { params.append(generateSingularMethodParameter(i, maker, data, builderType, source, names[i])); } - String addMethodName = getAddMethodName(); - if (returnStatement != null) statements.append(returnStatement); - JCBlock body = maker.Block(0, statements.toList()); - Name methodName = data.getSingularName(); - if (!fluent) methodName = builderType.toName(HandlerUtil.buildAccessorName(addMethodName, methodName.toString())); - - finishAndInjectMethod(maker, returnType, builderType, source, mods, body, methodName, params.toList()); + finishAndInjectSingularMethod(maker, returnType, returnStatement, data, builderType, source, fluent, mods, statements, params.toList(), getAddMethodName()); } @Override diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java index 981f40cd..7cc7e30e 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java @@ -106,13 +106,7 @@ abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularize JCVariableDecl param = generateSingularMethodParameter(0, maker, data, builderType, source, data.getSingularName()); List<JCVariableDecl> params = List.of(param); - String addMethodName = "add"; - if (returnStatement != null) statements.append(returnStatement); - JCBlock body = maker.Block(0, statements.toList()); - Name name = data.getSingularName(); - if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName(addMethodName, name.toString())); - - finishAndInjectMethod(maker, returnType, builderType, source, mods, body, name, params); + finishAndInjectSingularMethod(maker, returnType, returnStatement, data, builderType, source, fluent, mods, statements, params, "add"); } @Override diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java index a7859ce6..687cb1d1 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java @@ -141,13 +141,7 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { JCVariableDecl paramValue = generateSingularMethodParameter(1, maker, data, builderType, source, valueName); List<JCVariableDecl> params = List.of(paramKey, paramValue); - String addMethodName = "put"; - if (returnStatement != null) statements.append(returnStatement); - JCBlock body = maker.Block(0, statements.toList()); - Name name = data.getSingularName(); - if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName(addMethodName, name.toString())); - - finishAndInjectMethod(maker, returnType, builderType, source, mods, body, name, params); + finishAndInjectSingularMethod(maker, returnType, returnStatement, data, builderType, source, fluent, mods, statements, params, "put"); } @Override |