diff options
author | Emil Lundberg <emil@emlun.se> | 2019-01-10 05:42:14 +0100 |
---|---|---|
committer | Emil Lundberg <emil@emlun.se> | 2019-01-13 02:27:33 +0100 |
commit | bf43cb7cc4280bc9be67f1d1ac018c6d27d4cd39 (patch) | |
tree | 93e31919a4993027cac04d2816b2270ececa45c8 /src/core | |
parent | 0ef178137759f0a780e3e3f6ea141ee073d96826 (diff) | |
download | lombok-bf43cb7cc4280bc9be67f1d1ac018c6d27d4cd39.tar.gz lombok-bf43cb7cc4280bc9be67f1d1ac018c6d27d4cd39.tar.bz2 lombok-bf43cb7cc4280bc9be67f1d1ac018c6d27d4cd39.zip |
Extract method generatePluralMethodStatements
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/lombok/javac/handlers/JavacSingularsRecipes.java | 12 | ||||
-rw-r--r-- | src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java | 5 |
2 files changed, 10 insertions, 7 deletions
diff --git a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java index 62513bc1..96694fa4 100644 --- a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java +++ b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java @@ -294,17 +294,21 @@ public class JavacSingularsRecipes { protected abstract List<JCVariableDecl> generateSingularMethodParameters(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source); - protected void generatePluralMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) { + void generatePluralMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) { + ListBuffer<JCStatement> statements = generatePluralMethodStatements(maker, data, builderType, source); + finishAndInjectPluralMethod(deprecate, maker, returnType, returnStatement, data, builderType, source, fluent, statements); + } + + protected ListBuffer<JCStatement> generatePluralMethodStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) { ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>(); statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, source)); JCExpression thisDotFieldDotAdd = chainDots(builderType, "this", data.getPluralName().toString(), getAddMethodName() + "All"); JCExpression invokeAdd = maker.Apply(List.<JCExpression>nil(), thisDotFieldDotAdd, List.<JCExpression>of(maker.Ident(data.getPluralName()))); statements.append(maker.Exec(invokeAdd)); - - finishAndInjectPluralMethod(deprecate, maker, returnType, returnStatement, data, builderType, source, fluent, statements); + return statements; } - protected void finishAndInjectPluralMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent, ListBuffer<JCStatement> statements) { + void finishAndInjectPluralMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent, ListBuffer<JCStatement> statements) { if (returnStatement != null) statements.append(returnStatement); JCBlock body = maker.Block(0, statements.toList()); Name name = data.getPluralName(); diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java index d37dd445..c2010e0c 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java @@ -147,7 +147,7 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { } @Override - protected void generatePluralMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) { + protected ListBuffer<JCStatement> generatePluralMethodStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) { List<JCExpression> jceBlank = List.nil(); ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>(); statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, source)); @@ -164,8 +164,7 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { JCExpression entrySetInvocation = maker.Apply(jceBlank, maker.Select(maker.Ident(data.getPluralName()), builderType.toName("entrySet")), jceBlank); JCStatement forEach = maker.ForeachLoop(maker.VarDef(maker.Modifiers(baseFlags), entryName, forEachType, null), entrySetInvocation, forEachBody); statements.append(forEach); - - finishAndInjectPluralMethod(deprecate, maker, returnType, returnStatement, data, builderType, source, fluent, statements); + return statements; } @Override |