aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorEmil Lundberg <emil@emlun.se>2019-01-10 04:13:34 +0100
committerEmil Lundberg <emil@emlun.se>2019-01-13 02:25:26 +0100
commitfd7301117deeaa94f4ecb4316a3ef68c1a13a660 (patch)
tree3d35a24ac74541c397934cf7cd49dede38dd5215 /src/core
parente8c70dd755c528b4f975be95333a337c290db2be (diff)
downloadlombok-fd7301117deeaa94f4ecb4316a3ef68c1a13a660.tar.gz
lombok-fd7301117deeaa94f4ecb4316a3ef68c1a13a660.tar.bz2
lombok-fd7301117deeaa94f4ecb4316a3ef68c1a13a660.zip
Extract method finishAndInjectSingularMethod
Diffstat (limited to 'src/core')
-rw-r--r--src/core/lombok/javac/handlers/JavacSingularsRecipes.java9
-rw-r--r--src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java8
-rw-r--r--src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java8
-rw-r--r--src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java8
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