aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java24
-rw-r--r--src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java13
-rw-r--r--src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java17
3 files changed, 39 insertions, 15 deletions
diff --git a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java
index bf2e1cbc..64345742 100644
--- a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java
+++ b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java
@@ -39,7 +39,6 @@ import lombok.javac.handlers.JavacSingularsRecipes.StatementMaker;
import com.sun.tools.javac.code.Flags;
import com.sun.tools.javac.tree.JCTree;
-import com.sun.tools.javac.tree.JCTree.JCAnnotation;
import com.sun.tools.javac.tree.JCTree.JCBlock;
import com.sun.tools.javac.tree.JCTree.JCExpression;
import com.sun.tools.javac.tree.JCTree.JCModifiers;
@@ -82,9 +81,24 @@ abstract class JavacGuavaSingularizer extends JavacSingularizer {
@Override
protected void generateSingularMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) {
+ ListBuffer<JCStatement> statements = generateSingularMethodStatements(maker, data, builderType, source);
+ List<JCVariableDecl> params = generateSingularMethodParameters(maker, data, builderType, source);
+ finishAndInjectSingularMethod(maker, returnType, returnStatement, data, builderType, source, fluent, deprecate, statements, params, getAddMethodName());
+ }
+
+ private List<JCVariableDecl> generateSingularMethodParameters(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) {
Name[] names = generateSingularMethodParameterNames(data, builderType);
+ ListBuffer<JCVariableDecl> params = new ListBuffer<JCVariableDecl>();
+ for (int i = 0; i < names.length; i++) {
+ params.append(generateSingularMethodParameter(i, maker, data, builderType, source, names[i]));
+ }
+ return params.toList();
+ }
+ private ListBuffer<JCStatement> generateSingularMethodStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) {
ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>();
+ Name[] names = generateSingularMethodParameterNames(data, builderType);
+
statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, source));
JCExpression thisDotFieldDotAdd = chainDots(builderType, "this", data.getPluralName().toString(), getAddMethodName());
ListBuffer<JCExpression> invokeAddExprBuilder = new ListBuffer<JCExpression>();
@@ -95,13 +109,7 @@ abstract class JavacGuavaSingularizer extends JavacSingularizer {
JCExpression invokeAdd = maker.Apply(List.<JCExpression>nil(), thisDotFieldDotAdd, invokeAddExpr);
JCStatement st = maker.Exec(invokeAdd);
statements.append(st);
-
- ListBuffer<JCVariableDecl> params = new ListBuffer<JCVariableDecl>();
- for (int i = 0; i < names.length; i++) {
- params.append(generateSingularMethodParameter(i, maker, data, builderType, source, names[i]));
- }
-
- finishAndInjectSingularMethod(maker, returnType, returnStatement, data, builderType, source, fluent, deprecate, statements, params.toList(), getAddMethodName());
+ return statements;
}
private Name[] generateSingularMethodParameterNames(SingularData data, JavacNode builderType) {
diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java
index 182bf78a..90fdb0cb 100644
--- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java
+++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java
@@ -98,14 +98,21 @@ abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularize
@Override
protected void generateSingularMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) {
+ ListBuffer<JCStatement> statements = generateSingularMethodStatements(maker, data, builderType, source);
+ List<JCVariableDecl> params = generateSingularMethodParameters(maker, data, builderType, source);
+ finishAndInjectSingularMethod(maker, returnType, returnStatement, data, builderType, source, fluent, deprecate, statements, params, "add");
+ }
+
+ private ListBuffer<JCStatement> generateSingularMethodStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) {
ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>();
statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, false, source));
statements.append(generateSingularMethodAddStatement(maker, builderType, data.getSingularName(), data.getPluralName().toString()));
+ return statements;
+ }
+ private List<JCVariableDecl> generateSingularMethodParameters(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) {
JCVariableDecl param = generateSingularMethodParameter(0, maker, data, builderType, source, data.getSingularName());
- List<JCVariableDecl> params = List.of(param);
-
- finishAndInjectSingularMethod(maker, returnType, returnStatement, data, builderType, source, fluent, deprecate, statements, params, "add");
+ return List.of(param);
}
@Override
diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java
index 255bb63a..cc6b47f9 100644
--- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java
+++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java
@@ -125,21 +125,30 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer {
@Override
protected void generateSingularMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) {
+ ListBuffer<JCStatement> statements = generateSingularMethodStatements(maker, data, builderType, source);
+ List<JCVariableDecl> params = generateSingularMethodParameters(maker, data, builderType, source);
+ finishAndInjectSingularMethod(maker, returnType, returnStatement, data, builderType, source, fluent, deprecate, statements, params, "put");
+ }
+
+ private ListBuffer<JCStatement> generateSingularMethodStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) {
ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>();
- statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, true, source));
Name keyName = builderType.toName(data.getSingularName().toString() + "Key");
Name valueName = builderType.toName(data.getSingularName().toString() + "Value");
+ statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, true, source));
/* Generates: this.pluralname$key.add(singularnameKey); */
statements.append(generateSingularMethodAddStatement(maker, builderType, keyName, data.getPluralName() + "$key"));
/* Generates: this.pluralname$value.add(singularnameValue); */
statements.append(generateSingularMethodAddStatement(maker, builderType, valueName, data.getPluralName() + "$value"));
+ return statements;
+ }
+ private List<JCVariableDecl> generateSingularMethodParameters(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) {
+ Name keyName = builderType.toName(data.getSingularName().toString() + "Key");
+ Name valueName = builderType.toName(data.getSingularName().toString() + "Value");
JCVariableDecl paramKey = generateSingularMethodParameter(0, maker, data, builderType, source, keyName);
JCVariableDecl paramValue = generateSingularMethodParameter(1, maker, data, builderType, source, valueName);
- List<JCVariableDecl> params = List.of(paramKey, paramValue);
-
- finishAndInjectSingularMethod(maker, returnType, returnStatement, data, builderType, source, fluent, deprecate, statements, params, "put");
+ return List.of(paramKey, paramValue);
}
@Override