aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok
diff options
context:
space:
mode:
authorEmil Lundberg <emil@emlun.se>2019-01-10 03:58:48 +0100
committerEmil Lundberg <emil@emlun.se>2019-01-13 02:20:04 +0100
commit54d8d4b4313cdaa46f7f9581ee6d4214a1542c20 (patch)
treea7fde87d52bbccd5699765ba08e44154981cb97d /src/core/lombok
parente9f4bcb890ba96f1c31bce01c3ee7c15bf56866f (diff)
downloadlombok-54d8d4b4313cdaa46f7f9581ee6d4214a1542c20.tar.gz
lombok-54d8d4b4313cdaa46f7f9581ee6d4214a1542c20.tar.bz2
lombok-54d8d4b4313cdaa46f7f9581ee6d4214a1542c20.zip
Extract method generateSingularMethodAddStatement
Diffstat (limited to 'src/core/lombok')
-rw-r--r--src/core/lombok/javac/handlers/JavacSingularsRecipes.java6
-rw-r--r--src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java4
-rw-r--r--src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java9
3 files changed, 9 insertions, 10 deletions
diff --git a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java
index b2bcf091..d5ac5abb 100644
--- a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java
+++ b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java
@@ -275,6 +275,12 @@ public class JavacSingularsRecipes {
return maker.VarDef(mods, name, type, null);
}
+ protected JCStatement generateSingularMethodAddStatement(JavacTreeMaker maker, JavacNode builderType, Name argumentName, String builderFieldName) {
+ JCExpression thisDotFieldDotAdd = chainDots(builderType, "this", builderFieldName, "add");
+ JCExpression invokeAdd = maker.Apply(List.<JCExpression>nil(), thisDotFieldDotAdd, List.<JCExpression>of(maker.Ident(argumentName)));
+ return maker.Exec(invokeAdd);
+ }
+
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/JavacJavaUtilListSetSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java
index f270a375..3781a67e 100644
--- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java
+++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java
@@ -101,9 +101,7 @@ abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularize
JCModifiers mods = makeMods(maker, builderType, deprecate);
ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>();
statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, false, source));
- JCExpression thisDotFieldDotAdd = chainDots(builderType, "this", data.getPluralName().toString(), "add");
- JCExpression invokeAdd = maker.Apply(List.<JCExpression>nil(), thisDotFieldDotAdd, List.<JCExpression>of(maker.Ident(data.getSingularName())));
- JCStatement st = maker.Exec(invokeAdd);
+ JCStatement st = generateSingularMethodAddStatement(maker, builderType, data.getSingularName(), data.getPluralName().toString());
statements.append(st);
if (returnStatement != null) statements.append(returnStatement);
diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java
index ad628c5b..16b5f1a0 100644
--- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java
+++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java
@@ -40,7 +40,6 @@ import org.mangosdk.spi.ProviderFor;
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;
@@ -133,15 +132,11 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer {
Name keyName = builderType.toName(data.getSingularName().toString() + "Key");
Name valueName = builderType.toName(data.getSingularName().toString() + "Value");
/* this.pluralname$key.add(singularnameKey); */ {
- JCExpression thisDotKeyFieldDotAdd = chainDots(builderType, "this", data.getPluralName() + "$key", "add");
- JCExpression invokeAdd = maker.Apply(List.<JCExpression>nil(), thisDotKeyFieldDotAdd, List.<JCExpression>of(maker.Ident(keyName)));
- JCStatement st = maker.Exec(invokeAdd);
+ JCStatement st = generateSingularMethodAddStatement(maker, builderType, keyName, data.getPluralName() + "$key");
statements.append(st);
}
/* this.pluralname$value.add(singularnameValue); */ {
- JCExpression thisDotValueFieldDotAdd = chainDots(builderType, "this", data.getPluralName() + "$value", "add");
- JCExpression invokeAdd = maker.Apply(List.<JCExpression>nil(), thisDotValueFieldDotAdd, List.<JCExpression>of(maker.Ident(valueName)));
- JCStatement st = maker.Exec(invokeAdd);
+ JCStatement st = generateSingularMethodAddStatement(maker, builderType, valueName, data.getPluralName() + "$value");
statements.append(st);
}
if (returnStatement != null) statements.append(returnStatement);