From c336e6ff21636b77f8b23ef9c7b64dc94a985248 Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Thu, 10 Jan 2019 01:21:20 +0100 Subject: Extract abstract method JavacSingularizer.generateSingularMethod --- src/core/lombok/javac/handlers/JavacSingularsRecipes.java | 4 +++- src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java | 5 +++-- .../javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java | 5 +++-- .../javac/handlers/singulars/JavacJavaUtilMapSingularizer.java | 3 ++- 4 files changed, 11 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java index ab8c3a42..19b424cc 100644 --- a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java +++ b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java @@ -230,7 +230,9 @@ public class JavacSingularsRecipes { * Uses the given {@code returnTypeMaker} and {@code returnStatementMaker} for the generated methods. */ public abstract void generateMethods(SingularData data, boolean deprecate, JavacNode builderType, JCTree source, boolean fluent, ExpressionMaker returnTypeMaker, StatementMaker returnStatementMaker); - + + protected abstract void generateSingularMethod(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 statements, Name targetVariableName, String builderVariable); public boolean requiresCleaning() { diff --git a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java index c5d1b078..a701813b 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java @@ -95,8 +95,9 @@ abstract class JavacGuavaSingularizer extends JavacSingularizer { recursiveSetGeneratedBy(method, source, builderType.getContext()); injectMethod(builderType, method); } - - void generateSingularMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) { + + @Override + protected void generateSingularMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) { List typeParams = List.nil(); List thrown = List.nil(); diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java index 96928a4c..74b6ae97 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java @@ -110,8 +110,9 @@ abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularize recursiveSetGeneratedBy(method, source, builderType.getContext()); injectMethod(builderType, method); } - - void generateSingularMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) { + + @Override + protected void generateSingularMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) { List typeParams = List.nil(); List thrown = List.nil(); JCModifiers mods = makeMods(maker, builderType, deprecate); diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java index f829eedb..1a25f7e2 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java @@ -140,7 +140,8 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { injectMethod(builderType, method); } - private void generateSingularMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) { + @Override + protected void generateSingularMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) { List typeParams = List.nil(); List thrown = List.nil(); JCModifiers mods = makeMods(maker, builderType, deprecate); -- cgit From d57638b36e8013ff30bfe81cbf208aecdd4490aa Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Thu, 10 Jan 2019 01:24:30 +0100 Subject: Extract abstract method JavacSingularizer.generateClearMethod --- src/core/lombok/javac/handlers/JavacSingularsRecipes.java | 2 ++ src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java | 3 ++- .../javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java | 5 +++-- .../javac/handlers/singulars/JavacJavaUtilMapSingularizer.java | 5 +++-- 4 files changed, 10 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java index 19b424cc..69f023cf 100644 --- a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java +++ b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java @@ -231,6 +231,8 @@ public class JavacSingularsRecipes { */ public abstract void generateMethods(SingularData data, boolean deprecate, JavacNode builderType, JCTree source, boolean fluent, ExpressionMaker returnTypeMaker, StatementMaker returnStatementMaker); + protected abstract void generateClearMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source); + protected abstract void generateSingularMethod(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 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 a701813b..93b87a24 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java @@ -79,7 +79,8 @@ abstract class JavacGuavaSingularizer extends JavacSingularizer { generateClearMethod(deprecate, maker, returnTypeMaker.make(), returnStatementMaker.make(), data, builderType, source); } - private void generateClearMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source) { + @Override + protected void generateClearMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source) { JCModifiers mods = makeMods(maker, builderType, deprecate); List typeParams = List.nil(); List thrown = List.nil(); diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java index 74b6ae97..0d72ef7f 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java @@ -89,8 +89,9 @@ abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularize generatePluralMethod(deprecate, maker, returnTypeMaker.make(), returnStatementMaker.make(), data, builderType, source, fluent); generateClearMethod(deprecate, maker, returnTypeMaker.make(), returnStatementMaker.make(), data, builderType, source); } - - private void generateClearMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source) { + + @Override + protected void generateClearMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source) { JCModifiers mods = makeMods(maker, builderType, deprecate); List typeParams = List.nil(); List thrown = List.nil(); diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java index 1a25f7e2..862c24d8 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java @@ -114,8 +114,9 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { generatePluralMethod(deprecate, maker, returnTypeMaker.make(), returnStatementMaker.make(), data, builderType, source, fluent); generateClearMethod(deprecate, maker, returnTypeMaker.make(), returnStatementMaker.make(), data, builderType, source); } - - private void generateClearMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source) { + + @Override + protected void generateClearMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source) { JCModifiers mods = makeMods(maker, builderType, deprecate); List typeParams = List.nil(); -- cgit From c37b43690fbfe59382445ab994a2b6b31be6a015 Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Thu, 10 Jan 2019 01:25:14 +0100 Subject: Extract abstract method JavacSingularizer.generatePluralMethod --- src/core/lombok/javac/handlers/JavacSingularsRecipes.java | 2 ++ src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java | 1 + .../javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java | 5 +++-- .../javac/handlers/singulars/JavacJavaUtilMapSingularizer.java | 3 ++- 4 files changed, 8 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java index 69f023cf..e5164bdd 100644 --- a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java +++ b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java @@ -235,6 +235,8 @@ public class JavacSingularsRecipes { protected abstract void generateSingularMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent); + 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 statements, Name targetVariableName, String builderVariable); public boolean requiresCleaning() { diff --git a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java index 93b87a24..22b68259 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java @@ -141,6 +141,7 @@ abstract class JavacGuavaSingularizer extends JavacSingularizer { injectMethod(builderType, method); } + @Override protected void generatePluralMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) { List typeParams = List.nil(); List thrown = List.nil(); diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java index 0d72ef7f..a52d478c 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java @@ -136,8 +136,9 @@ abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularize recursiveSetGeneratedBy(method, source, builderType.getContext()); injectMethod(builderType, method); } - - void generatePluralMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) { + + @Override + protected void generatePluralMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) { List typeParams = List.nil(); List thrown = List.nil(); JCModifiers mods = makeMods(maker, builderType, deprecate); diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java index 862c24d8..140dab3b 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java @@ -182,7 +182,8 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { injectMethod(builderType, method); } - private void generatePluralMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) { + @Override + protected void generatePluralMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) { List typeParams = List.nil(); List jceBlank = List.nil(); JCModifiers mods = makeMods(maker, builderType, deprecate); -- cgit From a8a78880331db06122a4432009eb03d6833371b5 Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Thu, 10 Jan 2019 01:28:33 +0100 Subject: Extract method JavacSingularsRecipes.doGenerateMethods --- src/core/lombok/javac/handlers/JavacSingularsRecipes.java | 7 +++++++ .../lombok/javac/handlers/singulars/JavacGuavaSingularizer.java | 5 +---- .../javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java | 7 ++----- .../javac/handlers/singulars/JavacJavaUtilMapSingularizer.java | 7 ++----- 4 files changed, 12 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java index e5164bdd..5ef01edc 100644 --- a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java +++ b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java @@ -231,6 +231,13 @@ public class JavacSingularsRecipes { */ public abstract void generateMethods(SingularData data, boolean deprecate, JavacNode builderType, JCTree source, boolean fluent, ExpressionMaker returnTypeMaker, StatementMaker returnStatementMaker); + protected void doGenerateMethods(SingularData data, boolean deprecate, JavacNode builderType, JCTree source, boolean fluent, ExpressionMaker returnTypeMaker, StatementMaker returnStatementMaker) { + JavacTreeMaker maker = builderType.getTreeMaker(); + generateSingularMethod(deprecate, maker, returnTypeMaker.make(), returnStatementMaker.make(), data, builderType, source, fluent); + generatePluralMethod(deprecate, maker, returnTypeMaker.make(), returnStatementMaker.make(), data, builderType, source, fluent); + generateClearMethod(deprecate, maker, returnTypeMaker.make(), returnStatementMaker.make(), data, builderType, source); + } + protected abstract void generateClearMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source); protected abstract void generateSingularMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent); diff --git a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java index 22b68259..38783e95 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java @@ -73,10 +73,7 @@ abstract class JavacGuavaSingularizer extends JavacSingularizer { } @Override public void generateMethods(SingularData data, boolean deprecate, JavacNode builderType, JCTree source, boolean fluent, ExpressionMaker returnTypeMaker, StatementMaker returnStatementMaker) { - JavacTreeMaker maker = builderType.getTreeMaker(); - generateSingularMethod(deprecate, maker, returnTypeMaker.make(), returnStatementMaker.make(), data, builderType, source, fluent); - generatePluralMethod(deprecate, maker, returnTypeMaker.make(), returnStatementMaker.make(), data, builderType, source, fluent); - generateClearMethod(deprecate, maker, returnTypeMaker.make(), returnStatementMaker.make(), data, builderType, source); + doGenerateMethods(data, deprecate, builderType, source, fluent, returnTypeMaker, returnStatementMaker); } @Override diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java index a52d478c..fbd0bc7b 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java @@ -83,11 +83,8 @@ abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularize guavaListSetSingularizer.generateMethods(data, deprecate, builderType, source, fluent, returnTypeMaker, returnStatementMaker); return; } - - JavacTreeMaker maker = builderType.getTreeMaker(); - generateSingularMethod(deprecate, maker, returnTypeMaker.make(), returnStatementMaker.make(), data, builderType, source, fluent); - generatePluralMethod(deprecate, maker, returnTypeMaker.make(), returnStatementMaker.make(), data, builderType, source, fluent); - generateClearMethod(deprecate, maker, returnTypeMaker.make(), returnStatementMaker.make(), data, builderType, source); + + doGenerateMethods(data, deprecate, builderType, source, fluent, returnTypeMaker, returnStatementMaker); } @Override diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java index 140dab3b..e4f189ad 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java @@ -108,11 +108,8 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { guavaMapSingularizer.generateMethods(data, deprecate, builderType, source, fluent, returnTypeMaker, returnStatementMaker); return; } - - JavacTreeMaker maker = builderType.getTreeMaker(); - generateSingularMethod(deprecate, maker, returnTypeMaker.make(), returnStatementMaker.make(), data, builderType, source, fluent); - generatePluralMethod(deprecate, maker, returnTypeMaker.make(), returnStatementMaker.make(), data, builderType, source, fluent); - generateClearMethod(deprecate, maker, returnTypeMaker.make(), returnStatementMaker.make(), data, builderType, source); + + doGenerateMethods(data, deprecate, builderType, source, fluent, returnTypeMaker, returnStatementMaker); } @Override -- cgit From 5c99e5b9a01e434644e9589d018360d3815332e6 Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Thu, 10 Jan 2019 01:42:16 +0100 Subject: Extract method JavacSingularizer.finishGenerateClearMethod --- src/core/lombok/javac/handlers/JavacSingularsRecipes.java | 11 +++++++++++ .../javac/handlers/singulars/JavacGuavaSingularizer.java | 8 ++------ .../handlers/singulars/JavacJavaUtilListSetSingularizer.java | 8 ++------ .../handlers/singulars/JavacJavaUtilMapSingularizer.java | 8 ++------ 4 files changed, 17 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java index 5ef01edc..cab6dd20 100644 --- a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java +++ b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java @@ -24,6 +24,8 @@ package lombok.javac.handlers; import static lombok.javac.Javac.*; import static lombok.javac.handlers.JavacHandlerUtil.*; +import com.sun.tools.javac.tree.JCTree.JCBlock; +import com.sun.tools.javac.tree.JCTree.JCTypeParameter; import java.io.IOException; import java.util.Arrays; import java.util.Collections; @@ -33,6 +35,7 @@ import java.util.Map; import lombok.core.LombokImmutableList; import lombok.core.SpiLoadUtil; import lombok.core.TypeLibrary; +import lombok.core.handlers.HandlerUtil; import lombok.javac.JavacNode; import lombok.javac.JavacTreeMaker; @@ -240,6 +243,14 @@ public class JavacSingularsRecipes { protected abstract void generateClearMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source); + protected void finishGenerateClearMethod(JavacTreeMaker maker, JCExpression returnType, SingularData data, JavacNode builderType, JCTree source, JCModifiers mods, List typeParams, List thrown, List params, List statements) { + JCBlock body = maker.Block(0, statements); + Name methodName = builderType.toName(HandlerUtil.buildAccessorName("clear", data.getPluralName().toString())); + JCMethodDecl method = maker.MethodDef(mods, methodName, returnType, typeParams, params, thrown, body, null); + recursiveSetGeneratedBy(method, source, builderType.getContext()); + injectMethod(builderType, method); + } + protected abstract void generateSingularMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent); protected abstract void generatePluralMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent); diff --git a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java index 38783e95..ad972e8b 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java @@ -86,12 +86,8 @@ abstract class JavacGuavaSingularizer extends JavacSingularizer { JCExpression thisDotField = maker.Select(maker.Ident(builderType.toName("this")), data.getPluralName()); JCStatement clearField = maker.Exec(maker.Assign(thisDotField, maker.Literal(CTC_BOT, null))); List statements = returnStatement != null ? List.of(clearField, returnStatement) : List.of(clearField); - - JCBlock body = maker.Block(0, statements); - Name methodName = builderType.toName(HandlerUtil.buildAccessorName("clear", data.getPluralName().toString())); - JCMethodDecl method = maker.MethodDef(mods, methodName, returnType, typeParams, params, thrown, body, null); - recursiveSetGeneratedBy(method, source, builderType.getContext()); - injectMethod(builderType, method); + + finishGenerateClearMethod(maker, returnType, data, builderType, source, mods, typeParams, thrown, params, statements); } @Override diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java index fbd0bc7b..d84e5946 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java @@ -101,12 +101,8 @@ abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularize JCExpression cond = maker.Binary(CTC_NOT_EQUAL, thisDotField, maker.Literal(CTC_BOT, null)); JCStatement ifSetCallClear = maker.If(cond, clearCall, null); List statements = returnStatement != null ? List.of(ifSetCallClear, returnStatement) : List.of(ifSetCallClear); - - JCBlock body = maker.Block(0, statements); - Name methodName = builderType.toName(HandlerUtil.buildAccessorName("clear", data.getPluralName().toString())); - JCMethodDecl method = maker.MethodDef(mods, methodName, returnType, typeParams, params, thrown, body, null); - recursiveSetGeneratedBy(method, source, builderType.getContext()); - injectMethod(builderType, method); + + finishGenerateClearMethod(maker, returnType, data, builderType, source, mods, typeParams, thrown, params, statements); } @Override diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java index e4f189ad..0e6a794a 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java @@ -130,12 +130,8 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { JCBlock clearCalls = maker.Block(0, List.of(clearKeyCall, clearValueCall)); JCStatement ifSetCallClear = maker.If(cond, clearCalls, null); List statements = returnStatement != null ? List.of(ifSetCallClear, returnStatement) : List.of(ifSetCallClear); - - JCBlock body = maker.Block(0, statements); - Name methodName = builderType.toName(HandlerUtil.buildAccessorName("clear", data.getPluralName().toString())); - JCMethodDecl method = maker.MethodDef(mods, methodName, returnType, typeParams, params, thrown, body, null); - recursiveSetGeneratedBy(method, source, builderType.getContext()); - injectMethod(builderType, method); + + finishGenerateClearMethod(maker, returnType, data, builderType, source, mods, typeParams, thrown, params, statements); } @Override -- cgit From 05ce5e050ea15a7feb26ba2ef6f3cda9b54c8498 Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Thu, 10 Jan 2019 01:48:35 +0100 Subject: Extract abstract method JavacSingularizer.generateClearStatements --- src/core/lombok/javac/handlers/JavacSingularsRecipes.java | 2 ++ .../javac/handlers/singulars/JavacGuavaSingularizer.java | 14 ++++++++++---- .../singulars/JavacJavaUtilListSetSingularizer.java | 15 +++++++++++---- .../handlers/singulars/JavacJavaUtilMapSingularizer.java | 12 +++++++++--- 4 files changed, 32 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java index cab6dd20..1d4d5a8d 100644 --- a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java +++ b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java @@ -251,6 +251,8 @@ public class JavacSingularsRecipes { injectMethod(builderType, method); } + protected abstract List generateClearStatements(JavacTreeMaker maker, JCStatement returnStatement, SingularData data, JavacNode builderType); + protected abstract void generateSingularMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent); protected abstract void generatePluralMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent); diff --git a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java index ad972e8b..13a48869 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java @@ -82,14 +82,20 @@ abstract class JavacGuavaSingularizer extends JavacSingularizer { List typeParams = List.nil(); List thrown = List.nil(); List params = List.nil(); - - JCExpression thisDotField = maker.Select(maker.Ident(builderType.toName("this")), data.getPluralName()); - JCStatement clearField = maker.Exec(maker.Assign(thisDotField, maker.Literal(CTC_BOT, null))); - List statements = returnStatement != null ? List.of(clearField, returnStatement) : List.of(clearField); + + List statements = generateClearStatements(maker, returnStatement, data, builderType); finishGenerateClearMethod(maker, returnType, data, builderType, source, mods, typeParams, thrown, params, statements); } + @Override + protected List generateClearStatements(JavacTreeMaker maker, JCStatement returnStatement, SingularData data, JavacNode builderType) { + JCExpression thisDotField = maker.Select(maker.Ident(builderType.toName("this")), data.getPluralName()); + + JCStatement clearField = maker.Exec(maker.Assign(thisDotField, maker.Literal(CTC_BOT, null))); + return returnStatement != null ? List.of(clearField, returnStatement) : List.of(clearField); + } + @Override protected void generateSingularMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) { List typeParams = List.nil(); diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java index d84e5946..f332aad1 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java @@ -93,16 +93,23 @@ abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularize List typeParams = List.nil(); List thrown = List.nil(); List params = List.nil(); + + List statements = generateClearStatements(maker, returnStatement, data, builderType); + + finishGenerateClearMethod(maker, returnType, data, builderType, source, mods, typeParams, thrown, params, statements); + } + + @Override + protected List generateClearStatements(JavacTreeMaker maker, JCStatement returnStatement, SingularData data, JavacNode builderType) { List jceBlank = List.nil(); - JCExpression thisDotField = maker.Select(maker.Ident(builderType.toName("this")), data.getPluralName()); JCExpression thisDotFieldDotClear = maker.Select(maker.Select(maker.Ident(builderType.toName("this")), data.getPluralName()), builderType.toName("clear")); + JCStatement clearCall = maker.Exec(maker.Apply(jceBlank, thisDotFieldDotClear, jceBlank)); JCExpression cond = maker.Binary(CTC_NOT_EQUAL, thisDotField, maker.Literal(CTC_BOT, null)); - JCStatement ifSetCallClear = maker.If(cond, clearCall, null); - List statements = returnStatement != null ? List.of(ifSetCallClear, returnStatement) : List.of(ifSetCallClear); - finishGenerateClearMethod(maker, returnType, data, builderType, source, mods, typeParams, thrown, params, statements); + JCStatement ifSetCallClear = maker.If(cond, clearCall, null); + return returnStatement != null ? List.of(ifSetCallClear, returnStatement) : List.of(ifSetCallClear); } @Override diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java index 0e6a794a..dab09eb3 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java @@ -119,6 +119,14 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { List typeParams = List.nil(); List thrown = List.nil(); List params = List.nil(); + + List statements = generateClearStatements(maker, returnStatement, data, builderType); + + finishGenerateClearMethod(maker, returnType, data, builderType, source, mods, typeParams, thrown, params, statements); + } + + @Override + protected List generateClearStatements(JavacTreeMaker maker, JCStatement returnStatement, SingularData data, JavacNode builderType) { List jceBlank = List.nil(); JCExpression thisDotKeyField = chainDots(builderType, "this", data.getPluralName() + "$key"); @@ -129,9 +137,7 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { JCExpression cond = maker.Binary(CTC_NOT_EQUAL, thisDotKeyField, maker.Literal(CTC_BOT, null)); JCBlock clearCalls = maker.Block(0, List.of(clearKeyCall, clearValueCall)); JCStatement ifSetCallClear = maker.If(cond, clearCalls, null); - List statements = returnStatement != null ? List.of(ifSetCallClear, returnStatement) : List.of(ifSetCallClear); - - finishGenerateClearMethod(maker, returnType, data, builderType, source, mods, typeParams, thrown, params, statements); + return returnStatement != null ? List.of(ifSetCallClear, returnStatement) : List.of(ifSetCallClear); } @Override -- cgit From d08aa5a83d2302eaaf84c4323073dfe3edd43703 Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Thu, 10 Jan 2019 01:51:47 +0100 Subject: Pull generateClearMethod up to JavacSingularizer --- src/core/lombok/javac/handlers/JavacSingularsRecipes.java | 10 ++++++++-- .../javac/handlers/singulars/JavacGuavaSingularizer.java | 12 ------------ .../singulars/JavacJavaUtilListSetSingularizer.java | 12 ------------ .../handlers/singulars/JavacJavaUtilMapSingularizer.java | 13 ------------- 4 files changed, 8 insertions(+), 39 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java index 1d4d5a8d..765d7e43 100644 --- a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java +++ b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java @@ -241,9 +241,15 @@ public class JavacSingularsRecipes { generateClearMethod(deprecate, maker, returnTypeMaker.make(), returnStatementMaker.make(), data, builderType, source); } - protected abstract void generateClearMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source); + protected void generateClearMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source) { + JCModifiers mods = makeMods(maker, builderType, deprecate); + + List typeParams = List.nil(); + List thrown = List.nil(); + List params = List.nil(); + + List statements = generateClearStatements(maker, returnStatement, data, builderType); - protected void finishGenerateClearMethod(JavacTreeMaker maker, JCExpression returnType, SingularData data, JavacNode builderType, JCTree source, JCModifiers mods, List typeParams, List thrown, List params, List statements) { JCBlock body = maker.Block(0, statements); Name methodName = builderType.toName(HandlerUtil.buildAccessorName("clear", data.getPluralName().toString())); JCMethodDecl method = maker.MethodDef(mods, methodName, returnType, typeParams, params, thrown, body, null); diff --git a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java index 13a48869..d6796d51 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java @@ -76,18 +76,6 @@ abstract class JavacGuavaSingularizer extends JavacSingularizer { doGenerateMethods(data, deprecate, builderType, source, fluent, returnTypeMaker, returnStatementMaker); } - @Override - protected void generateClearMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source) { - JCModifiers mods = makeMods(maker, builderType, deprecate); - List typeParams = List.nil(); - List thrown = List.nil(); - List params = List.nil(); - - List statements = generateClearStatements(maker, returnStatement, data, builderType); - - finishGenerateClearMethod(maker, returnType, data, builderType, source, mods, typeParams, thrown, params, statements); - } - @Override protected List generateClearStatements(JavacTreeMaker maker, JCStatement returnStatement, SingularData data, JavacNode builderType) { JCExpression thisDotField = maker.Select(maker.Ident(builderType.toName("this")), data.getPluralName()); diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java index f332aad1..9ecdbbaf 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java @@ -87,18 +87,6 @@ abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularize doGenerateMethods(data, deprecate, builderType, source, fluent, returnTypeMaker, returnStatementMaker); } - @Override - protected void generateClearMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source) { - JCModifiers mods = makeMods(maker, builderType, deprecate); - List typeParams = List.nil(); - List thrown = List.nil(); - List params = List.nil(); - - List statements = generateClearStatements(maker, returnStatement, data, builderType); - - finishGenerateClearMethod(maker, returnType, data, builderType, source, mods, typeParams, thrown, params, statements); - } - @Override protected List generateClearStatements(JavacTreeMaker maker, JCStatement returnStatement, SingularData data, JavacNode builderType) { List jceBlank = List.nil(); diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java index dab09eb3..ecd01aa3 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java @@ -112,19 +112,6 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { doGenerateMethods(data, deprecate, builderType, source, fluent, returnTypeMaker, returnStatementMaker); } - @Override - protected void generateClearMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source) { - JCModifiers mods = makeMods(maker, builderType, deprecate); - - List typeParams = List.nil(); - List thrown = List.nil(); - List params = List.nil(); - - List statements = generateClearStatements(maker, returnStatement, data, builderType); - - finishGenerateClearMethod(maker, returnType, data, builderType, source, mods, typeParams, thrown, params, statements); - } - @Override protected List generateClearStatements(JavacTreeMaker maker, JCStatement returnStatement, SingularData data, JavacNode builderType) { List jceBlank = List.nil(); -- cgit From 62bb81311e58f6ec1108e94bc4f61bbf93eb411a Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Thu, 10 Jan 2019 02:04:15 +0100 Subject: Pull return statement wrapping up into generateClearMethod --- src/core/lombok/javac/handlers/JavacSingularsRecipes.java | 5 +++-- .../lombok/javac/handlers/singulars/JavacGuavaSingularizer.java | 6 ++---- .../javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java | 5 ++--- .../javac/handlers/singulars/JavacJavaUtilMapSingularizer.java | 5 ++--- 4 files changed, 9 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java index 765d7e43..eed21af4 100644 --- a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java +++ b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java @@ -248,7 +248,8 @@ public class JavacSingularsRecipes { List thrown = List.nil(); List params = List.nil(); - List statements = generateClearStatements(maker, returnStatement, data, builderType); + JCStatement clearStatement = generateClearStatements(maker, data, builderType); + List statements = returnStatement != null ? List.of(clearStatement, returnStatement) : List.of(clearStatement); JCBlock body = maker.Block(0, statements); Name methodName = builderType.toName(HandlerUtil.buildAccessorName("clear", data.getPluralName().toString())); @@ -257,7 +258,7 @@ public class JavacSingularsRecipes { injectMethod(builderType, method); } - protected abstract List generateClearStatements(JavacTreeMaker maker, JCStatement returnStatement, SingularData data, JavacNode builderType); + protected abstract JCStatement generateClearStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType); protected abstract void generateSingularMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent); diff --git a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java index d6796d51..6c60798d 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java @@ -77,11 +77,9 @@ abstract class JavacGuavaSingularizer extends JavacSingularizer { } @Override - protected List generateClearStatements(JavacTreeMaker maker, JCStatement returnStatement, SingularData data, JavacNode builderType) { + protected JCStatement generateClearStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType) { JCExpression thisDotField = maker.Select(maker.Ident(builderType.toName("this")), data.getPluralName()); - - JCStatement clearField = maker.Exec(maker.Assign(thisDotField, maker.Literal(CTC_BOT, null))); - return returnStatement != null ? List.of(clearField, returnStatement) : List.of(clearField); + return maker.Exec(maker.Assign(thisDotField, maker.Literal(CTC_BOT, null))); } @Override diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java index 9ecdbbaf..d07355c9 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java @@ -88,7 +88,7 @@ abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularize } @Override - protected List generateClearStatements(JavacTreeMaker maker, JCStatement returnStatement, SingularData data, JavacNode builderType) { + protected JCStatement generateClearStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType) { List jceBlank = List.nil(); JCExpression thisDotField = maker.Select(maker.Ident(builderType.toName("this")), data.getPluralName()); JCExpression thisDotFieldDotClear = maker.Select(maker.Select(maker.Ident(builderType.toName("this")), data.getPluralName()), builderType.toName("clear")); @@ -96,8 +96,7 @@ abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularize JCStatement clearCall = maker.Exec(maker.Apply(jceBlank, thisDotFieldDotClear, jceBlank)); JCExpression cond = maker.Binary(CTC_NOT_EQUAL, thisDotField, maker.Literal(CTC_BOT, null)); - JCStatement ifSetCallClear = maker.If(cond, clearCall, null); - return returnStatement != null ? List.of(ifSetCallClear, returnStatement) : List.of(ifSetCallClear); + return maker.If(cond, clearCall, null); } @Override diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java index ecd01aa3..fce0ccb9 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java @@ -113,7 +113,7 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { } @Override - protected List generateClearStatements(JavacTreeMaker maker, JCStatement returnStatement, SingularData data, JavacNode builderType) { + protected JCStatement generateClearStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType) { List jceBlank = List.nil(); JCExpression thisDotKeyField = chainDots(builderType, "this", data.getPluralName() + "$key"); @@ -123,8 +123,7 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { JCStatement clearValueCall = maker.Exec(maker.Apply(jceBlank, thisDotValueFieldDotClear, jceBlank)); JCExpression cond = maker.Binary(CTC_NOT_EQUAL, thisDotKeyField, maker.Literal(CTC_BOT, null)); JCBlock clearCalls = maker.Block(0, List.of(clearKeyCall, clearValueCall)); - JCStatement ifSetCallClear = maker.If(cond, clearCalls, null); - return returnStatement != null ? List.of(ifSetCallClear, returnStatement) : List.of(ifSetCallClear); + return maker.If(cond, clearCalls, null); } @Override -- cgit From 3c9324e801b6192717c1e9b78e4d762c9e4ef57f Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Thu, 10 Jan 2019 02:33:51 +0100 Subject: Extract method finishAndInjectMethod --- src/core/lombok/javac/handlers/JavacSingularsRecipes.java | 10 +++++++--- .../javac/handlers/singulars/JavacGuavaSingularizer.java | 13 ++++--------- .../singulars/JavacJavaUtilListSetSingularizer.java | 9 ++------- .../handlers/singulars/JavacJavaUtilMapSingularizer.java | 9 ++------- 4 files changed, 15 insertions(+), 26 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java index eed21af4..602e926c 100644 --- a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java +++ b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java @@ -241,6 +241,12 @@ public class JavacSingularsRecipes { generateClearMethod(deprecate, maker, returnTypeMaker.make(), returnStatementMaker.make(), data, builderType, source); } + protected void finishAndInjectMethod(JavacTreeMaker maker, JCExpression returnType, JavacNode builderType, JCTree source, List typeParams, List thrown, JCModifiers mods, JCBlock body, Name methodName, List jcVariableDecls) { + JCMethodDecl method = maker.MethodDef(mods, methodName, returnType, typeParams, jcVariableDecls, thrown, body, null); + recursiveSetGeneratedBy(method, source, builderType.getContext()); + injectMethod(builderType, method); + } + protected void generateClearMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source) { JCModifiers mods = makeMods(maker, builderType, deprecate); @@ -253,9 +259,7 @@ public class JavacSingularsRecipes { JCBlock body = maker.Block(0, statements); Name methodName = builderType.toName(HandlerUtil.buildAccessorName("clear", data.getPluralName().toString())); - JCMethodDecl method = maker.MethodDef(mods, methodName, returnType, typeParams, params, thrown, body, null); - recursiveSetGeneratedBy(method, source, builderType.getContext()); - injectMethod(builderType, method); + finishAndInjectMethod(maker, returnType, builderType, source, typeParams, thrown, mods, body, methodName, params); } protected abstract JCStatement generateClearStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType); diff --git a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java index 6c60798d..de5585b3 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java @@ -42,7 +42,6 @@ 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.JCMethodDecl; import com.sun.tools.javac.tree.JCTree.JCModifiers; import com.sun.tools.javac.tree.JCTree.JCStatement; import com.sun.tools.javac.tree.JCTree.JCTypeParameter; @@ -120,10 +119,8 @@ abstract class JavacGuavaSingularizer extends JavacSingularizer { JCVariableDecl p = maker.VarDef(paramMods, names[i], pt, null); params.append(p); } - - JCMethodDecl method = maker.MethodDef(mods, methodName, returnType, typeParams, params.toList(), thrown, body, null); - recursiveSetGeneratedBy(method, source, builderType.getContext()); - injectMethod(builderType, method); + + finishAndInjectMethod(maker, returnType, builderType, source, typeParams, thrown, mods, body, methodName, params.toList()); } @Override @@ -150,10 +147,8 @@ abstract class JavacGuavaSingularizer extends JavacSingularizer { } paramType = addTypeArgs(getTypeArgumentsCount(), true, builderType, paramType, data.getTypeArgs(), source); JCVariableDecl param = maker.VarDef(maker.Modifiers(paramFlags), data.getPluralName(), paramType, null); - JCMethodDecl method = maker.MethodDef(mods, methodName, returnType, typeParams, List.of(param), thrown, body, null); - recursiveSetGeneratedBy(method, source, builderType.getContext()); - injectMethod(builderType, method); - } + finishAndInjectMethod(maker, returnType, builderType, source, typeParams, thrown, mods, body, methodName, List.of(param)); + } @Override public void appendBuildCode(SingularData data, JavacNode builderType, JCTree source, ListBuffer statements, Name targetVariableName, String builderVariable) { JavacTreeMaker maker = builderType.getTreeMaker(); diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java index d07355c9..e90198c0 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java @@ -39,7 +39,6 @@ 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.JCMethodDecl; import com.sun.tools.javac.tree.JCTree.JCModifiers; import com.sun.tools.javac.tree.JCTree.JCStatement; import com.sun.tools.javac.tree.JCTree.JCTypeParameter; @@ -119,9 +118,7 @@ abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularize paramType = removeTypeUseAnnotations(paramType); JCModifiers paramMods = typeUseAnns.isEmpty() ? maker.Modifiers(paramFlags) : maker.Modifiers(paramFlags, typeUseAnns); JCVariableDecl param = maker.VarDef(paramMods, data.getSingularName(), paramType, null); - JCMethodDecl method = maker.MethodDef(mods, name, returnType, typeParams, List.of(param), thrown, body, null); - recursiveSetGeneratedBy(method, source, builderType.getContext()); - injectMethod(builderType, method); + finishAndInjectMethod(maker, returnType, builderType, source, typeParams, thrown, mods, body, name, List.of(param)); } @Override @@ -142,8 +139,6 @@ abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularize JCExpression paramType = chainDots(builderType, "java", "util", "Collection"); paramType = addTypeArgs(1, true, builderType, paramType, data.getTypeArgs(), source); JCVariableDecl param = maker.VarDef(maker.Modifiers(paramFlags), data.getPluralName(), paramType, null); - JCMethodDecl method = maker.MethodDef(mods, name, returnType, typeParams, List.of(param), thrown, body, null); - recursiveSetGeneratedBy(method, source, builderType.getContext()); - injectMethod(builderType, method); + finishAndInjectMethod(maker, returnType, builderType, source, typeParams, thrown, mods, body, name, List.of(param)); } } diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java index fce0ccb9..9a6a8f89 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java @@ -43,7 +43,6 @@ 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.JCMethodDecl; import com.sun.tools.javac.tree.JCTree.JCModifiers; import com.sun.tools.javac.tree.JCTree.JCStatement; import com.sun.tools.javac.tree.JCTree.JCTypeParameter; @@ -162,9 +161,7 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { JCModifiers paramModsValue = typeUseAnnsValue.isEmpty() ? maker.Modifiers(paramFlags) : maker.Modifiers(paramFlags, typeUseAnnsValue); JCVariableDecl paramKey = maker.VarDef(paramModsKey, keyName, paramTypeKey, null); JCVariableDecl paramValue = maker.VarDef(paramModsValue, valueName, paramTypeValue, null); - JCMethodDecl method = maker.MethodDef(mods, name, returnType, typeParams, List.of(paramKey, paramValue), thrown, body, null); - recursiveSetGeneratedBy(method, source, builderType.getContext()); - injectMethod(builderType, method); + finishAndInjectMethod(maker, returnType, builderType, source, typeParams, thrown, mods, body, name, List.of(paramKey, paramValue)); } @Override @@ -196,9 +193,7 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { JCExpression paramType = chainDots(builderType, "java", "util", "Map"); paramType = addTypeArgs(2, true, builderType, paramType, data.getTypeArgs(), source); JCVariableDecl param = maker.VarDef(maker.Modifiers(paramFlags), data.getPluralName(), paramType, null); - JCMethodDecl method = maker.MethodDef(mods, name, returnType, typeParams, List.of(param), jceBlank, body, null); - recursiveSetGeneratedBy(method, source, builderType.getContext()); - injectMethod(builderType, method); + finishAndInjectMethod(maker, returnType, builderType, source, typeParams, jceBlank, mods, body, name, List.of(param)); } @Override public void appendBuildCode(SingularData data, JavacNode builderType, JCTree source, ListBuffer statements, Name targetVariableName, String builderVariable) { -- cgit From bb7b5cce75988b0d774152a6f4d7b56ac1ab3953 Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Thu, 10 Jan 2019 02:34:20 +0100 Subject: Move one-use variable declarations to just before use --- src/core/lombok/javac/handlers/JavacSingularsRecipes.java | 4 ++-- .../lombok/javac/handlers/singulars/JavacGuavaSingularizer.java | 9 ++++----- .../handlers/singulars/JavacJavaUtilListSetSingularizer.java | 8 ++++---- .../javac/handlers/singulars/JavacJavaUtilMapSingularizer.java | 6 +++--- 4 files changed, 13 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java index 602e926c..6391c66c 100644 --- a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java +++ b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java @@ -250,8 +250,6 @@ public class JavacSingularsRecipes { protected void generateClearMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source) { JCModifiers mods = makeMods(maker, builderType, deprecate); - List typeParams = List.nil(); - List thrown = List.nil(); List params = List.nil(); JCStatement clearStatement = generateClearStatements(maker, data, builderType); @@ -259,6 +257,8 @@ public class JavacSingularsRecipes { JCBlock body = maker.Block(0, statements); Name methodName = builderType.toName(HandlerUtil.buildAccessorName("clear", data.getPluralName().toString())); + List typeParams = List.nil(); + List thrown = List.nil(); finishAndInjectMethod(maker, returnType, builderType, source, typeParams, thrown, mods, body, methodName, params); } diff --git a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java index de5585b3..9141482f 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java @@ -83,9 +83,6 @@ 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) { - List typeParams = List.nil(); - List thrown = List.nil(); - LombokImmutableList suffixes = getArgumentSuffixes(); Name[] names = new Name[suffixes.size()]; for (int i = 0; i < suffixes.size(); i++) { @@ -120,13 +117,13 @@ abstract class JavacGuavaSingularizer extends JavacSingularizer { params.append(p); } + List typeParams = List.nil(); + List thrown = List.nil(); finishAndInjectMethod(maker, returnType, builderType, source, typeParams, thrown, mods, body, methodName, params.toList()); } @Override protected void generatePluralMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) { - List typeParams = List.nil(); - List thrown = List.nil(); JCModifiers mods = makeMods(maker, builderType, deprecate); ListBuffer statements = new ListBuffer(); statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, source)); @@ -147,6 +144,8 @@ abstract class JavacGuavaSingularizer extends JavacSingularizer { } paramType = addTypeArgs(getTypeArgumentsCount(), true, builderType, paramType, data.getTypeArgs(), source); JCVariableDecl param = maker.VarDef(maker.Modifiers(paramFlags), data.getPluralName(), paramType, null); + List typeParams = List.nil(); + List thrown = List.nil(); finishAndInjectMethod(maker, returnType, builderType, source, typeParams, thrown, mods, body, methodName, List.of(param)); } diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java index e90198c0..ba73d392 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java @@ -100,8 +100,6 @@ 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) { - List typeParams = List.nil(); - List thrown = List.nil(); JCModifiers mods = makeMods(maker, builderType, deprecate); ListBuffer statements = new ListBuffer(); statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, false, source)); @@ -118,13 +116,13 @@ abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularize paramType = removeTypeUseAnnotations(paramType); JCModifiers paramMods = typeUseAnns.isEmpty() ? maker.Modifiers(paramFlags) : maker.Modifiers(paramFlags, typeUseAnns); JCVariableDecl param = maker.VarDef(paramMods, data.getSingularName(), paramType, null); + List typeParams = List.nil(); + List thrown = List.nil(); finishAndInjectMethod(maker, returnType, builderType, source, typeParams, thrown, mods, body, name, List.of(param)); } @Override protected void generatePluralMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) { - List typeParams = List.nil(); - List thrown = List.nil(); JCModifiers mods = makeMods(maker, builderType, deprecate); ListBuffer statements = new ListBuffer(); statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, false, source)); @@ -139,6 +137,8 @@ abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularize JCExpression paramType = chainDots(builderType, "java", "util", "Collection"); paramType = addTypeArgs(1, true, builderType, paramType, data.getTypeArgs(), source); JCVariableDecl param = maker.VarDef(maker.Modifiers(paramFlags), data.getPluralName(), paramType, null); + List typeParams = List.nil(); + List thrown = List.nil(); finishAndInjectMethod(maker, returnType, builderType, source, typeParams, thrown, mods, body, name, List.of(param)); } } diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java index 9a6a8f89..fe0db83e 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java @@ -127,8 +127,6 @@ 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) { - List typeParams = List.nil(); - List thrown = List.nil(); JCModifiers mods = makeMods(maker, builderType, deprecate); ListBuffer statements = new ListBuffer(); @@ -161,12 +159,13 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { JCModifiers paramModsValue = typeUseAnnsValue.isEmpty() ? maker.Modifiers(paramFlags) : maker.Modifiers(paramFlags, typeUseAnnsValue); JCVariableDecl paramKey = maker.VarDef(paramModsKey, keyName, paramTypeKey, null); JCVariableDecl paramValue = maker.VarDef(paramModsValue, valueName, paramTypeValue, null); + List typeParams = List.nil(); + List thrown = List.nil(); finishAndInjectMethod(maker, returnType, builderType, source, typeParams, thrown, mods, body, name, List.of(paramKey, paramValue)); } @Override protected void generatePluralMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) { - List typeParams = List.nil(); List jceBlank = List.nil(); JCModifiers mods = makeMods(maker, builderType, deprecate); ListBuffer statements = new ListBuffer(); @@ -193,6 +192,7 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { JCExpression paramType = chainDots(builderType, "java", "util", "Map"); paramType = addTypeArgs(2, true, builderType, paramType, data.getTypeArgs(), source); JCVariableDecl param = maker.VarDef(maker.Modifiers(paramFlags), data.getPluralName(), paramType, null); + List typeParams = List.nil(); finishAndInjectMethod(maker, returnType, builderType, source, typeParams, jceBlank, mods, body, name, List.of(param)); } -- cgit From 360c1d5a21273793ef5c96c21b979501bdebb5c3 Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Thu, 10 Jan 2019 02:35:30 +0100 Subject: Move invariant parameters inside finishAndInjectMethod --- src/core/lombok/javac/handlers/JavacSingularsRecipes.java | 8 ++++---- .../lombok/javac/handlers/singulars/JavacGuavaSingularizer.java | 8 ++------ .../handlers/singulars/JavacJavaUtilListSetSingularizer.java | 8 ++------ .../javac/handlers/singulars/JavacJavaUtilMapSingularizer.java | 7 ++----- 4 files changed, 10 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java index 6391c66c..9921ba89 100644 --- a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java +++ b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java @@ -241,7 +241,9 @@ public class JavacSingularsRecipes { generateClearMethod(deprecate, maker, returnTypeMaker.make(), returnStatementMaker.make(), data, builderType, source); } - protected void finishAndInjectMethod(JavacTreeMaker maker, JCExpression returnType, JavacNode builderType, JCTree source, List typeParams, List thrown, JCModifiers mods, JCBlock body, Name methodName, List jcVariableDecls) { + protected void finishAndInjectMethod(JavacTreeMaker maker, JCExpression returnType, JavacNode builderType, JCTree source, JCModifiers mods, JCBlock body, Name methodName, List jcVariableDecls) { + List typeParams = List.nil(); + List thrown = List.nil(); JCMethodDecl method = maker.MethodDef(mods, methodName, returnType, typeParams, jcVariableDecls, thrown, body, null); recursiveSetGeneratedBy(method, source, builderType.getContext()); injectMethod(builderType, method); @@ -257,9 +259,7 @@ public class JavacSingularsRecipes { JCBlock body = maker.Block(0, statements); Name methodName = builderType.toName(HandlerUtil.buildAccessorName("clear", data.getPluralName().toString())); - List typeParams = List.nil(); - List thrown = List.nil(); - finishAndInjectMethod(maker, returnType, builderType, source, typeParams, thrown, mods, body, methodName, params); + finishAndInjectMethod(maker, returnType, builderType, source, mods, body, methodName, params); } protected abstract JCStatement generateClearStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType); diff --git a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java index 9141482f..b514ebd5 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java @@ -117,9 +117,7 @@ abstract class JavacGuavaSingularizer extends JavacSingularizer { params.append(p); } - List typeParams = List.nil(); - List thrown = List.nil(); - finishAndInjectMethod(maker, returnType, builderType, source, typeParams, thrown, mods, body, methodName, params.toList()); + finishAndInjectMethod(maker, returnType, builderType, source, mods, body, methodName, params.toList()); } @Override @@ -144,9 +142,7 @@ abstract class JavacGuavaSingularizer extends JavacSingularizer { } paramType = addTypeArgs(getTypeArgumentsCount(), true, builderType, paramType, data.getTypeArgs(), source); JCVariableDecl param = maker.VarDef(maker.Modifiers(paramFlags), data.getPluralName(), paramType, null); - List typeParams = List.nil(); - List thrown = List.nil(); - finishAndInjectMethod(maker, returnType, builderType, source, typeParams, thrown, mods, body, methodName, List.of(param)); + finishAndInjectMethod(maker, returnType, builderType, source, mods, body, methodName, List.of(param)); } @Override public void appendBuildCode(SingularData data, JavacNode builderType, JCTree source, ListBuffer 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 ba73d392..1b661bb2 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java @@ -116,9 +116,7 @@ abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularize paramType = removeTypeUseAnnotations(paramType); JCModifiers paramMods = typeUseAnns.isEmpty() ? maker.Modifiers(paramFlags) : maker.Modifiers(paramFlags, typeUseAnns); JCVariableDecl param = maker.VarDef(paramMods, data.getSingularName(), paramType, null); - List typeParams = List.nil(); - List thrown = List.nil(); - finishAndInjectMethod(maker, returnType, builderType, source, typeParams, thrown, mods, body, name, List.of(param)); + finishAndInjectMethod(maker, returnType, builderType, source, mods, body, name, List.of(param)); } @Override @@ -137,8 +135,6 @@ abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularize JCExpression paramType = chainDots(builderType, "java", "util", "Collection"); paramType = addTypeArgs(1, true, builderType, paramType, data.getTypeArgs(), source); JCVariableDecl param = maker.VarDef(maker.Modifiers(paramFlags), data.getPluralName(), paramType, null); - List typeParams = List.nil(); - List thrown = List.nil(); - finishAndInjectMethod(maker, returnType, builderType, source, typeParams, thrown, mods, body, name, List.of(param)); + finishAndInjectMethod(maker, returnType, builderType, source, mods, body, name, List.of(param)); } } diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java index fe0db83e..c7483be6 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java @@ -159,9 +159,7 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { JCModifiers paramModsValue = typeUseAnnsValue.isEmpty() ? maker.Modifiers(paramFlags) : maker.Modifiers(paramFlags, typeUseAnnsValue); JCVariableDecl paramKey = maker.VarDef(paramModsKey, keyName, paramTypeKey, null); JCVariableDecl paramValue = maker.VarDef(paramModsValue, valueName, paramTypeValue, null); - List typeParams = List.nil(); - List thrown = List.nil(); - finishAndInjectMethod(maker, returnType, builderType, source, typeParams, thrown, mods, body, name, List.of(paramKey, paramValue)); + finishAndInjectMethod(maker, returnType, builderType, source, mods, body, name, List.of(paramKey, paramValue)); } @Override @@ -192,8 +190,7 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { JCExpression paramType = chainDots(builderType, "java", "util", "Map"); paramType = addTypeArgs(2, true, builderType, paramType, data.getTypeArgs(), source); JCVariableDecl param = maker.VarDef(maker.Modifiers(paramFlags), data.getPluralName(), paramType, null); - List typeParams = List.nil(); - finishAndInjectMethod(maker, returnType, builderType, source, typeParams, jceBlank, mods, body, name, List.of(param)); + finishAndInjectMethod(maker, returnType, builderType, source, mods, body, name, List.of(param)); } @Override public void appendBuildCode(SingularData data, JavacNode builderType, JCTree source, ListBuffer statements, Name targetVariableName, String builderVariable) { -- cgit From f84349965803816d46473b42d08ed0c0d288ce8a Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Thu, 10 Jan 2019 02:53:09 +0100 Subject: Extract local variable paramName --- .../javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java index 1b661bb2..79d5166e 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java @@ -111,11 +111,12 @@ abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularize Name name = data.getSingularName(); long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext()); if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName("add", name.toString())); + Name paramName = data.getSingularName(); JCExpression paramType = cloneParamType(0, maker, data.getTypeArgs(), builderType, source); List typeUseAnns = getTypeUseAnnotations(paramType); paramType = removeTypeUseAnnotations(paramType); JCModifiers paramMods = typeUseAnns.isEmpty() ? maker.Modifiers(paramFlags) : maker.Modifiers(paramFlags, typeUseAnns); - JCVariableDecl param = maker.VarDef(paramMods, data.getSingularName(), paramType, null); + JCVariableDecl param = maker.VarDef(paramMods, paramName, paramType, null); finishAndInjectMethod(maker, returnType, builderType, source, mods, body, name, List.of(param)); } -- cgit From 85759a1949fe862a2baa2cb836d0bbea5349db66 Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Thu, 10 Jan 2019 02:53:47 +0100 Subject: Detangle key/value param creation in JavacJavaUtilMapSingularizer.generateSingularMethod --- .../javac/handlers/singulars/JavacJavaUtilMapSingularizer.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java index c7483be6..9373512a 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java @@ -149,15 +149,17 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { Name name = data.getSingularName(); if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName("put", name.toString())); + JCExpression paramTypeKey = cloneParamType(0, maker, data.getTypeArgs(), builderType, source); - JCExpression paramTypeValue = cloneParamType(1, maker, data.getTypeArgs(), builderType, source); List typeUseAnnsKey = getTypeUseAnnotations(paramTypeKey); - List typeUseAnnsValue = getTypeUseAnnotations(paramTypeValue); paramTypeKey = removeTypeUseAnnotations(paramTypeKey); - paramTypeValue = removeTypeUseAnnotations(paramTypeValue); JCModifiers paramModsKey = typeUseAnnsKey.isEmpty() ? maker.Modifiers(paramFlags) : maker.Modifiers(paramFlags, typeUseAnnsKey); - JCModifiers paramModsValue = typeUseAnnsValue.isEmpty() ? maker.Modifiers(paramFlags) : maker.Modifiers(paramFlags, typeUseAnnsValue); JCVariableDecl paramKey = maker.VarDef(paramModsKey, keyName, paramTypeKey, null); + + JCExpression paramTypeValue = cloneParamType(1, maker, data.getTypeArgs(), builderType, source); + List typeUseAnnsValue = getTypeUseAnnotations(paramTypeValue); + paramTypeValue = removeTypeUseAnnotations(paramTypeValue); + JCModifiers paramModsValue = typeUseAnnsValue.isEmpty() ? maker.Modifiers(paramFlags) : maker.Modifiers(paramFlags, typeUseAnnsValue); JCVariableDecl paramValue = maker.VarDef(paramModsValue, valueName, paramTypeValue, null); finishAndInjectMethod(maker, returnType, builderType, source, mods, body, name, List.of(paramKey, paramValue)); } -- cgit From 4599a65b7df036eabf5d6784466a0ab848a63d16 Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Thu, 10 Jan 2019 03:06:57 +0100 Subject: Extract method JavacSingularizer.generateSingularMethodParameter --- src/core/lombok/javac/handlers/JavacSingularsRecipes.java | 8 ++++++++ .../javac/handlers/singulars/JavacGuavaSingularizer.java | 7 +------ .../singulars/JavacJavaUtilListSetSingularizer.java | 8 +------- .../handlers/singulars/JavacJavaUtilMapSingularizer.java | 14 ++------------ 4 files changed, 12 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java index 9921ba89..d8dc65c7 100644 --- a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java +++ b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java @@ -266,6 +266,14 @@ public class JavacSingularsRecipes { protected abstract void generateSingularMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent); + protected JCVariableDecl generateSingularMethodParameter(int typeIndex, JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source, Name name, long flags) { + JCExpression type = cloneParamType(typeIndex, maker, data.getTypeArgs(), builderType, source); + List typeUseAnns = getTypeUseAnnotations(type); + type = removeTypeUseAnnotations(type); + JCModifiers mods = typeUseAnns.isEmpty() ? maker.Modifiers(flags) : maker.Modifiers(flags, typeUseAnns); + return maker.VarDef(mods, name, type, null); + } + 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 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 b514ebd5..cd650f9a 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java @@ -44,7 +44,6 @@ import com.sun.tools.javac.tree.JCTree.JCBlock; import com.sun.tools.javac.tree.JCTree.JCExpression; import com.sun.tools.javac.tree.JCTree.JCModifiers; import com.sun.tools.javac.tree.JCTree.JCStatement; -import com.sun.tools.javac.tree.JCTree.JCTypeParameter; import com.sun.tools.javac.tree.JCTree.JCVariableDecl; import com.sun.tools.javac.util.List; import com.sun.tools.javac.util.ListBuffer; @@ -109,11 +108,7 @@ abstract class JavacGuavaSingularizer extends JavacSingularizer { if (!fluent) methodName = builderType.toName(HandlerUtil.buildAccessorName(getAddMethodName(), methodName.toString())); ListBuffer params = new ListBuffer(); for (int i = 0; i < suffixes.size(); i++) { - JCExpression pt = cloneParamType(i, maker, data.getTypeArgs(), builderType, source); - List typeUseAnns = getTypeUseAnnotations(pt); - pt = removeTypeUseAnnotations(pt); - JCModifiers paramMods = typeUseAnns.isEmpty() ? maker.Modifiers(paramFlags) : maker.Modifiers(paramFlags, typeUseAnns); - JCVariableDecl p = maker.VarDef(paramMods, names[i], pt, null); + JCVariableDecl p = generateSingularMethodParameter(i, maker, data, builderType, source, names[i], paramFlags); params.append(p); } diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java index 79d5166e..665e22ea 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java @@ -36,12 +36,10 @@ 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; import com.sun.tools.javac.tree.JCTree.JCStatement; -import com.sun.tools.javac.tree.JCTree.JCTypeParameter; import com.sun.tools.javac.tree.JCTree.JCVariableDecl; import com.sun.tools.javac.util.List; import com.sun.tools.javac.util.ListBuffer; @@ -112,11 +110,7 @@ abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularize long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext()); if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName("add", name.toString())); Name paramName = data.getSingularName(); - JCExpression paramType = cloneParamType(0, maker, data.getTypeArgs(), builderType, source); - List typeUseAnns = getTypeUseAnnotations(paramType); - paramType = removeTypeUseAnnotations(paramType); - JCModifiers paramMods = typeUseAnns.isEmpty() ? maker.Modifiers(paramFlags) : maker.Modifiers(paramFlags, typeUseAnns); - JCVariableDecl param = maker.VarDef(paramMods, paramName, paramType, null); + JCVariableDecl param = generateSingularMethodParameter(0, maker, data, builderType, source, paramName, paramFlags); finishAndInjectMethod(maker, returnType, builderType, source, mods, body, name, List.of(param)); } diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java index 9373512a..8b5f08eb 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java @@ -45,7 +45,6 @@ import com.sun.tools.javac.tree.JCTree.JCBlock; import com.sun.tools.javac.tree.JCTree.JCExpression; import com.sun.tools.javac.tree.JCTree.JCModifiers; import com.sun.tools.javac.tree.JCTree.JCStatement; -import com.sun.tools.javac.tree.JCTree.JCTypeParameter; import com.sun.tools.javac.tree.JCTree.JCVariableDecl; import com.sun.tools.javac.util.List; import com.sun.tools.javac.util.ListBuffer; @@ -150,17 +149,8 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { Name name = data.getSingularName(); if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName("put", name.toString())); - JCExpression paramTypeKey = cloneParamType(0, maker, data.getTypeArgs(), builderType, source); - List typeUseAnnsKey = getTypeUseAnnotations(paramTypeKey); - paramTypeKey = removeTypeUseAnnotations(paramTypeKey); - JCModifiers paramModsKey = typeUseAnnsKey.isEmpty() ? maker.Modifiers(paramFlags) : maker.Modifiers(paramFlags, typeUseAnnsKey); - JCVariableDecl paramKey = maker.VarDef(paramModsKey, keyName, paramTypeKey, null); - - JCExpression paramTypeValue = cloneParamType(1, maker, data.getTypeArgs(), builderType, source); - List typeUseAnnsValue = getTypeUseAnnotations(paramTypeValue); - paramTypeValue = removeTypeUseAnnotations(paramTypeValue); - JCModifiers paramModsValue = typeUseAnnsValue.isEmpty() ? maker.Modifiers(paramFlags) : maker.Modifiers(paramFlags, typeUseAnnsValue); - JCVariableDecl paramValue = maker.VarDef(paramModsValue, valueName, paramTypeValue, null); + JCVariableDecl paramKey = generateSingularMethodParameter(0, maker, data, builderType, source, keyName, paramFlags); + JCVariableDecl paramValue = generateSingularMethodParameter(1, maker, data, builderType, source, valueName, paramFlags); finishAndInjectMethod(maker, returnType, builderType, source, mods, body, name, List.of(paramKey, paramValue)); } -- cgit From b09f4ca38dd1a7f819b9294382db0c7a43ebe809 Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Thu, 10 Jan 2019 03:28:09 +0100 Subject: Inline single-use variable --- src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java index cd650f9a..50426a87 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java @@ -108,8 +108,7 @@ abstract class JavacGuavaSingularizer extends JavacSingularizer { if (!fluent) methodName = builderType.toName(HandlerUtil.buildAccessorName(getAddMethodName(), methodName.toString())); ListBuffer params = new ListBuffer(); for (int i = 0; i < suffixes.size(); i++) { - JCVariableDecl p = generateSingularMethodParameter(i, maker, data, builderType, source, names[i], paramFlags); - params.append(p); + params.append(generateSingularMethodParameter(i, maker, data, builderType, source, names[i], paramFlags)); } finishAndInjectMethod(maker, returnType, builderType, source, mods, body, methodName, params.toList()); -- cgit From a367f7815dcf7a818e3494929e3d005e06c2efb1 Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Thu, 10 Jan 2019 03:29:55 +0100 Subject: Move local variable declarations to just before use --- src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java | 2 +- .../javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java | 3 ++- .../lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java index 50426a87..73b1a456 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java @@ -104,10 +104,10 @@ abstract class JavacGuavaSingularizer extends JavacSingularizer { if (returnStatement != null) statements.append(returnStatement); JCBlock body = maker.Block(0, statements.toList()); Name methodName = data.getSingularName(); - long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext()); if (!fluent) methodName = builderType.toName(HandlerUtil.buildAccessorName(getAddMethodName(), methodName.toString())); ListBuffer params = new ListBuffer(); for (int i = 0; i < suffixes.size(); i++) { + long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext()); params.append(generateSingularMethodParameter(i, maker, data, builderType, source, names[i], paramFlags)); } diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java index 665e22ea..d6c0a02d 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java @@ -107,9 +107,10 @@ abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularize if (returnStatement != null) statements.append(returnStatement); JCBlock body = maker.Block(0, statements.toList()); Name name = data.getSingularName(); - long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext()); if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName("add", name.toString())); Name paramName = data.getSingularName(); + + long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext()); JCVariableDecl param = generateSingularMethodParameter(0, maker, data, builderType, source, paramName, paramFlags); finishAndInjectMethod(maker, returnType, builderType, source, mods, body, name, List.of(param)); } diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java index 8b5f08eb..a936f117 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java @@ -144,11 +144,11 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { } if (returnStatement != null) statements.append(returnStatement); JCBlock body = maker.Block(0, statements.toList()); - long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext()); - + Name name = data.getSingularName(); if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName("put", name.toString())); + long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext()); JCVariableDecl paramKey = generateSingularMethodParameter(0, maker, data, builderType, source, keyName, paramFlags); JCVariableDecl paramValue = generateSingularMethodParameter(1, maker, data, builderType, source, valueName, paramFlags); finishAndInjectMethod(maker, returnType, builderType, source, mods, body, name, List.of(paramKey, paramValue)); -- cgit From 2747ce6a2ca3ae5b06cc8fdbd1c2c8607c515858 Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Thu, 10 Jan 2019 03:31:46 +0100 Subject: Move invariant parameter inside generateSingularMethodParameter --- src/core/lombok/javac/handlers/JavacSingularsRecipes.java | 3 ++- src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java | 3 +-- .../javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java | 3 +-- .../javac/handlers/singulars/JavacJavaUtilMapSingularizer.java | 5 ++--- 4 files changed, 6 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java index d8dc65c7..b2bcf091 100644 --- a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java +++ b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java @@ -266,7 +266,8 @@ public class JavacSingularsRecipes { protected abstract void generateSingularMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent); - protected JCVariableDecl generateSingularMethodParameter(int typeIndex, JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source, Name name, long flags) { + protected JCVariableDecl generateSingularMethodParameter(int typeIndex, JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source, Name name) { + long flags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext()); JCExpression type = cloneParamType(typeIndex, maker, data.getTypeArgs(), builderType, source); List typeUseAnns = getTypeUseAnnotations(type); type = removeTypeUseAnnotations(type); diff --git a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java index 73b1a456..971738c7 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java @@ -107,8 +107,7 @@ abstract class JavacGuavaSingularizer extends JavacSingularizer { if (!fluent) methodName = builderType.toName(HandlerUtil.buildAccessorName(getAddMethodName(), methodName.toString())); ListBuffer params = new ListBuffer(); for (int i = 0; i < suffixes.size(); i++) { - long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext()); - params.append(generateSingularMethodParameter(i, maker, data, builderType, source, names[i], paramFlags)); + params.append(generateSingularMethodParameter(i, maker, data, builderType, source, names[i])); } finishAndInjectMethod(maker, returnType, builderType, source, mods, body, methodName, params.toList()); diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java index d6c0a02d..955dfef0 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java @@ -110,8 +110,7 @@ abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularize if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName("add", name.toString())); Name paramName = data.getSingularName(); - long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext()); - JCVariableDecl param = generateSingularMethodParameter(0, maker, data, builderType, source, paramName, paramFlags); + JCVariableDecl param = generateSingularMethodParameter(0, maker, data, builderType, source, paramName); finishAndInjectMethod(maker, returnType, builderType, source, mods, body, name, List.of(param)); } diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java index a936f117..346fe5d7 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java @@ -148,9 +148,8 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { Name name = data.getSingularName(); if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName("put", name.toString())); - long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext()); - JCVariableDecl paramKey = generateSingularMethodParameter(0, maker, data, builderType, source, keyName, paramFlags); - JCVariableDecl paramValue = generateSingularMethodParameter(1, maker, data, builderType, source, valueName, paramFlags); + JCVariableDecl paramKey = generateSingularMethodParameter(0, maker, data, builderType, source, keyName); + JCVariableDecl paramValue = generateSingularMethodParameter(1, maker, data, builderType, source, valueName); finishAndInjectMethod(maker, returnType, builderType, source, mods, body, name, List.of(paramKey, paramValue)); } -- cgit From 8cec66794357b26f53a773f8dd448b2b3b1fdd72 Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Thu, 10 Jan 2019 03:32:48 +0100 Subject: Inline single-use variable --- .../javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java index 955dfef0..13418903 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java @@ -108,9 +108,8 @@ abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularize JCBlock body = maker.Block(0, statements.toList()); Name name = data.getSingularName(); if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName("add", name.toString())); - Name paramName = data.getSingularName(); - JCVariableDecl param = generateSingularMethodParameter(0, maker, data, builderType, source, paramName); + JCVariableDecl param = generateSingularMethodParameter(0, maker, data, builderType, source, data.getSingularName()); finishAndInjectMethod(maker, returnType, builderType, source, mods, body, name, List.of(param)); } -- cgit From e9f4bcb890ba96f1c31bce01c3ee7c15bf56866f Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Thu, 10 Jan 2019 03:43:08 +0100 Subject: Extract local variables --- .../lombok/javac/handlers/singulars/JavacGuavaSingularizer.java | 4 +++- .../javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java | 4 +++- .../javac/handlers/singulars/JavacJavaUtilMapSingularizer.java | 6 ++++-- 3 files changed, 10 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java index 971738c7..4cd5cf46 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java @@ -100,7 +100,9 @@ abstract class JavacGuavaSingularizer extends JavacSingularizer { } List invokeAddExpr = invokeAddExprBuilder.toList(); JCExpression invokeAdd = maker.Apply(List.nil(), thisDotFieldDotAdd, invokeAddExpr); - statements.append(maker.Exec(invokeAdd)); + JCStatement st = maker.Exec(invokeAdd); + statements.append(st); + if (returnStatement != null) statements.append(returnStatement); JCBlock body = maker.Block(0, statements.toList()); Name methodName = data.getSingularName(); diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java index 13418903..f270a375 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java @@ -103,7 +103,9 @@ abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularize statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, false, source)); JCExpression thisDotFieldDotAdd = chainDots(builderType, "this", data.getPluralName().toString(), "add"); JCExpression invokeAdd = maker.Apply(List.nil(), thisDotFieldDotAdd, List.of(maker.Ident(data.getSingularName()))); - statements.append(maker.Exec(invokeAdd)); + JCStatement st = maker.Exec(invokeAdd); + statements.append(st); + if (returnStatement != null) statements.append(returnStatement); JCBlock body = maker.Block(0, statements.toList()); Name name = data.getSingularName(); diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java index 346fe5d7..ad628c5b 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java @@ -135,12 +135,14 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { /* this.pluralname$key.add(singularnameKey); */ { JCExpression thisDotKeyFieldDotAdd = chainDots(builderType, "this", data.getPluralName() + "$key", "add"); JCExpression invokeAdd = maker.Apply(List.nil(), thisDotKeyFieldDotAdd, List.of(maker.Ident(keyName))); - statements.append(maker.Exec(invokeAdd)); + JCStatement st = maker.Exec(invokeAdd); + statements.append(st); } /* this.pluralname$value.add(singularnameValue); */ { JCExpression thisDotValueFieldDotAdd = chainDots(builderType, "this", data.getPluralName() + "$value", "add"); JCExpression invokeAdd = maker.Apply(List.nil(), thisDotValueFieldDotAdd, List.of(maker.Ident(valueName))); - statements.append(maker.Exec(invokeAdd)); + JCStatement st = maker.Exec(invokeAdd); + statements.append(st); } if (returnStatement != null) statements.append(returnStatement); JCBlock body = maker.Block(0, statements.toList()); -- cgit From 54d8d4b4313cdaa46f7f9581ee6d4214a1542c20 Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Thu, 10 Jan 2019 03:58:48 +0100 Subject: Extract method generateSingularMethodAddStatement --- src/core/lombok/javac/handlers/JavacSingularsRecipes.java | 6 ++++++ .../handlers/singulars/JavacJavaUtilListSetSingularizer.java | 4 +--- .../javac/handlers/singulars/JavacJavaUtilMapSingularizer.java | 9 ++------- 3 files changed, 9 insertions(+), 10 deletions(-) (limited to 'src') 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.nil(), thisDotFieldDotAdd, List.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 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 statements = new ListBuffer(); statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, false, source)); - JCExpression thisDotFieldDotAdd = chainDots(builderType, "this", data.getPluralName().toString(), "add"); - JCExpression invokeAdd = maker.Apply(List.nil(), thisDotFieldDotAdd, List.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.nil(), thisDotKeyFieldDotAdd, List.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.nil(), thisDotValueFieldDotAdd, List.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); -- cgit From 36e6e56a93b783b3847d53e998c8e124475d8053 Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Thu, 10 Jan 2019 04:00:09 +0100 Subject: Inline single-use variables --- .../handlers/singulars/JavacJavaUtilListSetSingularizer.java | 3 +-- .../handlers/singulars/JavacJavaUtilMapSingularizer.java | 11 +++-------- 2 files changed, 4 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java index 3781a67e..935edbc3 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java @@ -101,8 +101,7 @@ abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularize JCModifiers mods = makeMods(maker, builderType, deprecate); ListBuffer statements = new ListBuffer(); statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, false, source)); - JCStatement st = generateSingularMethodAddStatement(maker, builderType, data.getSingularName(), data.getPluralName().toString()); - statements.append(st); + statements.append(generateSingularMethodAddStatement(maker, builderType, data.getSingularName(), data.getPluralName().toString())); if (returnStatement != null) statements.append(returnStatement); JCBlock body = maker.Block(0, statements.toList()); diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java index 16b5f1a0..f9a95095 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java @@ -131,14 +131,9 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, true, source)); Name keyName = builderType.toName(data.getSingularName().toString() + "Key"); Name valueName = builderType.toName(data.getSingularName().toString() + "Value"); - /* this.pluralname$key.add(singularnameKey); */ { - JCStatement st = generateSingularMethodAddStatement(maker, builderType, keyName, data.getPluralName() + "$key"); - statements.append(st); - } - /* this.pluralname$value.add(singularnameValue); */ { - JCStatement st = generateSingularMethodAddStatement(maker, builderType, valueName, data.getPluralName() + "$value"); - statements.append(st); - } + statements.append(generateSingularMethodAddStatement(maker, builderType, keyName, data.getPluralName() + "$key")); + statements.append(generateSingularMethodAddStatement(maker, builderType, valueName, data.getPluralName() + "$value")); + if (returnStatement != null) statements.append(returnStatement); JCBlock body = maker.Block(0, statements.toList()); -- cgit From 130c115eaf07ae9183f95c861ebb0c4011c74774 Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Sun, 13 Jan 2019 02:25:25 +0100 Subject: Restore comments describing generated code --- .../lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java index f9a95095..b1e34d47 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java @@ -131,7 +131,10 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, true, source)); Name keyName = builderType.toName(data.getSingularName().toString() + "Key"); Name valueName = builderType.toName(data.getSingularName().toString() + "Value"); + + /* 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")); if (returnStatement != null) statements.append(returnStatement); -- cgit From f995dd20360311f355e18bf5fa048058efecdd11 Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Thu, 10 Jan 2019 04:07:54 +0100 Subject: Extract local variable: params --- .../javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java | 3 ++- .../lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java index 935edbc3..6beebec7 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java @@ -109,7 +109,8 @@ abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularize if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName("add", name.toString())); JCVariableDecl param = generateSingularMethodParameter(0, maker, data, builderType, source, data.getSingularName()); - finishAndInjectMethod(maker, returnType, builderType, source, mods, body, name, List.of(param)); + List params = List.of(param); + finishAndInjectMethod(maker, returnType, builderType, source, mods, body, name, params); } @Override diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java index b1e34d47..cd98fd1e 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java @@ -145,7 +145,8 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { JCVariableDecl paramKey = generateSingularMethodParameter(0, maker, data, builderType, source, keyName); JCVariableDecl paramValue = generateSingularMethodParameter(1, maker, data, builderType, source, valueName); - finishAndInjectMethod(maker, returnType, builderType, source, mods, body, name, List.of(paramKey, paramValue)); + List params = List.of(paramKey, paramValue); + finishAndInjectMethod(maker, returnType, builderType, source, mods, body, name, params); } @Override -- cgit From a4c21e941d28160c33e6541a29350d23209cfb8f Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Thu, 10 Jan 2019 04:10:29 +0100 Subject: Make last few statements the same between generateSingularMethod implementations --- .../lombok/javac/handlers/singulars/JavacGuavaSingularizer.java | 9 +++++---- .../handlers/singulars/JavacJavaUtilListSetSingularizer.java | 5 +++-- .../javac/handlers/singulars/JavacJavaUtilMapSingularizer.java | 8 ++++---- 3 files changed, 12 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java index 4cd5cf46..7f610b79 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java @@ -103,15 +103,16 @@ abstract class JavacGuavaSingularizer extends JavacSingularizer { JCStatement st = maker.Exec(invokeAdd); statements.append(st); - if (returnStatement != null) statements.append(returnStatement); - JCBlock body = maker.Block(0, statements.toList()); - Name methodName = data.getSingularName(); - if (!fluent) methodName = builderType.toName(HandlerUtil.buildAccessorName(getAddMethodName(), methodName.toString())); ListBuffer params = new ListBuffer(); for (int i = 0; i < suffixes.size(); i++) { params.append(generateSingularMethodParameter(i, maker, data, builderType, source, names[i])); } + if (returnStatement != null) statements.append(returnStatement); + JCBlock body = maker.Block(0, statements.toList()); + Name methodName = data.getSingularName(); + if (!fluent) methodName = builderType.toName(HandlerUtil.buildAccessorName(getAddMethodName(), methodName.toString())); + finishAndInjectMethod(maker, returnType, builderType, source, mods, body, methodName, params.toList()); } diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java index 6beebec7..441f9eda 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java @@ -103,13 +103,14 @@ abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularize statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, false, source)); statements.append(generateSingularMethodAddStatement(maker, builderType, data.getSingularName(), data.getPluralName().toString())); + JCVariableDecl param = generateSingularMethodParameter(0, maker, data, builderType, source, data.getSingularName()); + List params = List.of(param); + if (returnStatement != null) statements.append(returnStatement); JCBlock body = maker.Block(0, statements.toList()); Name name = data.getSingularName(); if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName("add", name.toString())); - JCVariableDecl param = generateSingularMethodParameter(0, maker, data, builderType, source, data.getSingularName()); - List params = List.of(param); finishAndInjectMethod(maker, returnType, builderType, source, mods, body, name, params); } diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java index cd98fd1e..5ecbee8a 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java @@ -137,15 +137,15 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { /* Generates: this.pluralname$value.add(singularnameValue); */ statements.append(generateSingularMethodAddStatement(maker, builderType, valueName, data.getPluralName() + "$value")); + JCVariableDecl paramKey = generateSingularMethodParameter(0, maker, data, builderType, source, keyName); + JCVariableDecl paramValue = generateSingularMethodParameter(1, maker, data, builderType, source, valueName); + List params = List.of(paramKey, paramValue); + if (returnStatement != null) statements.append(returnStatement); JCBlock body = maker.Block(0, statements.toList()); - Name name = data.getSingularName(); if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName("put", name.toString())); - JCVariableDecl paramKey = generateSingularMethodParameter(0, maker, data, builderType, source, keyName); - JCVariableDecl paramValue = generateSingularMethodParameter(1, maker, data, builderType, source, valueName); - List params = List.of(paramKey, paramValue); finishAndInjectMethod(maker, returnType, builderType, source, mods, body, name, params); } -- cgit From e8c70dd755c528b4f975be95333a337c290db2be Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Thu, 10 Jan 2019 04:11:59 +0100 Subject: Extract local variable addMethodName --- src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java | 3 ++- .../javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java | 3 ++- .../lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java index 7f610b79..25fc8751 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java @@ -108,10 +108,11 @@ 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(getAddMethodName(), methodName.toString())); + if (!fluent) methodName = builderType.toName(HandlerUtil.buildAccessorName(addMethodName, methodName.toString())); finishAndInjectMethod(maker, returnType, builderType, source, mods, body, methodName, params.toList()); } diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java index 441f9eda..981f40cd 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java @@ -106,10 +106,11 @@ abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularize JCVariableDecl param = generateSingularMethodParameter(0, maker, data, builderType, source, data.getSingularName()); List 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("add", name.toString())); + if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName(addMethodName, name.toString())); finishAndInjectMethod(maker, returnType, builderType, source, mods, body, name, params); } diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java index 5ecbee8a..a7859ce6 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java @@ -141,10 +141,11 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { JCVariableDecl paramValue = generateSingularMethodParameter(1, maker, data, builderType, source, valueName); List 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("put", name.toString())); + if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName(addMethodName, name.toString())); finishAndInjectMethod(maker, returnType, builderType, source, mods, body, name, params); } -- cgit From fd7301117deeaa94f4ecb4316a3ef68c1a13a660 Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Thu, 10 Jan 2019 04:13:34 +0100 Subject: Extract method finishAndInjectSingularMethod --- src/core/lombok/javac/handlers/JavacSingularsRecipes.java | 9 +++++++++ .../lombok/javac/handlers/singulars/JavacGuavaSingularizer.java | 8 +------- .../handlers/singulars/JavacJavaUtilListSetSingularizer.java | 8 +------- .../javac/handlers/singulars/JavacJavaUtilMapSingularizer.java | 8 +------- 4 files changed, 12 insertions(+), 21 deletions(-) (limited to 'src') 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 statements, List 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 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 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 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 -- cgit From 0c20da8e0e19e6db37c4c9d0de05d784e472c258 Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Thu, 10 Jan 2019 04:21:54 +0100 Subject: Move single-use variable declarations to just before use --- src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java | 2 +- .../javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java | 2 +- .../lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java | 3 +-- 3 files changed, 3 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java index e79f626c..97329f78 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java @@ -90,7 +90,6 @@ abstract class JavacGuavaSingularizer extends JavacSingularizer { names[i] = s.isEmpty() ? n : builderType.toName(s); } - JCModifiers mods = makeMods(maker, builderType, deprecate); ListBuffer statements = new ListBuffer(); statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, source)); JCExpression thisDotFieldDotAdd = chainDots(builderType, "this", data.getPluralName().toString(), getAddMethodName()); @@ -108,6 +107,7 @@ abstract class JavacGuavaSingularizer extends JavacSingularizer { params.append(generateSingularMethodParameter(i, maker, data, builderType, source, names[i])); } + JCModifiers mods = makeMods(maker, builderType, deprecate); finishAndInjectSingularMethod(maker, returnType, returnStatement, data, builderType, source, fluent, mods, statements, params.toList(), getAddMethodName()); } diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java index 7cc7e30e..76c58678 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java @@ -98,7 +98,6 @@ 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) { - JCModifiers mods = makeMods(maker, builderType, deprecate); ListBuffer statements = new ListBuffer(); statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, false, source)); statements.append(generateSingularMethodAddStatement(maker, builderType, data.getSingularName(), data.getPluralName().toString())); @@ -106,6 +105,7 @@ abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularize JCVariableDecl param = generateSingularMethodParameter(0, maker, data, builderType, source, data.getSingularName()); List params = List.of(param); + JCModifiers mods = makeMods(maker, builderType, deprecate); finishAndInjectSingularMethod(maker, returnType, returnStatement, data, builderType, source, fluent, mods, statements, params, "add"); } diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java index 687cb1d1..6add2fcb 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java @@ -125,8 +125,6 @@ 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) { - JCModifiers mods = makeMods(maker, builderType, deprecate); - ListBuffer statements = new ListBuffer(); statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, true, source)); Name keyName = builderType.toName(data.getSingularName().toString() + "Key"); @@ -141,6 +139,7 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { JCVariableDecl paramValue = generateSingularMethodParameter(1, maker, data, builderType, source, valueName); List params = List.of(paramKey, paramValue); + JCModifiers mods = makeMods(maker, builderType, deprecate); finishAndInjectSingularMethod(maker, returnType, returnStatement, data, builderType, source, fluent, mods, statements, params, "put"); } -- cgit From 73a70e3332230170a11657610417f6d62a269643 Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Thu, 10 Jan 2019 04:23:24 +0100 Subject: Move invariant parameter inside finishAndInjectSingularMethod --- src/core/lombok/javac/handlers/JavacSingularsRecipes.java | 3 ++- src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java | 3 +-- .../javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java | 3 +-- .../lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java | 3 +-- 4 files changed, 5 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java index ad8f978a..1546e523 100644 --- a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java +++ b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java @@ -281,7 +281,8 @@ 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 statements, List params, String addMethodName) { + protected void finishAndInjectSingularMethod(JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent, boolean deprecate, ListBuffer statements, List params, String addMethodName) { + JCModifiers mods = makeMods(maker, builderType, deprecate); if (returnStatement != null) statements.append(returnStatement); JCBlock body = maker.Block(0, statements.toList()); Name name = data.getSingularName(); diff --git a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java index 97329f78..9d5264c4 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java @@ -107,8 +107,7 @@ abstract class JavacGuavaSingularizer extends JavacSingularizer { params.append(generateSingularMethodParameter(i, maker, data, builderType, source, names[i])); } - JCModifiers mods = makeMods(maker, builderType, deprecate); - finishAndInjectSingularMethod(maker, returnType, returnStatement, data, builderType, source, fluent, mods, statements, params.toList(), getAddMethodName()); + finishAndInjectSingularMethod(maker, returnType, returnStatement, data, builderType, source, fluent, deprecate, 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 76c58678..182bf78a 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java @@ -105,8 +105,7 @@ abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularize JCVariableDecl param = generateSingularMethodParameter(0, maker, data, builderType, source, data.getSingularName()); List params = List.of(param); - JCModifiers mods = makeMods(maker, builderType, deprecate); - finishAndInjectSingularMethod(maker, returnType, returnStatement, data, builderType, source, fluent, mods, statements, params, "add"); + finishAndInjectSingularMethod(maker, returnType, returnStatement, data, builderType, source, fluent, deprecate, 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 6add2fcb..255bb63a 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java @@ -139,8 +139,7 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { JCVariableDecl paramValue = generateSingularMethodParameter(1, maker, data, builderType, source, valueName); List params = List.of(paramKey, paramValue); - JCModifiers mods = makeMods(maker, builderType, deprecate); - finishAndInjectSingularMethod(maker, returnType, returnStatement, data, builderType, source, fluent, mods, statements, params, "put"); + finishAndInjectSingularMethod(maker, returnType, returnStatement, data, builderType, source, fluent, deprecate, statements, params, "put"); } @Override -- cgit From 223a3fdb97ce67247b03a2537f53600fa6f2c383 Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Thu, 10 Jan 2019 04:31:57 +0100 Subject: Uae names.length instead of suffixes.size() as loop limits --- .../lombok/javac/handlers/singulars/JavacGuavaSingularizer.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java index 9d5264c4..d3db63ff 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java @@ -84,17 +84,17 @@ abstract class JavacGuavaSingularizer extends JavacSingularizer { protected void generateSingularMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) { LombokImmutableList suffixes = getArgumentSuffixes(); Name[] names = new Name[suffixes.size()]; - for (int i = 0; i < suffixes.size(); i++) { + for (int i = 0; i < names.length; i++) { String s = suffixes.get(i); Name n = data.getSingularName(); names[i] = s.isEmpty() ? n : builderType.toName(s); } - + ListBuffer statements = new ListBuffer(); statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, source)); JCExpression thisDotFieldDotAdd = chainDots(builderType, "this", data.getPluralName().toString(), getAddMethodName()); ListBuffer invokeAddExprBuilder = new ListBuffer(); - for (int i = 0; i < suffixes.size(); i++) { + for (int i = 0; i < names.length; i++) { invokeAddExprBuilder.append(maker.Ident(names[i])); } List invokeAddExpr = invokeAddExprBuilder.toList(); @@ -103,7 +103,7 @@ abstract class JavacGuavaSingularizer extends JavacSingularizer { statements.append(st); ListBuffer params = new ListBuffer(); - for (int i = 0; i < suffixes.size(); i++) { + for (int i = 0; i < names.length; i++) { params.append(generateSingularMethodParameter(i, maker, data, builderType, source, names[i])); } -- cgit From bbaa932c11dbe70bb14ec49434df9ef5196b04cc Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Thu, 10 Jan 2019 04:32:15 +0100 Subject: Replace for-int with for-each --- src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java index d3db63ff..d4becda7 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java @@ -94,8 +94,8 @@ abstract class JavacGuavaSingularizer extends JavacSingularizer { statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, source)); JCExpression thisDotFieldDotAdd = chainDots(builderType, "this", data.getPluralName().toString(), getAddMethodName()); ListBuffer invokeAddExprBuilder = new ListBuffer(); - for (int i = 0; i < names.length; i++) { - invokeAddExprBuilder.append(maker.Ident(names[i])); + for (Name name : names) { + invokeAddExprBuilder.append(maker.Ident(name)); } List invokeAddExpr = invokeAddExprBuilder.toList(); JCExpression invokeAdd = maker.Apply(List.nil(), thisDotFieldDotAdd, invokeAddExpr); -- cgit From 3c28cf93ff79fb8f0c1c46c64a5851d235179700 Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Thu, 10 Jan 2019 04:33:16 +0100 Subject: Extract function generateSingularMethodParameterNames --- .../handlers/singulars/JavacGuavaSingularizer.java | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java index d4becda7..bf2e1cbc 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java @@ -82,13 +82,7 @@ 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) { - LombokImmutableList suffixes = getArgumentSuffixes(); - Name[] names = new Name[suffixes.size()]; - for (int i = 0; i < names.length; i++) { - String s = suffixes.get(i); - Name n = data.getSingularName(); - names[i] = s.isEmpty() ? n : builderType.toName(s); - } + Name[] names = generateSingularMethodParameterNames(data, builderType); ListBuffer statements = new ListBuffer(); statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, source)); @@ -109,7 +103,18 @@ abstract class JavacGuavaSingularizer extends JavacSingularizer { finishAndInjectSingularMethod(maker, returnType, returnStatement, data, builderType, source, fluent, deprecate, statements, params.toList(), getAddMethodName()); } - + + private Name[] generateSingularMethodParameterNames(SingularData data, JavacNode builderType) { + LombokImmutableList suffixes = getArgumentSuffixes(); + Name[] names = new Name[suffixes.size()]; + for (int i = 0; i < names.length; i++) { + String s = suffixes.get(i); + Name n = data.getSingularName(); + names[i] = s.isEmpty() ? n : builderType.toName(s); + } + return names; + } + @Override protected void generatePluralMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) { JCModifiers mods = makeMods(maker, builderType, deprecate); -- cgit From 975f26bcc6324de748d2f307aed80e0950cd7f19 Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Thu, 10 Jan 2019 04:37:32 +0100 Subject: Extract methods generateSingularMethod{Parameters,Statements} --- .../handlers/singulars/JavacGuavaSingularizer.java | 24 ++++++++++++++-------- .../JavacJavaUtilListSetSingularizer.java | 13 +++++++++--- .../singulars/JavacJavaUtilMapSingularizer.java | 17 +++++++++++---- 3 files changed, 39 insertions(+), 15 deletions(-) (limited to 'src') 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 statements = generateSingularMethodStatements(maker, data, builderType, source); + List params = generateSingularMethodParameters(maker, data, builderType, source); + finishAndInjectSingularMethod(maker, returnType, returnStatement, data, builderType, source, fluent, deprecate, statements, params, getAddMethodName()); + } + + private List generateSingularMethodParameters(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) { Name[] names = generateSingularMethodParameterNames(data, builderType); + ListBuffer params = new ListBuffer(); + for (int i = 0; i < names.length; i++) { + params.append(generateSingularMethodParameter(i, maker, data, builderType, source, names[i])); + } + return params.toList(); + } + private ListBuffer generateSingularMethodStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) { ListBuffer statements = new ListBuffer(); + Name[] names = generateSingularMethodParameterNames(data, builderType); + statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, source)); JCExpression thisDotFieldDotAdd = chainDots(builderType, "this", data.getPluralName().toString(), getAddMethodName()); ListBuffer invokeAddExprBuilder = new ListBuffer(); @@ -95,13 +109,7 @@ abstract class JavacGuavaSingularizer extends JavacSingularizer { JCExpression invokeAdd = maker.Apply(List.nil(), thisDotFieldDotAdd, invokeAddExpr); JCStatement st = maker.Exec(invokeAdd); statements.append(st); - - ListBuffer params = new ListBuffer(); - 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 statements = generateSingularMethodStatements(maker, data, builderType, source); + List params = generateSingularMethodParameters(maker, data, builderType, source); + finishAndInjectSingularMethod(maker, returnType, returnStatement, data, builderType, source, fluent, deprecate, statements, params, "add"); + } + + private ListBuffer generateSingularMethodStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) { ListBuffer statements = new ListBuffer(); statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, false, source)); statements.append(generateSingularMethodAddStatement(maker, builderType, data.getSingularName(), data.getPluralName().toString())); + return statements; + } + private List generateSingularMethodParameters(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) { JCVariableDecl param = generateSingularMethodParameter(0, maker, data, builderType, source, data.getSingularName()); - List 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 statements = generateSingularMethodStatements(maker, data, builderType, source); + List params = generateSingularMethodParameters(maker, data, builderType, source); + finishAndInjectSingularMethod(maker, returnType, returnStatement, data, builderType, source, fluent, deprecate, statements, params, "put"); + } + + private ListBuffer generateSingularMethodStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) { ListBuffer statements = new ListBuffer(); - 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 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 params = List.of(paramKey, paramValue); - - finishAndInjectSingularMethod(maker, returnType, returnStatement, data, builderType, source, fluent, deprecate, statements, params, "put"); + return List.of(paramKey, paramValue); } @Override -- cgit From 2ca4120ca2339d5ddf74cb74c0d3485e3779d3ca Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Thu, 10 Jan 2019 04:42:12 +0100 Subject: Extract method getAddMethodName --- .../javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java | 6 +++++- .../javac/handlers/singulars/JavacJavaUtilMapSingularizer.java | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java index 90fdb0cb..e3a568f8 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java @@ -100,7 +100,7 @@ abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularize protected void generateSingularMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) { ListBuffer statements = generateSingularMethodStatements(maker, data, builderType, source); List params = generateSingularMethodParameters(maker, data, builderType, source); - finishAndInjectSingularMethod(maker, returnType, returnStatement, data, builderType, source, fluent, deprecate, statements, params, "add"); + finishAndInjectSingularMethod(maker, returnType, returnStatement, data, builderType, source, fluent, deprecate, statements, params, getAddMethodName()); } private ListBuffer generateSingularMethodStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) { @@ -133,4 +133,8 @@ abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularize JCVariableDecl param = maker.VarDef(maker.Modifiers(paramFlags), data.getPluralName(), paramType, null); finishAndInjectMethod(maker, returnType, builderType, source, mods, body, name, List.of(param)); } + + private String getAddMethodName() { + return "add"; + } } diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java index cc6b47f9..ddbb546c 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java @@ -127,7 +127,7 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { protected void generateSingularMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) { ListBuffer statements = generateSingularMethodStatements(maker, data, builderType, source); List params = generateSingularMethodParameters(maker, data, builderType, source); - finishAndInjectSingularMethod(maker, returnType, returnStatement, data, builderType, source, fluent, deprecate, statements, params, "put"); + finishAndInjectSingularMethod(maker, returnType, returnStatement, data, builderType, source, fluent, deprecate, statements, params, getAddMethodName()); } private ListBuffer generateSingularMethodStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) { @@ -196,4 +196,8 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { statements.appendList(createJavaUtilSimpleCreationAndFillStatements(maker, data, builderType, true, true, false, true, "TreeMap", source, builderVariable)); } } + + private String getAddMethodName() { + return "put"; + } } -- cgit From ca7fdd7becb9340441d870e952ab1545973ae12a Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Thu, 10 Jan 2019 04:43:09 +0100 Subject: Pull method getAddMethodName up to JavacSingularizer --- src/core/lombok/javac/handlers/JavacSingularsRecipes.java | 2 ++ src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java | 2 +- .../javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java | 3 ++- .../lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java | 3 ++- 4 files changed, 7 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java index 1546e523..fbfd0b7c 100644 --- a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java +++ b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java @@ -404,5 +404,7 @@ public class JavacSingularsRecipes { } } } + + protected abstract String getAddMethodName(); } } diff --git a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java index 64345742..e2571507 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java @@ -193,7 +193,7 @@ abstract class JavacGuavaSingularizer extends JavacSingularizer { } protected abstract LombokImmutableList getArgumentSuffixes(); - protected abstract String getAddMethodName(); + protected abstract String getAddAllTypeName(); protected int getTypeArgumentsCount() { diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java index e3a568f8..f2bd94ea 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java @@ -134,7 +134,8 @@ abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularize finishAndInjectMethod(maker, returnType, builderType, source, mods, body, name, List.of(param)); } - private String getAddMethodName() { + @Override + protected String getAddMethodName() { return "add"; } } diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java index ddbb546c..09077660 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java @@ -197,7 +197,8 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { } } - private String getAddMethodName() { + @Override + protected String getAddMethodName() { return "put"; } } -- cgit From 452f1cb8eb11ab6335cc631e30c9ab21f9717140 Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Thu, 10 Jan 2019 04:47:37 +0100 Subject: Pull generateSingularMethod implementation up to JavacSingularizer --- src/core/lombok/javac/handlers/JavacSingularsRecipes.java | 10 +++++++++- .../javac/handlers/singulars/JavacGuavaSingularizer.java | 11 +++-------- .../singulars/JavacJavaUtilListSetSingularizer.java | 11 +++-------- .../handlers/singulars/JavacJavaUtilMapSingularizer.java | 13 ++++--------- 4 files changed, 19 insertions(+), 26 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java index fbfd0b7c..12dd0bf8 100644 --- a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java +++ b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java @@ -264,7 +264,11 @@ public class JavacSingularsRecipes { protected abstract JCStatement generateClearStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType); - protected abstract void generateSingularMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent); + void generateSingularMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) { + ListBuffer statements = generateSingularMethodStatements(maker, data, builderType, source); + List params = generateSingularMethodParameters(maker, data, builderType, source); + finishAndInjectSingularMethod(maker, returnType, returnStatement, data, builderType, source, fluent, deprecate, statements, params, getAddMethodName()); + } protected JCVariableDecl generateSingularMethodParameter(int typeIndex, JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source, Name name) { long flags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext()); @@ -291,6 +295,10 @@ public class JavacSingularsRecipes { finishAndInjectMethod(maker, returnType, builderType, source, mods, body, name, params); } + protected abstract ListBuffer generateSingularMethodStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source); + + protected abstract List generateSingularMethodParameters(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source); + 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 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 e2571507..b192564c 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java @@ -80,13 +80,7 @@ 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 statements = generateSingularMethodStatements(maker, data, builderType, source); - List params = generateSingularMethodParameters(maker, data, builderType, source); - finishAndInjectSingularMethod(maker, returnType, returnStatement, data, builderType, source, fluent, deprecate, statements, params, getAddMethodName()); - } - - private List generateSingularMethodParameters(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) { + protected List generateSingularMethodParameters(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) { Name[] names = generateSingularMethodParameterNames(data, builderType); ListBuffer params = new ListBuffer(); for (int i = 0; i < names.length; i++) { @@ -95,7 +89,8 @@ abstract class JavacGuavaSingularizer extends JavacSingularizer { return params.toList(); } - private ListBuffer generateSingularMethodStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) { + @Override + protected ListBuffer generateSingularMethodStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) { ListBuffer statements = new ListBuffer(); Name[] names = generateSingularMethodParameterNames(data, builderType); diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java index f2bd94ea..2f9bd0b7 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java @@ -97,20 +97,15 @@ 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 statements = generateSingularMethodStatements(maker, data, builderType, source); - List params = generateSingularMethodParameters(maker, data, builderType, source); - finishAndInjectSingularMethod(maker, returnType, returnStatement, data, builderType, source, fluent, deprecate, statements, params, getAddMethodName()); - } - - private ListBuffer generateSingularMethodStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) { + protected ListBuffer generateSingularMethodStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) { ListBuffer statements = new ListBuffer(); statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, false, source)); statements.append(generateSingularMethodAddStatement(maker, builderType, data.getSingularName(), data.getPluralName().toString())); return statements; } - private List generateSingularMethodParameters(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) { + @Override + protected List generateSingularMethodParameters(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) { JCVariableDecl param = generateSingularMethodParameter(0, maker, data, builderType, source, data.getSingularName()); return List.of(param); } diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java index 09077660..4bd771a4 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java @@ -122,15 +122,9 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { JCBlock clearCalls = maker.Block(0, List.of(clearKeyCall, clearValueCall)); return maker.If(cond, clearCalls, null); } - - @Override - protected void generateSingularMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) { - ListBuffer statements = generateSingularMethodStatements(maker, data, builderType, source); - List params = generateSingularMethodParameters(maker, data, builderType, source); - finishAndInjectSingularMethod(maker, returnType, returnStatement, data, builderType, source, fluent, deprecate, statements, params, getAddMethodName()); - } - private ListBuffer generateSingularMethodStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) { + @Override + protected ListBuffer generateSingularMethodStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) { ListBuffer statements = new ListBuffer(); Name keyName = builderType.toName(data.getSingularName().toString() + "Key"); Name valueName = builderType.toName(data.getSingularName().toString() + "Value"); @@ -143,7 +137,8 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { return statements; } - private List generateSingularMethodParameters(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) { + @Override + protected List 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); -- cgit From 1eaa6da81602ddfd7d2d170974c064b8c0b117cf Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Thu, 10 Jan 2019 04:50:38 +0100 Subject: Inline finishAndInjectSingularMethod into generateSingularMethod --- .../lombok/javac/handlers/JavacSingularsRecipes.java | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java index 12dd0bf8..db03c77a 100644 --- a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java +++ b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java @@ -267,7 +267,13 @@ public class JavacSingularsRecipes { void generateSingularMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) { ListBuffer statements = generateSingularMethodStatements(maker, data, builderType, source); List params = generateSingularMethodParameters(maker, data, builderType, source); - finishAndInjectSingularMethod(maker, returnType, returnStatement, data, builderType, source, fluent, deprecate, statements, params, getAddMethodName()); + JCModifiers mods = makeMods(maker, builderType, deprecate); + if (returnStatement != null) statements.append(returnStatement); + JCBlock body = maker.Block(0, statements.toList()); + Name name = data.getSingularName(); + if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName(getAddMethodName(), name.toString())); + + finishAndInjectMethod(maker, returnType, builderType, source, mods, body, name, params); } protected JCVariableDecl generateSingularMethodParameter(int typeIndex, JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source, Name name) { @@ -285,16 +291,6 @@ public class JavacSingularsRecipes { return maker.Exec(invokeAdd); } - protected void finishAndInjectSingularMethod(JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent, boolean deprecate, ListBuffer statements, List params, String addMethodName) { - JCModifiers mods = makeMods(maker, builderType, deprecate); - 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 ListBuffer generateSingularMethodStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source); protected abstract List generateSingularMethodParameters(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source); -- cgit From 36653329e51cd478199a2d74da6ec5ee471d9cac Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Thu, 10 Jan 2019 05:00:59 +0100 Subject: Move single-use variable declarations to just before use --- src/core/lombok/javac/handlers/JavacSingularsRecipes.java | 4 ++-- src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java | 2 +- .../javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java | 2 +- .../lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java index db03c77a..a32a64be 100644 --- a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java +++ b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java @@ -250,7 +250,6 @@ public class JavacSingularsRecipes { } protected void generateClearMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source) { - JCModifiers mods = makeMods(maker, builderType, deprecate); List params = List.nil(); @@ -259,6 +258,7 @@ public class JavacSingularsRecipes { JCBlock body = maker.Block(0, statements); Name methodName = builderType.toName(HandlerUtil.buildAccessorName("clear", data.getPluralName().toString())); + JCModifiers mods = makeMods(maker, builderType, deprecate); finishAndInjectMethod(maker, returnType, builderType, source, mods, body, methodName, params); } @@ -267,12 +267,12 @@ public class JavacSingularsRecipes { void generateSingularMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) { ListBuffer statements = generateSingularMethodStatements(maker, data, builderType, source); List params = generateSingularMethodParameters(maker, data, builderType, source); - JCModifiers mods = makeMods(maker, builderType, deprecate); if (returnStatement != null) statements.append(returnStatement); JCBlock body = maker.Block(0, statements.toList()); Name name = data.getSingularName(); if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName(getAddMethodName(), name.toString())); + JCModifiers mods = makeMods(maker, builderType, deprecate); finishAndInjectMethod(maker, returnType, builderType, source, mods, body, name, params); } diff --git a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java index b192564c..c493e08f 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java @@ -120,7 +120,6 @@ abstract class JavacGuavaSingularizer extends JavacSingularizer { @Override protected void generatePluralMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) { - JCModifiers mods = makeMods(maker, builderType, deprecate); ListBuffer statements = new ListBuffer(); statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, source)); JCExpression thisDotFieldDotAddAll = chainDots(builderType, "this", data.getPluralName().toString(), getAddMethodName() + "All"); @@ -140,6 +139,7 @@ abstract class JavacGuavaSingularizer extends JavacSingularizer { } paramType = addTypeArgs(getTypeArgumentsCount(), true, builderType, paramType, data.getTypeArgs(), source); JCVariableDecl param = maker.VarDef(maker.Modifiers(paramFlags), data.getPluralName(), paramType, null); + JCModifiers mods = makeMods(maker, builderType, deprecate); finishAndInjectMethod(maker, returnType, builderType, source, mods, body, methodName, List.of(param)); } diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java index 2f9bd0b7..0d88e662 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java @@ -112,7 +112,6 @@ abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularize @Override protected void generatePluralMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) { - JCModifiers mods = makeMods(maker, builderType, deprecate); ListBuffer statements = new ListBuffer(); statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, false, source)); JCExpression thisDotFieldDotAdd = chainDots(builderType, "this", data.getPluralName().toString(), "addAll"); @@ -126,6 +125,7 @@ abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularize JCExpression paramType = chainDots(builderType, "java", "util", "Collection"); paramType = addTypeArgs(1, true, builderType, paramType, data.getTypeArgs(), source); JCVariableDecl param = maker.VarDef(maker.Modifiers(paramFlags), data.getPluralName(), paramType, null); + JCModifiers mods = makeMods(maker, builderType, deprecate); finishAndInjectMethod(maker, returnType, builderType, source, mods, body, name, List.of(param)); } diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java index 4bd771a4..f849203e 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java @@ -149,7 +149,6 @@ 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) { List jceBlank = List.nil(); - JCModifiers mods = makeMods(maker, builderType, deprecate); ListBuffer statements = new ListBuffer(); statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, true, source)); long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext()); @@ -174,6 +173,7 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { JCExpression paramType = chainDots(builderType, "java", "util", "Map"); paramType = addTypeArgs(2, true, builderType, paramType, data.getTypeArgs(), source); JCVariableDecl param = maker.VarDef(maker.Modifiers(paramFlags), data.getPluralName(), paramType, null); + JCModifiers mods = makeMods(maker, builderType, deprecate); finishAndInjectMethod(maker, returnType, builderType, source, mods, body, name, List.of(param)); } -- cgit From fe143bfd69f70749f4e745c5be6644c37840083f Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Thu, 10 Jan 2019 05:03:17 +0100 Subject: Move invariant parameter inside finishAndInjectMethod --- src/core/lombok/javac/handlers/JavacSingularsRecipes.java | 9 ++++----- .../lombok/javac/handlers/singulars/JavacGuavaSingularizer.java | 3 +-- .../handlers/singulars/JavacJavaUtilListSetSingularizer.java | 3 +-- .../javac/handlers/singulars/JavacJavaUtilMapSingularizer.java | 3 +-- 4 files changed, 7 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java index a32a64be..69eaf97c 100644 --- a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java +++ b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java @@ -241,7 +241,8 @@ public class JavacSingularsRecipes { generateClearMethod(deprecate, maker, returnTypeMaker.make(), returnStatementMaker.make(), data, builderType, source); } - protected void finishAndInjectMethod(JavacTreeMaker maker, JCExpression returnType, JavacNode builderType, JCTree source, JCModifiers mods, JCBlock body, Name methodName, List jcVariableDecls) { + protected void finishAndInjectMethod(JavacTreeMaker maker, JCExpression returnType, JavacNode builderType, JCTree source, boolean deprecate, JCBlock body, Name methodName, List jcVariableDecls) { + JCModifiers mods = makeMods(maker, builderType, deprecate); List typeParams = List.nil(); List thrown = List.nil(); JCMethodDecl method = maker.MethodDef(mods, methodName, returnType, typeParams, jcVariableDecls, thrown, body, null); @@ -258,8 +259,7 @@ public class JavacSingularsRecipes { JCBlock body = maker.Block(0, statements); Name methodName = builderType.toName(HandlerUtil.buildAccessorName("clear", data.getPluralName().toString())); - JCModifiers mods = makeMods(maker, builderType, deprecate); - finishAndInjectMethod(maker, returnType, builderType, source, mods, body, methodName, params); + finishAndInjectMethod(maker, returnType, builderType, source, deprecate, body, methodName, params); } protected abstract JCStatement generateClearStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType); @@ -272,8 +272,7 @@ public class JavacSingularsRecipes { Name name = data.getSingularName(); if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName(getAddMethodName(), name.toString())); - JCModifiers mods = makeMods(maker, builderType, deprecate); - finishAndInjectMethod(maker, returnType, builderType, source, mods, body, name, params); + finishAndInjectMethod(maker, returnType, builderType, source, deprecate, body, name, params); } protected JCVariableDecl generateSingularMethodParameter(int typeIndex, JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source, Name name) { diff --git a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java index c493e08f..53b5e416 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java @@ -139,8 +139,7 @@ abstract class JavacGuavaSingularizer extends JavacSingularizer { } paramType = addTypeArgs(getTypeArgumentsCount(), true, builderType, paramType, data.getTypeArgs(), source); JCVariableDecl param = maker.VarDef(maker.Modifiers(paramFlags), data.getPluralName(), paramType, null); - JCModifiers mods = makeMods(maker, builderType, deprecate); - finishAndInjectMethod(maker, returnType, builderType, source, mods, body, methodName, List.of(param)); + finishAndInjectMethod(maker, returnType, builderType, source, deprecate, body, methodName, List.of(param)); } @Override public void appendBuildCode(SingularData data, JavacNode builderType, JCTree source, ListBuffer 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 0d88e662..51aaf3f7 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java @@ -125,8 +125,7 @@ abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularize JCExpression paramType = chainDots(builderType, "java", "util", "Collection"); paramType = addTypeArgs(1, true, builderType, paramType, data.getTypeArgs(), source); JCVariableDecl param = maker.VarDef(maker.Modifiers(paramFlags), data.getPluralName(), paramType, null); - JCModifiers mods = makeMods(maker, builderType, deprecate); - finishAndInjectMethod(maker, returnType, builderType, source, mods, body, name, List.of(param)); + finishAndInjectMethod(maker, returnType, builderType, source, deprecate, body, name, 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 f849203e..cbf61225 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java @@ -173,8 +173,7 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { JCExpression paramType = chainDots(builderType, "java", "util", "Map"); paramType = addTypeArgs(2, true, builderType, paramType, data.getTypeArgs(), source); JCVariableDecl param = maker.VarDef(maker.Modifiers(paramFlags), data.getPluralName(), paramType, null); - JCModifiers mods = makeMods(maker, builderType, deprecate); - finishAndInjectMethod(maker, returnType, builderType, source, mods, body, name, List.of(param)); + finishAndInjectMethod(maker, returnType, builderType, source, deprecate, body, name, List.of(param)); } @Override public void appendBuildCode(SingularData data, JavacNode builderType, JCTree source, ListBuffer statements, Name targetVariableName, String builderVariable) { -- cgit From f4b77187afede3f30b4b82939b806b88772c3990 Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Thu, 10 Jan 2019 05:09:04 +0100 Subject: Move single-use variable declarations to just before use --- src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java | 2 +- .../javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java | 3 ++- .../lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java index 53b5e416..fe5a6765 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java @@ -128,7 +128,6 @@ abstract class JavacGuavaSingularizer extends JavacSingularizer { if (returnStatement != null) statements.append(returnStatement); JCBlock body = maker.Block(0, statements.toList()); Name methodName = data.getPluralName(); - long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext()); if (!fluent) methodName = builderType.toName(HandlerUtil.buildAccessorName(getAddMethodName() + "All", methodName.toString())); JCExpression paramType; String aaTypeName = getAddAllTypeName(); @@ -138,6 +137,7 @@ abstract class JavacGuavaSingularizer extends JavacSingularizer { paramType = chainDotsString(builderType, aaTypeName); } paramType = addTypeArgs(getTypeArgumentsCount(), true, builderType, paramType, data.getTypeArgs(), source); + long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext()); JCVariableDecl param = maker.VarDef(maker.Modifiers(paramFlags), data.getPluralName(), paramType, null); finishAndInjectMethod(maker, returnType, builderType, source, deprecate, body, methodName, List.of(param)); } diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java index 51aaf3f7..95b29faf 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java @@ -117,13 +117,14 @@ abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularize JCExpression thisDotFieldDotAdd = chainDots(builderType, "this", data.getPluralName().toString(), "addAll"); JCExpression invokeAdd = maker.Apply(List.nil(), thisDotFieldDotAdd, List.of(maker.Ident(data.getPluralName()))); statements.append(maker.Exec(invokeAdd)); + if (returnStatement != null) statements.append(returnStatement); JCBlock body = maker.Block(0, statements.toList()); Name name = data.getPluralName(); - long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext()); if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName("addAll", name.toString())); JCExpression paramType = chainDots(builderType, "java", "util", "Collection"); paramType = addTypeArgs(1, true, builderType, paramType, data.getTypeArgs(), source); + long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext()); JCVariableDecl param = maker.VarDef(maker.Modifiers(paramFlags), data.getPluralName(), paramType, null); finishAndInjectMethod(maker, returnType, builderType, source, deprecate, body, name, List.of(param)); } diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java index cbf61225..610f041d 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java @@ -151,7 +151,6 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { List jceBlank = List.nil(); ListBuffer statements = new ListBuffer(); statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, true, source)); - long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext()); long baseFlags = JavacHandlerUtil.addFinalIfNeeded(0, builderType.getContext()); Name entryName = builderType.toName("$lombokEntry"); @@ -172,6 +171,7 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName("putAll", name.toString())); JCExpression paramType = chainDots(builderType, "java", "util", "Map"); paramType = addTypeArgs(2, true, builderType, paramType, data.getTypeArgs(), source); + long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext()); JCVariableDecl param = maker.VarDef(maker.Modifiers(paramFlags), data.getPluralName(), paramType, null); finishAndInjectMethod(maker, returnType, builderType, source, deprecate, body, name, List.of(param)); } -- cgit From 749b8a5d1472ff49ca2ad5219d0c7f5f0b98d6a3 Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Thu, 10 Jan 2019 05:16:46 +0100 Subject: Extract method getPluralMethodParamType --- .../handlers/singulars/JavacGuavaSingularizer.java | 18 ++++++++++++------ .../singulars/JavacJavaUtilListSetSingularizer.java | 6 +++++- .../singulars/JavacJavaUtilMapSingularizer.java | 8 ++++++-- 3 files changed, 23 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java index fe5a6765..96a40090 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java @@ -125,10 +125,19 @@ abstract class JavacGuavaSingularizer extends JavacSingularizer { JCExpression thisDotFieldDotAddAll = chainDots(builderType, "this", data.getPluralName().toString(), getAddMethodName() + "All"); JCExpression invokeAddAll = maker.Apply(List.nil(), thisDotFieldDotAddAll, List.of(maker.Ident(data.getPluralName()))); statements.append(maker.Exec(invokeAddAll)); + if (returnStatement != null) statements.append(returnStatement); JCBlock body = maker.Block(0, statements.toList()); Name methodName = data.getPluralName(); if (!fluent) methodName = builderType.toName(HandlerUtil.buildAccessorName(getAddMethodName() + "All", methodName.toString())); + JCExpression paramType = getPluralMethodParamType(builderType); + paramType = addTypeArgs(getTypeArgumentsCount(), true, builderType, paramType, data.getTypeArgs(), source); + long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext()); + JCVariableDecl param = maker.VarDef(maker.Modifiers(paramFlags), data.getPluralName(), paramType, null); + finishAndInjectMethod(maker, returnType, builderType, source, deprecate, body, methodName, List.of(param)); + } + + private JCExpression getPluralMethodParamType(JavacNode builderType) { JCExpression paramType; String aaTypeName = getAddAllTypeName(); if (aaTypeName.startsWith("java.lang.") && aaTypeName.indexOf('.', 11) == -1) { @@ -136,12 +145,9 @@ abstract class JavacGuavaSingularizer extends JavacSingularizer { } else { paramType = chainDotsString(builderType, aaTypeName); } - paramType = addTypeArgs(getTypeArgumentsCount(), true, builderType, paramType, data.getTypeArgs(), source); - long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext()); - JCVariableDecl param = maker.VarDef(maker.Modifiers(paramFlags), data.getPluralName(), paramType, null); - finishAndInjectMethod(maker, returnType, builderType, source, deprecate, body, methodName, List.of(param)); - } - + return paramType; + } + @Override public void appendBuildCode(SingularData data, JavacNode builderType, JCTree source, ListBuffer statements, Name targetVariableName, String builderVariable) { JavacTreeMaker maker = builderType.getTreeMaker(); List jceBlank = List.nil(); diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java index 95b29faf..e870142c 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java @@ -122,13 +122,17 @@ abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularize JCBlock body = maker.Block(0, statements.toList()); Name name = data.getPluralName(); if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName("addAll", name.toString())); - JCExpression paramType = chainDots(builderType, "java", "util", "Collection"); + JCExpression paramType = getPluralMethodParamType(builderType); paramType = addTypeArgs(1, true, builderType, paramType, data.getTypeArgs(), source); long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext()); JCVariableDecl param = maker.VarDef(maker.Modifiers(paramFlags), data.getPluralName(), paramType, null); finishAndInjectMethod(maker, returnType, builderType, source, deprecate, body, name, List.of(param)); } + private JCExpression getPluralMethodParamType(JavacNode builderType) { + return chainDots(builderType, "java", "util", "Collection"); + } + @Override protected String getAddMethodName() { return "add"; diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java index 610f041d..94938288 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java @@ -169,13 +169,17 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { JCBlock body = maker.Block(0, statements.toList()); Name name = data.getPluralName(); if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName("putAll", name.toString())); - JCExpression paramType = chainDots(builderType, "java", "util", "Map"); + JCExpression paramType = getPluralMethodParamType(builderType); paramType = addTypeArgs(2, true, builderType, paramType, data.getTypeArgs(), source); long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext()); JCVariableDecl param = maker.VarDef(maker.Modifiers(paramFlags), data.getPluralName(), paramType, null); finishAndInjectMethod(maker, returnType, builderType, source, deprecate, body, name, List.of(param)); } - + + private JCExpression getPluralMethodParamType(JavacNode builderType) { + return chainDots(builderType, "java", "util", "Map"); + } + @Override public void appendBuildCode(SingularData data, JavacNode builderType, JCTree source, ListBuffer statements, Name targetVariableName, String builderVariable) { if (useGuavaInstead(builderType)) { guavaMapSingularizer.appendBuildCode(data, builderType, source, statements, targetVariableName, builderVariable); -- cgit From c502090813dcbe73617643f8affebcc776a6dd6c Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Thu, 10 Jan 2019 05:19:35 +0100 Subject: Extract method getTypeArgumentsCount --- .../javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java | 6 +++++- .../javac/handlers/singulars/JavacJavaUtilMapSingularizer.java | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java index e870142c..652e63f3 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java @@ -123,7 +123,7 @@ abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularize Name name = data.getPluralName(); if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName("addAll", name.toString())); JCExpression paramType = getPluralMethodParamType(builderType); - paramType = addTypeArgs(1, true, builderType, paramType, data.getTypeArgs(), source); + paramType = addTypeArgs(getTypeArgumentsCount(), true, builderType, paramType, data.getTypeArgs(), source); long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext()); JCVariableDecl param = maker.VarDef(maker.Modifiers(paramFlags), data.getPluralName(), paramType, null); finishAndInjectMethod(maker, returnType, builderType, source, deprecate, body, name, List.of(param)); @@ -137,4 +137,8 @@ abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularize protected String getAddMethodName() { return "add"; } + + private int getTypeArgumentsCount() { + return 1; + } } diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java index 94938288..4bef2f1d 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java @@ -170,7 +170,7 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { Name name = data.getPluralName(); if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName("putAll", name.toString())); JCExpression paramType = getPluralMethodParamType(builderType); - paramType = addTypeArgs(2, true, builderType, paramType, data.getTypeArgs(), source); + paramType = addTypeArgs(getTypeArgumentsCount(), true, builderType, paramType, data.getTypeArgs(), source); long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext()); JCVariableDecl param = maker.VarDef(maker.Modifiers(paramFlags), data.getPluralName(), paramType, null); finishAndInjectMethod(maker, returnType, builderType, source, deprecate, body, name, List.of(param)); @@ -199,4 +199,8 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { protected String getAddMethodName() { return "put"; } + + private int getTypeArgumentsCount() { + return 2; + } } -- cgit From e0b6dae52106f399ac9020f590119a1ec11a3636 Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Thu, 10 Jan 2019 05:20:53 +0100 Subject: Extract references to getAddMethodName --- .../javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java | 4 ++-- .../lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java index 652e63f3..9b8e32d1 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java @@ -114,14 +114,14 @@ abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularize protected void generatePluralMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) { ListBuffer statements = new ListBuffer(); statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, false, source)); - JCExpression thisDotFieldDotAdd = chainDots(builderType, "this", data.getPluralName().toString(), "addAll"); + JCExpression thisDotFieldDotAdd = chainDots(builderType, "this", data.getPluralName().toString(), getAddMethodName() + "All"); JCExpression invokeAdd = maker.Apply(List.nil(), thisDotFieldDotAdd, List.of(maker.Ident(data.getPluralName()))); statements.append(maker.Exec(invokeAdd)); if (returnStatement != null) statements.append(returnStatement); JCBlock body = maker.Block(0, statements.toList()); Name name = data.getPluralName(); - if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName("addAll", name.toString())); + if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName(getAddMethodName() + "All", name.toString())); JCExpression paramType = getPluralMethodParamType(builderType); paramType = addTypeArgs(getTypeArgumentsCount(), true, builderType, paramType, data.getTypeArgs(), source); long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext()); diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java index 4bef2f1d..8270bae7 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java @@ -168,7 +168,7 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { if (returnStatement != null) statements.append(returnStatement); JCBlock body = maker.Block(0, statements.toList()); Name name = data.getPluralName(); - if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName("putAll", name.toString())); + if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName(getAddMethodName() + "All", name.toString())); JCExpression paramType = getPluralMethodParamType(builderType); paramType = addTypeArgs(getTypeArgumentsCount(), true, builderType, paramType, data.getTypeArgs(), source); long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext()); -- cgit From fe11913fa6ecbf3cec06263dcb0fef08a2eb8cce Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Thu, 10 Jan 2019 05:26:24 +0100 Subject: Extract overloaded method createConstructBuilderVarIfNeeded --- .../handlers/singulars/JavacJavaUtilListSetSingularizer.java | 8 ++++++-- .../javac/handlers/singulars/JavacJavaUtilMapSingularizer.java | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java index 9b8e32d1..2ae4b32b 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java @@ -99,7 +99,7 @@ abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularize @Override protected ListBuffer generateSingularMethodStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) { ListBuffer statements = new ListBuffer(); - statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, false, source)); + statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, source)); statements.append(generateSingularMethodAddStatement(maker, builderType, data.getSingularName(), data.getPluralName().toString())); return statements; } @@ -113,7 +113,7 @@ abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularize @Override protected void generatePluralMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) { ListBuffer statements = new ListBuffer(); - statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, false, source)); + statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, source)); JCExpression thisDotFieldDotAdd = chainDots(builderType, "this", data.getPluralName().toString(), getAddMethodName() + "All"); JCExpression invokeAdd = maker.Apply(List.nil(), thisDotFieldDotAdd, List.of(maker.Ident(data.getPluralName()))); statements.append(maker.Exec(invokeAdd)); @@ -133,6 +133,10 @@ abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularize return chainDots(builderType, "java", "util", "Collection"); } + private JCStatement createConstructBuilderVarIfNeeded(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) { + return createConstructBuilderVarIfNeeded(maker, data, builderType, false, source); + } + @Override protected String getAddMethodName() { return "add"; diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java index 8270bae7..d92923c1 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java @@ -129,7 +129,7 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { Name keyName = builderType.toName(data.getSingularName().toString() + "Key"); Name valueName = builderType.toName(data.getSingularName().toString() + "Value"); - statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, true, source)); + statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, source)); /* Generates: this.pluralname$key.add(singularnameKey); */ statements.append(generateSingularMethodAddStatement(maker, builderType, keyName, data.getPluralName() + "$key")); /* Generates: this.pluralname$value.add(singularnameValue); */ @@ -150,7 +150,7 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { protected void generatePluralMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) { List jceBlank = List.nil(); ListBuffer statements = new ListBuffer(); - statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, true, source)); + statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, source)); long baseFlags = JavacHandlerUtil.addFinalIfNeeded(0, builderType.getContext()); Name entryName = builderType.toName("$lombokEntry"); @@ -180,6 +180,10 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { return chainDots(builderType, "java", "util", "Map"); } + private JCStatement createConstructBuilderVarIfNeeded(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) { + return createConstructBuilderVarIfNeeded(maker, data, builderType, true, source); + } + @Override public void appendBuildCode(SingularData data, JavacNode builderType, JCTree source, ListBuffer statements, Name targetVariableName, String builderVariable) { if (useGuavaInstead(builderType)) { guavaMapSingularizer.appendBuildCode(data, builderType, source, statements, targetVariableName, builderVariable); -- cgit From af3226ffaaf1277a217fc8c9fbe3c1259a561c78 Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Thu, 10 Jan 2019 05:28:51 +0100 Subject: Pull overloaded createConstructBuilderVarIfNeeded up to JavacSingularizer --- src/core/lombok/javac/handlers/JavacSingularsRecipes.java | 2 ++ src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java | 3 ++- .../javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java | 3 ++- .../lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java | 3 ++- 4 files changed, 8 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java index 69eaf97c..59f38ff2 100644 --- a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java +++ b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java @@ -296,6 +296,8 @@ public class JavacSingularsRecipes { protected abstract void generatePluralMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent); + protected abstract JCStatement createConstructBuilderVarIfNeeded(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source); + public abstract void appendBuildCode(SingularData data, JavacNode builderType, JCTree source, ListBuffer statements, Name targetVariableName, String builderVariable); public boolean requiresCleaning() { diff --git a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java index 96a40090..425510c2 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java @@ -178,7 +178,8 @@ abstract class JavacGuavaSingularizer extends JavacSingularizer { JCStatement jcs = maker.VarDef(maker.Modifiers(0), data.getPluralName(), varType, init); statements.append(jcs); } - + + @Override protected JCStatement createConstructBuilderVarIfNeeded(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) { List jceBlank = List.nil(); diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java index 2ae4b32b..115bb7f7 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java @@ -133,7 +133,8 @@ abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularize return chainDots(builderType, "java", "util", "Collection"); } - private JCStatement createConstructBuilderVarIfNeeded(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) { + @Override + protected JCStatement createConstructBuilderVarIfNeeded(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) { return createConstructBuilderVarIfNeeded(maker, data, builderType, false, source); } diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java index d92923c1..4a03961c 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java @@ -180,7 +180,8 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { return chainDots(builderType, "java", "util", "Map"); } - private JCStatement createConstructBuilderVarIfNeeded(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) { + @Override + protected JCStatement createConstructBuilderVarIfNeeded(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) { return createConstructBuilderVarIfNeeded(maker, data, builderType, true, source); } -- cgit From b227bcb487471631fffb6e33999986d4fa1013b2 Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Thu, 10 Jan 2019 05:34:24 +0100 Subject: Pull generatePluralMethod implementation up to JavacSingularizer --- .../javac/handlers/JavacSingularsRecipes.java | 22 ++++++++++++++++++++- .../handlers/singulars/JavacGuavaSingularizer.java | 23 +++------------------- .../JavacJavaUtilListSetSingularizer.java | 23 +++------------------- .../singulars/JavacJavaUtilMapSingularizer.java | 6 ++++-- 4 files changed, 31 insertions(+), 43 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java index 59f38ff2..13b2bb67 100644 --- a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java +++ b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java @@ -294,7 +294,25 @@ public class JavacSingularsRecipes { protected abstract List generateSingularMethodParameters(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source); - protected abstract void generatePluralMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent); + protected void generatePluralMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) { + ListBuffer statements = new ListBuffer(); + statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, source)); + JCExpression thisDotFieldDotAdd = chainDots(builderType, "this", data.getPluralName().toString(), getAddMethodName() + "All"); + JCExpression invokeAdd = maker.Apply(List.nil(), thisDotFieldDotAdd, List.of(maker.Ident(data.getPluralName()))); + statements.append(maker.Exec(invokeAdd)); + + if (returnStatement != null) statements.append(returnStatement); + JCBlock body = maker.Block(0, statements.toList()); + Name name = data.getPluralName(); + if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName(getAddMethodName() + "All", name.toString())); + JCExpression paramType = getPluralMethodParamType(builderType); + paramType = addTypeArgs(getTypeArgumentsCount(), true, builderType, paramType, data.getTypeArgs(), source); + long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext()); + JCVariableDecl param = maker.VarDef(maker.Modifiers(paramFlags), data.getPluralName(), paramType, null); + finishAndInjectMethod(maker, returnType, builderType, source, deprecate, body, name, List.of(param)); + } + + protected abstract JCExpression getPluralMethodParamType(JavacNode builderType); protected abstract JCStatement createConstructBuilderVarIfNeeded(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source); @@ -411,5 +429,7 @@ public class JavacSingularsRecipes { } protected abstract String getAddMethodName(); + + protected abstract int getTypeArgumentsCount(); } } diff --git a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java index 425510c2..aa074994 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java @@ -119,25 +119,7 @@ abstract class JavacGuavaSingularizer extends JavacSingularizer { } @Override - protected void generatePluralMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) { - ListBuffer statements = new ListBuffer(); - statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, source)); - JCExpression thisDotFieldDotAddAll = chainDots(builderType, "this", data.getPluralName().toString(), getAddMethodName() + "All"); - JCExpression invokeAddAll = maker.Apply(List.nil(), thisDotFieldDotAddAll, List.of(maker.Ident(data.getPluralName()))); - statements.append(maker.Exec(invokeAddAll)); - - if (returnStatement != null) statements.append(returnStatement); - JCBlock body = maker.Block(0, statements.toList()); - Name methodName = data.getPluralName(); - if (!fluent) methodName = builderType.toName(HandlerUtil.buildAccessorName(getAddMethodName() + "All", methodName.toString())); - JCExpression paramType = getPluralMethodParamType(builderType); - paramType = addTypeArgs(getTypeArgumentsCount(), true, builderType, paramType, data.getTypeArgs(), source); - long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext()); - JCVariableDecl param = maker.VarDef(maker.Modifiers(paramFlags), data.getPluralName(), paramType, null); - finishAndInjectMethod(maker, returnType, builderType, source, deprecate, body, methodName, List.of(param)); - } - - private JCExpression getPluralMethodParamType(JavacNode builderType) { + protected JCExpression getPluralMethodParamType(JavacNode builderType) { JCExpression paramType; String aaTypeName = getAddAllTypeName(); if (aaTypeName.startsWith("java.lang.") && aaTypeName.indexOf('.', 11) == -1) { @@ -196,7 +178,8 @@ abstract class JavacGuavaSingularizer extends JavacSingularizer { protected abstract LombokImmutableList getArgumentSuffixes(); protected abstract String getAddAllTypeName(); - + + @Override protected int getTypeArgumentsCount() { return getArgumentSuffixes().size(); } diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java index 115bb7f7..e1601970 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java @@ -111,25 +111,7 @@ abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularize } @Override - protected void generatePluralMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) { - ListBuffer statements = new ListBuffer(); - statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, source)); - JCExpression thisDotFieldDotAdd = chainDots(builderType, "this", data.getPluralName().toString(), getAddMethodName() + "All"); - JCExpression invokeAdd = maker.Apply(List.nil(), thisDotFieldDotAdd, List.of(maker.Ident(data.getPluralName()))); - statements.append(maker.Exec(invokeAdd)); - - if (returnStatement != null) statements.append(returnStatement); - JCBlock body = maker.Block(0, statements.toList()); - Name name = data.getPluralName(); - if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName(getAddMethodName() + "All", name.toString())); - JCExpression paramType = getPluralMethodParamType(builderType); - paramType = addTypeArgs(getTypeArgumentsCount(), true, builderType, paramType, data.getTypeArgs(), source); - long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext()); - JCVariableDecl param = maker.VarDef(maker.Modifiers(paramFlags), data.getPluralName(), paramType, null); - finishAndInjectMethod(maker, returnType, builderType, source, deprecate, body, name, List.of(param)); - } - - private JCExpression getPluralMethodParamType(JavacNode builderType) { + protected JCExpression getPluralMethodParamType(JavacNode builderType) { return chainDots(builderType, "java", "util", "Collection"); } @@ -143,7 +125,8 @@ abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularize return "add"; } - private int getTypeArgumentsCount() { + @Override + protected int getTypeArgumentsCount() { return 1; } } diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java index 4a03961c..6792f94e 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java @@ -176,7 +176,8 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { finishAndInjectMethod(maker, returnType, builderType, source, deprecate, body, name, List.of(param)); } - private JCExpression getPluralMethodParamType(JavacNode builderType) { + @Override + protected JCExpression getPluralMethodParamType(JavacNode builderType) { return chainDots(builderType, "java", "util", "Map"); } @@ -205,7 +206,8 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { return "put"; } - private int getTypeArgumentsCount() { + @Override + protected int getTypeArgumentsCount() { return 2; } } -- cgit From 0ef178137759f0a780e3e3f6ea141ee073d96826 Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Thu, 10 Jan 2019 05:37:26 +0100 Subject: Extract method finishAndInjectPluralMethod --- src/core/lombok/javac/handlers/JavacSingularsRecipes.java | 6 +++++- .../handlers/singulars/JavacJavaUtilMapSingularizer.java | 12 ++---------- 2 files changed, 7 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java index 13b2bb67..62513bc1 100644 --- a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java +++ b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java @@ -241,7 +241,7 @@ public class JavacSingularsRecipes { generateClearMethod(deprecate, maker, returnTypeMaker.make(), returnStatementMaker.make(), data, builderType, source); } - protected void finishAndInjectMethod(JavacTreeMaker maker, JCExpression returnType, JavacNode builderType, JCTree source, boolean deprecate, JCBlock body, Name methodName, List jcVariableDecls) { + void finishAndInjectMethod(JavacTreeMaker maker, JCExpression returnType, JavacNode builderType, JCTree source, boolean deprecate, JCBlock body, Name methodName, List jcVariableDecls) { JCModifiers mods = makeMods(maker, builderType, deprecate); List typeParams = List.nil(); List thrown = List.nil(); @@ -301,6 +301,10 @@ public class JavacSingularsRecipes { JCExpression invokeAdd = maker.Apply(List.nil(), thisDotFieldDotAdd, List.of(maker.Ident(data.getPluralName()))); statements.append(maker.Exec(invokeAdd)); + finishAndInjectPluralMethod(deprecate, maker, returnType, returnStatement, data, builderType, source, fluent, statements); + } + + protected void finishAndInjectPluralMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent, ListBuffer 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 6792f94e..d37dd445 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java @@ -164,16 +164,8 @@ 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); - - if (returnStatement != null) statements.append(returnStatement); - JCBlock body = maker.Block(0, statements.toList()); - Name name = data.getPluralName(); - if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName(getAddMethodName() + "All", name.toString())); - JCExpression paramType = getPluralMethodParamType(builderType); - paramType = addTypeArgs(getTypeArgumentsCount(), true, builderType, paramType, data.getTypeArgs(), source); - long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext()); - JCVariableDecl param = maker.VarDef(maker.Modifiers(paramFlags), data.getPluralName(), paramType, null); - finishAndInjectMethod(maker, returnType, builderType, source, deprecate, body, name, List.of(param)); + + finishAndInjectPluralMethod(deprecate, maker, returnType, returnStatement, data, builderType, source, fluent, statements); } @Override -- cgit From bf43cb7cc4280bc9be67f1d1ac018c6d27d4cd39 Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Thu, 10 Jan 2019 05:42:14 +0100 Subject: Extract method generatePluralMethodStatements --- src/core/lombok/javac/handlers/JavacSingularsRecipes.java | 12 ++++++++---- .../handlers/singulars/JavacJavaUtilMapSingularizer.java | 5 ++--- 2 files changed, 10 insertions(+), 7 deletions(-) (limited to 'src') 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 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 statements = generatePluralMethodStatements(maker, data, builderType, source); + finishAndInjectPluralMethod(deprecate, maker, returnType, returnStatement, data, builderType, source, fluent, statements); + } + + protected ListBuffer generatePluralMethodStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) { ListBuffer statements = new ListBuffer(); statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, source)); JCExpression thisDotFieldDotAdd = chainDots(builderType, "this", data.getPluralName().toString(), getAddMethodName() + "All"); JCExpression invokeAdd = maker.Apply(List.nil(), thisDotFieldDotAdd, List.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 statements) { + void finishAndInjectPluralMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent, ListBuffer 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 generatePluralMethodStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) { List jceBlank = List.nil(); ListBuffer statements = new ListBuffer(); 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 -- cgit From 8059a4e383b2c2ebbb8b811d8bb45e5fac2e2d4c Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Thu, 10 Jan 2019 05:42:58 +0100 Subject: Merge finishAndInjectPluralMethod into generatePluralMethod --- .../javac/handlers/JavacSingularsRecipes.java | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java index 96694fa4..058fa38a 100644 --- a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java +++ b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java @@ -296,19 +296,6 @@ public class JavacSingularsRecipes { void generatePluralMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) { ListBuffer statements = generatePluralMethodStatements(maker, data, builderType, source); - finishAndInjectPluralMethod(deprecate, maker, returnType, returnStatement, data, builderType, source, fluent, statements); - } - - protected ListBuffer generatePluralMethodStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) { - ListBuffer statements = new ListBuffer(); - statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, source)); - JCExpression thisDotFieldDotAdd = chainDots(builderType, "this", data.getPluralName().toString(), getAddMethodName() + "All"); - JCExpression invokeAdd = maker.Apply(List.nil(), thisDotFieldDotAdd, List.of(maker.Ident(data.getPluralName()))); - statements.append(maker.Exec(invokeAdd)); - return statements; - } - - void finishAndInjectPluralMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent, ListBuffer statements) { if (returnStatement != null) statements.append(returnStatement); JCBlock body = maker.Block(0, statements.toList()); Name name = data.getPluralName(); @@ -320,6 +307,15 @@ public class JavacSingularsRecipes { finishAndInjectMethod(maker, returnType, builderType, source, deprecate, body, name, List.of(param)); } + protected ListBuffer generatePluralMethodStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) { + ListBuffer statements = new ListBuffer(); + statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, source)); + JCExpression thisDotFieldDotAdd = chainDots(builderType, "this", data.getPluralName().toString(), getAddMethodName() + "All"); + JCExpression invokeAdd = maker.Apply(List.nil(), thisDotFieldDotAdd, List.of(maker.Ident(data.getPluralName()))); + statements.append(maker.Exec(invokeAdd)); + return statements; + } + protected abstract JCExpression getPluralMethodParamType(JavacNode builderType); protected abstract JCStatement createConstructBuilderVarIfNeeded(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source); -- cgit From 683b43257c417fce0c1154eb666eabcf6af5f30c Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Thu, 10 Jan 2019 05:46:38 +0100 Subject: Make generateClearMethod package-private --- src/core/lombok/javac/handlers/JavacSingularsRecipes.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java index 058fa38a..de45649b 100644 --- a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java +++ b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java @@ -250,7 +250,7 @@ public class JavacSingularsRecipes { injectMethod(builderType, method); } - protected void generateClearMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source) { + void generateClearMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source) { List params = List.nil(); -- cgit From e7face9bd6d7660cf37f1c04b9754a1d0352f02e Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Thu, 10 Jan 2019 05:50:35 +0100 Subject: Inline single-use variable --- src/core/lombok/javac/handlers/JavacSingularsRecipes.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java index de45649b..1eb80f29 100644 --- a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java +++ b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java @@ -251,15 +251,12 @@ public class JavacSingularsRecipes { } void generateClearMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source) { - - List params = List.nil(); - JCStatement clearStatement = generateClearStatements(maker, data, builderType); List statements = returnStatement != null ? List.of(clearStatement, returnStatement) : List.of(clearStatement); JCBlock body = maker.Block(0, statements); Name methodName = builderType.toName(HandlerUtil.buildAccessorName("clear", data.getPluralName().toString())); - finishAndInjectMethod(maker, returnType, builderType, source, deprecate, body, methodName, params); + finishAndInjectMethod(maker, returnType, builderType, source, deprecate, body, methodName, List.nil()); } protected abstract JCStatement generateClearStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType); -- cgit From ad4cc0f1831136d1836335020582b0adf6d801a6 Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Thu, 10 Jan 2019 05:53:41 +0100 Subject: Move single-use variable declarations to just before use --- src/core/lombok/javac/handlers/JavacSingularsRecipes.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java index 1eb80f29..0cfeaf4d 100644 --- a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java +++ b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java @@ -254,8 +254,8 @@ public class JavacSingularsRecipes { JCStatement clearStatement = generateClearStatements(maker, data, builderType); List statements = returnStatement != null ? List.of(clearStatement, returnStatement) : List.of(clearStatement); - JCBlock body = maker.Block(0, statements); Name methodName = builderType.toName(HandlerUtil.buildAccessorName("clear", data.getPluralName().toString())); + JCBlock body = maker.Block(0, statements); finishAndInjectMethod(maker, returnType, builderType, source, deprecate, body, methodName, List.nil()); } @@ -265,10 +265,10 @@ public class JavacSingularsRecipes { ListBuffer statements = generateSingularMethodStatements(maker, data, builderType, source); List params = generateSingularMethodParameters(maker, data, builderType, source); if (returnStatement != null) statements.append(returnStatement); - JCBlock body = maker.Block(0, statements.toList()); Name name = data.getSingularName(); if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName(getAddMethodName(), name.toString())); + JCBlock body = maker.Block(0, statements.toList()); finishAndInjectMethod(maker, returnType, builderType, source, deprecate, body, name, params); } @@ -294,13 +294,13 @@ public class JavacSingularsRecipes { void generatePluralMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) { ListBuffer statements = generatePluralMethodStatements(maker, data, builderType, source); if (returnStatement != null) statements.append(returnStatement); - JCBlock body = maker.Block(0, statements.toList()); Name name = data.getPluralName(); if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName(getAddMethodName() + "All", name.toString())); JCExpression paramType = getPluralMethodParamType(builderType); paramType = addTypeArgs(getTypeArgumentsCount(), true, builderType, paramType, data.getTypeArgs(), source); long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext()); JCVariableDecl param = maker.VarDef(maker.Modifiers(paramFlags), data.getPluralName(), paramType, null); + JCBlock body = maker.Block(0, statements.toList()); finishAndInjectMethod(maker, returnType, builderType, source, deprecate, body, name, List.of(param)); } -- cgit From 4c93fcb9fa3c7d4c026fffb4becb6beb7cc508a5 Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Thu, 10 Jan 2019 05:56:52 +0100 Subject: Build statements list in generateClearMethod in the same way as in sibling methods --- src/core/lombok/javac/handlers/JavacSingularsRecipes.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java index 0cfeaf4d..e169e2f9 100644 --- a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java +++ b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java @@ -252,10 +252,12 @@ public class JavacSingularsRecipes { void generateClearMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source) { JCStatement clearStatement = generateClearStatements(maker, data, builderType); - List statements = returnStatement != null ? List.of(clearStatement, returnStatement) : List.of(clearStatement); + ListBuffer statements = new ListBuffer(); + statements.add(clearStatement); + if (returnStatement != null) statements.append(returnStatement); Name methodName = builderType.toName(HandlerUtil.buildAccessorName("clear", data.getPluralName().toString())); - JCBlock body = maker.Block(0, statements); + JCBlock body = maker.Block(0, statements.toList()); finishAndInjectMethod(maker, returnType, builderType, source, deprecate, body, methodName, List.nil()); } -- cgit From 691c855b8962ef78d38ebb6851f5a74b500beab4 Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Thu, 10 Jan 2019 05:58:08 +0100 Subject: Move invariant parameter inside finishAndInjectMethod --- src/core/lombok/javac/handlers/JavacSingularsRecipes.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java index e169e2f9..5f6c4784 100644 --- a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java +++ b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java @@ -241,7 +241,8 @@ public class JavacSingularsRecipes { generateClearMethod(deprecate, maker, returnTypeMaker.make(), returnStatementMaker.make(), data, builderType, source); } - void finishAndInjectMethod(JavacTreeMaker maker, JCExpression returnType, JavacNode builderType, JCTree source, boolean deprecate, JCBlock body, Name methodName, List jcVariableDecls) { + void finishAndInjectMethod(JavacTreeMaker maker, JCExpression returnType, JavacNode builderType, JCTree source, boolean deprecate, ListBuffer statements, Name methodName, List jcVariableDecls) { + JCBlock body = maker.Block(0, statements.toList()); JCModifiers mods = makeMods(maker, builderType, deprecate); List typeParams = List.nil(); List thrown = List.nil(); @@ -257,8 +258,7 @@ public class JavacSingularsRecipes { if (returnStatement != null) statements.append(returnStatement); Name methodName = builderType.toName(HandlerUtil.buildAccessorName("clear", data.getPluralName().toString())); - JCBlock body = maker.Block(0, statements.toList()); - finishAndInjectMethod(maker, returnType, builderType, source, deprecate, body, methodName, List.nil()); + finishAndInjectMethod(maker, returnType, builderType, source, deprecate, statements, methodName, List.nil()); } protected abstract JCStatement generateClearStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType); @@ -270,8 +270,7 @@ public class JavacSingularsRecipes { Name name = data.getSingularName(); if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName(getAddMethodName(), name.toString())); - JCBlock body = maker.Block(0, statements.toList()); - finishAndInjectMethod(maker, returnType, builderType, source, deprecate, body, name, params); + finishAndInjectMethod(maker, returnType, builderType, source, deprecate, statements, name, params); } protected JCVariableDecl generateSingularMethodParameter(int typeIndex, JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source, Name name) { @@ -302,8 +301,7 @@ public class JavacSingularsRecipes { paramType = addTypeArgs(getTypeArgumentsCount(), true, builderType, paramType, data.getTypeArgs(), source); long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext()); JCVariableDecl param = maker.VarDef(maker.Modifiers(paramFlags), data.getPluralName(), paramType, null); - JCBlock body = maker.Block(0, statements.toList()); - finishAndInjectMethod(maker, returnType, builderType, source, deprecate, body, name, List.of(param)); + finishAndInjectMethod(maker, returnType, builderType, source, deprecate, statements, name, List.of(param)); } protected ListBuffer generatePluralMethodStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) { -- cgit From 07e4a3d4cac3e173d61ae49b267e7a87939d9104 Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Thu, 10 Jan 2019 05:59:25 +0100 Subject: Move return statement addition statement to just before finishAndInjectMethod call --- src/core/lombok/javac/handlers/JavacSingularsRecipes.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java index 5f6c4784..d8b53ab5 100644 --- a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java +++ b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java @@ -255,9 +255,9 @@ public class JavacSingularsRecipes { JCStatement clearStatement = generateClearStatements(maker, data, builderType); ListBuffer statements = new ListBuffer(); statements.add(clearStatement); - if (returnStatement != null) statements.append(returnStatement); Name methodName = builderType.toName(HandlerUtil.buildAccessorName("clear", data.getPluralName().toString())); + if (returnStatement != null) statements.append(returnStatement); finishAndInjectMethod(maker, returnType, builderType, source, deprecate, statements, methodName, List.nil()); } @@ -266,10 +266,10 @@ public class JavacSingularsRecipes { void generateSingularMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) { ListBuffer statements = generateSingularMethodStatements(maker, data, builderType, source); List params = generateSingularMethodParameters(maker, data, builderType, source); - if (returnStatement != null) statements.append(returnStatement); Name name = data.getSingularName(); if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName(getAddMethodName(), name.toString())); + if (returnStatement != null) statements.append(returnStatement); finishAndInjectMethod(maker, returnType, builderType, source, deprecate, statements, name, params); } @@ -294,13 +294,13 @@ public class JavacSingularsRecipes { void generatePluralMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) { ListBuffer statements = generatePluralMethodStatements(maker, data, builderType, source); - if (returnStatement != null) statements.append(returnStatement); Name name = data.getPluralName(); if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName(getAddMethodName() + "All", name.toString())); JCExpression paramType = getPluralMethodParamType(builderType); paramType = addTypeArgs(getTypeArgumentsCount(), true, builderType, paramType, data.getTypeArgs(), source); long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext()); JCVariableDecl param = maker.VarDef(maker.Modifiers(paramFlags), data.getPluralName(), paramType, null); + if (returnStatement != null) statements.append(returnStatement); finishAndInjectMethod(maker, returnType, builderType, source, deprecate, statements, name, List.of(param)); } -- cgit From 87bb89177c1ea0e1fb3e757d5d3c6d90f475ad7f Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Thu, 10 Jan 2019 06:00:35 +0100 Subject: Move return statement addition statement inside finishAndInjectMethod --- src/core/lombok/javac/handlers/JavacSingularsRecipes.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java index d8b53ab5..5a5e7258 100644 --- a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java +++ b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java @@ -241,7 +241,8 @@ public class JavacSingularsRecipes { generateClearMethod(deprecate, maker, returnTypeMaker.make(), returnStatementMaker.make(), data, builderType, source); } - void finishAndInjectMethod(JavacTreeMaker maker, JCExpression returnType, JavacNode builderType, JCTree source, boolean deprecate, ListBuffer statements, Name methodName, List jcVariableDecls) { + void finishAndInjectMethod(JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, JavacNode builderType, JCTree source, boolean deprecate, ListBuffer statements, Name methodName, List jcVariableDecls) { + if (returnStatement != null) statements.append(returnStatement); JCBlock body = maker.Block(0, statements.toList()); JCModifiers mods = makeMods(maker, builderType, deprecate); List typeParams = List.nil(); @@ -257,8 +258,7 @@ public class JavacSingularsRecipes { statements.add(clearStatement); Name methodName = builderType.toName(HandlerUtil.buildAccessorName("clear", data.getPluralName().toString())); - if (returnStatement != null) statements.append(returnStatement); - finishAndInjectMethod(maker, returnType, builderType, source, deprecate, statements, methodName, List.nil()); + finishAndInjectMethod(maker, returnType, returnStatement, builderType, source, deprecate, statements, methodName, List.nil()); } protected abstract JCStatement generateClearStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType); @@ -269,8 +269,7 @@ public class JavacSingularsRecipes { Name name = data.getSingularName(); if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName(getAddMethodName(), name.toString())); - if (returnStatement != null) statements.append(returnStatement); - finishAndInjectMethod(maker, returnType, builderType, source, deprecate, statements, name, params); + finishAndInjectMethod(maker, returnType, returnStatement, builderType, source, deprecate, statements, name, params); } protected JCVariableDecl generateSingularMethodParameter(int typeIndex, JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source, Name name) { @@ -300,8 +299,7 @@ public class JavacSingularsRecipes { paramType = addTypeArgs(getTypeArgumentsCount(), true, builderType, paramType, data.getTypeArgs(), source); long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext()); JCVariableDecl param = maker.VarDef(maker.Modifiers(paramFlags), data.getPluralName(), paramType, null); - if (returnStatement != null) statements.append(returnStatement); - finishAndInjectMethod(maker, returnType, builderType, source, deprecate, statements, name, List.of(param)); + finishAndInjectMethod(maker, returnType, returnStatement, builderType, source, deprecate, statements, name, List.of(param)); } protected ListBuffer generatePluralMethodStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) { -- cgit From dc28a8a2d251fe48d414b90abd591b1d36f8bdd6 Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Thu, 10 Jan 2019 06:08:30 +0100 Subject: Make some JavacSingularizer methods private --- src/core/lombok/javac/handlers/JavacSingularsRecipes.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java index 5a5e7258..2f6e97dc 100644 --- a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java +++ b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java @@ -241,7 +241,7 @@ public class JavacSingularsRecipes { generateClearMethod(deprecate, maker, returnTypeMaker.make(), returnStatementMaker.make(), data, builderType, source); } - void finishAndInjectMethod(JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, JavacNode builderType, JCTree source, boolean deprecate, ListBuffer statements, Name methodName, List jcVariableDecls) { + private void finishAndInjectMethod(JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, JavacNode builderType, JCTree source, boolean deprecate, ListBuffer statements, Name methodName, List jcVariableDecls) { if (returnStatement != null) statements.append(returnStatement); JCBlock body = maker.Block(0, statements.toList()); JCModifiers mods = makeMods(maker, builderType, deprecate); @@ -252,7 +252,7 @@ public class JavacSingularsRecipes { injectMethod(builderType, method); } - void generateClearMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source) { + private void generateClearMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source) { JCStatement clearStatement = generateClearStatements(maker, data, builderType); ListBuffer statements = new ListBuffer(); statements.add(clearStatement); @@ -263,7 +263,7 @@ public class JavacSingularsRecipes { protected abstract JCStatement generateClearStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType); - void generateSingularMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) { + private void generateSingularMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) { ListBuffer statements = generateSingularMethodStatements(maker, data, builderType, source); List params = generateSingularMethodParameters(maker, data, builderType, source); Name name = data.getSingularName(); @@ -291,7 +291,7 @@ public class JavacSingularsRecipes { protected abstract List generateSingularMethodParameters(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source); - void generatePluralMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) { + private void generatePluralMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) { ListBuffer statements = generatePluralMethodStatements(maker, data, builderType, source); Name name = data.getPluralName(); if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName(getAddMethodName() + "All", name.toString())); -- cgit From e390aa12047a79e5de2a72170f980f8011789bba Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Sat, 12 Jan 2019 23:01:16 +0100 Subject: Remove unused imports --- src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java | 3 --- .../javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java | 3 --- .../lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java | 2 -- 3 files changed, 8 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java index aa074994..8b057875 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java @@ -28,7 +28,6 @@ import java.util.Collections; import lombok.core.GuavaTypeMap; import lombok.core.LombokImmutableList; -import lombok.core.handlers.HandlerUtil; import lombok.javac.JavacNode; import lombok.javac.JavacTreeMaker; import lombok.javac.handlers.JavacHandlerUtil; @@ -39,9 +38,7 @@ 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.JCBlock; import com.sun.tools.javac.tree.JCTree.JCExpression; -import com.sun.tools.javac.tree.JCTree.JCModifiers; import com.sun.tools.javac.tree.JCTree.JCStatement; import com.sun.tools.javac.tree.JCTree.JCVariableDecl; import com.sun.tools.javac.util.List; diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java index e1601970..6fe457f0 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java @@ -26,7 +26,6 @@ import static lombok.javac.handlers.JavacHandlerUtil.*; import java.util.Collections; -import lombok.core.handlers.HandlerUtil; import lombok.javac.JavacNode; import lombok.javac.JavacTreeMaker; import lombok.javac.handlers.JavacHandlerUtil; @@ -36,9 +35,7 @@ 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.JCBlock; import com.sun.tools.javac.tree.JCTree.JCExpression; -import com.sun.tools.javac.tree.JCTree.JCModifiers; import com.sun.tools.javac.tree.JCTree.JCStatement; import com.sun.tools.javac.tree.JCTree.JCVariableDecl; import com.sun.tools.javac.util.List; diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java index c2010e0c..f087a00f 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java @@ -27,7 +27,6 @@ import static lombok.javac.handlers.JavacHandlerUtil.*; import java.util.Arrays; import lombok.core.LombokImmutableList; -import lombok.core.handlers.HandlerUtil; import lombok.javac.JavacNode; import lombok.javac.JavacTreeMaker; import lombok.javac.handlers.JavacHandlerUtil; @@ -42,7 +41,6 @@ import com.sun.tools.javac.code.Flags; import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.tree.JCTree.JCBlock; import com.sun.tools.javac.tree.JCTree.JCExpression; -import com.sun.tools.javac.tree.JCTree.JCModifiers; import com.sun.tools.javac.tree.JCTree.JCStatement; import com.sun.tools.javac.tree.JCTree.JCVariableDecl; import com.sun.tools.javac.util.List; -- cgit From a633e395883d5d24806204a0c10d2ae5b008b8d8 Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Sun, 13 Jan 2019 00:19:57 +0100 Subject: Replace JavacSingularizers with Guava version once and for all --- src/core/lombok/javac/handlers/HandleBuilder.java | 2 +- .../lombok/javac/handlers/HandleSuperBuilder.java | 2 +- .../javac/handlers/JavacSingularsRecipes.java | 8 ++++-- .../JavacJavaUtilListSetSingularizer.java | 27 +++++++----------- .../singulars/JavacJavaUtilListSingularizer.java | 5 ---- .../singulars/JavacJavaUtilMapSingularizer.java | 32 ++++++---------------- .../singulars/JavacJavaUtilSetSingularizer.java | 5 ---- 7 files changed, 27 insertions(+), 54 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/HandleBuilder.java b/src/core/lombok/javac/handlers/HandleBuilder.java index 83a44cca..1038f116 100644 --- a/src/core/lombok/javac/handlers/HandleBuilder.java +++ b/src/core/lombok/javac/handlers/HandleBuilder.java @@ -788,7 +788,7 @@ public class HandleBuilder extends JavacAnnotationHandler { name = type.toString(); String targetFqn = JavacSingularsRecipes.get().toQualified(name); - JavacSingularizer singularizer = JavacSingularsRecipes.get().getSingularizer(targetFqn); + JavacSingularizer singularizer = JavacSingularsRecipes.get().getSingularizer(targetFqn, node); if (singularizer == null) { node.addError("Lombok does not know how to create the singular-form builder methods for type '" + name + "'; they won't be generated."); return null; diff --git a/src/core/lombok/javac/handlers/HandleSuperBuilder.java b/src/core/lombok/javac/handlers/HandleSuperBuilder.java index 72437814..7ef6b658 100644 --- a/src/core/lombok/javac/handlers/HandleSuperBuilder.java +++ b/src/core/lombok/javac/handlers/HandleSuperBuilder.java @@ -919,7 +919,7 @@ public class HandleSuperBuilder extends JavacAnnotationHandler { name = type.toString(); String targetFqn = JavacSingularsRecipes.get().toQualified(name); - JavacSingularizer singularizer = JavacSingularsRecipes.get().getSingularizer(targetFqn); + JavacSingularizer singularizer = JavacSingularsRecipes.get().getSingularizer(targetFqn, node); if (singularizer == null) { node.addError("Lombok does not know how to create the singular-form builder methods for type '" + name + "'; they won't be generated."); return null; diff --git a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java index 2f6e97dc..28f8c69c 100644 --- a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java +++ b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java @@ -101,8 +101,8 @@ public class JavacSingularsRecipes { return singularizableTypes.toQualified(typeReference); } - public JavacSingularizer getSingularizer(String fqn) { - return singularizers.get(fqn); + public JavacSingularizer getSingularizer(String fqn, JavacNode node) { + return singularizers.get(fqn).getGuavaInsteadIfNeeded(node); } public static final class SingularData { @@ -154,6 +154,10 @@ public class JavacSingularsRecipes { public static abstract class JavacSingularizer { public abstract LombokImmutableList getSupportedTypes(); + + protected JavacSingularizer getGuavaInsteadIfNeeded(JavacNode node) { + return this; + } protected JCModifiers makeMods(JavacTreeMaker maker, JavacNode node, boolean deprecate) { if (deprecate) return maker.Modifiers(Flags.PUBLIC, List.of(maker.Annotation(genJavaLangTypeRef(node, "Deprecated"), List.nil()))); diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java index 6fe457f0..856a2295 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java @@ -30,6 +30,7 @@ import lombok.javac.JavacNode; import lombok.javac.JavacTreeMaker; import lombok.javac.handlers.JavacHandlerUtil; import lombok.javac.handlers.JavacSingularsRecipes.ExpressionMaker; +import lombok.javac.handlers.JavacSingularsRecipes.JavacSingularizer; import lombok.javac.handlers.JavacSingularsRecipes.SingularData; import lombok.javac.handlers.JavacSingularsRecipes.StatementMaker; @@ -43,27 +44,24 @@ import com.sun.tools.javac.util.ListBuffer; import com.sun.tools.javac.util.Name; abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularizer { - @Override public java.util.List listFieldsToBeGenerated(SingularData data, JavacNode builderType) { - if (useGuavaInstead(builderType)) { - return guavaListSetSingularizer.listFieldsToBeGenerated(data, builderType); + + @Override + protected JavacSingularizer getGuavaInsteadIfNeeded(JavacNode node) { + if (useGuavaInstead(node)) { + return guavaListSetSingularizer; } - + return this; + } + + @Override public java.util.List listFieldsToBeGenerated(SingularData data, JavacNode builderType) { return super.listFieldsToBeGenerated(data, builderType); } @Override public java.util.List listMethodsToBeGenerated(SingularData data, JavacNode builderType) { - if (useGuavaInstead(builderType)) { - return guavaListSetSingularizer.listMethodsToBeGenerated(data, builderType); - } - return super.listMethodsToBeGenerated(data, builderType); } @Override public java.util.List generateFields(SingularData data, JavacNode builderType, JCTree source) { - if (useGuavaInstead(builderType)) { - return guavaListSetSingularizer.generateFields(data, builderType, source); - } - JavacTreeMaker maker = builderType.getTreeMaker(); JCExpression type = JavacHandlerUtil.chainDots(builderType, "java", "util", "ArrayList"); type = addTypeArgs(1, false, builderType, type, data.getTypeArgs(), source); @@ -73,11 +71,6 @@ abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularize } @Override public void generateMethods(SingularData data, boolean deprecate, JavacNode builderType, JCTree source, boolean fluent, ExpressionMaker returnTypeMaker, StatementMaker returnStatementMaker) { - if (useGuavaInstead(builderType)) { - guavaListSetSingularizer.generateMethods(data, deprecate, builderType, source, fluent, returnTypeMaker, returnStatementMaker); - return; - } - doGenerateMethods(data, deprecate, builderType, source, fluent, returnTypeMaker, returnStatementMaker); } diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSingularizer.java index b1375151..e5c5a170 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSingularizer.java @@ -47,11 +47,6 @@ public class JavacJavaUtilListSingularizer extends JavacJavaUtilListSetSingulari } @Override public void appendBuildCode(SingularData data, JavacNode builderType, JCTree source, ListBuffer statements, Name targetVariableName, String builderVariable) { - if (useGuavaInstead(builderType)) { - guavaListSetSingularizer.appendBuildCode(data, builderType, source, statements, targetVariableName, builderVariable); - return; - } - JavacTreeMaker maker = builderType.getTreeMaker(); List jceBlank = List.nil(); ListBuffer cases = new ListBuffer(); diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java index f087a00f..c2c1f233 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java @@ -52,29 +52,25 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { @Override public LombokImmutableList getSupportedTypes() { return LombokImmutableList.of("java.util.Map", "java.util.SortedMap", "java.util.NavigableMap"); } - - @Override public java.util.List listFieldsToBeGenerated(SingularData data, JavacNode builderType) { - if (useGuavaInstead(builderType)) { - return guavaMapSingularizer.listFieldsToBeGenerated(data, builderType); + + @Override + protected JavacSingularizer getGuavaInsteadIfNeeded(JavacNode node) { + if (useGuavaInstead(node)) { + return guavaMapSingularizer; } - + return this; + } + + @Override public java.util.List listFieldsToBeGenerated(SingularData data, JavacNode builderType) { String p = data.getPluralName().toString(); return Arrays.asList(builderType.toName(p + "$key"), builderType.toName(p + "$value")); } @Override public java.util.List listMethodsToBeGenerated(SingularData data, JavacNode builderType) { - if (useGuavaInstead(builderType)) { - return guavaMapSingularizer.listMethodsToBeGenerated(data, builderType); - } - return super.listMethodsToBeGenerated(data, builderType); } @Override public java.util.List generateFields(SingularData data, JavacNode builderType, JCTree source) { - if (useGuavaInstead(builderType)) { - return guavaMapSingularizer.generateFields(data, builderType, source); - } - JavacTreeMaker maker = builderType.getTreeMaker(); JCVariableDecl buildKeyField; { @@ -99,11 +95,6 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { } @Override public void generateMethods(SingularData data, boolean deprecate, JavacNode builderType, JCTree source, boolean fluent, ExpressionMaker returnTypeMaker, StatementMaker returnStatementMaker) { - if (useGuavaInstead(builderType)) { - guavaMapSingularizer.generateMethods(data, deprecate, builderType, source, fluent, returnTypeMaker, returnStatementMaker); - return; - } - doGenerateMethods(data, deprecate, builderType, source, fluent, returnTypeMaker, returnStatementMaker); } @@ -176,11 +167,6 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { } @Override public void appendBuildCode(SingularData data, JavacNode builderType, JCTree source, ListBuffer statements, Name targetVariableName, String builderVariable) { - if (useGuavaInstead(builderType)) { - guavaMapSingularizer.appendBuildCode(data, builderType, source, statements, targetVariableName, builderVariable); - return; - } - JavacTreeMaker maker = builderType.getTreeMaker(); if (data.getTargetFqn().equals("java.util.Map")) { diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilSetSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilSetSingularizer.java index 71a36c0e..22d74896 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilSetSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilSetSingularizer.java @@ -41,11 +41,6 @@ public class JavacJavaUtilSetSingularizer extends JavacJavaUtilListSetSingulariz } @Override public void appendBuildCode(SingularData data, JavacNode builderType, JCTree source, ListBuffer statements, Name targetVariableName, String builderVariable) { - if (useGuavaInstead(builderType)) { - guavaListSetSingularizer.appendBuildCode(data, builderType, source, statements, targetVariableName, builderVariable); - return; - } - JavacTreeMaker maker = builderType.getTreeMaker(); if (data.getTargetFqn().equals("java.util.Set")) { -- cgit From f6d2933795d9091d0cace8d81df530967d84a779 Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Sun, 13 Jan 2019 01:12:59 +0100 Subject: Pull useGuavaInstead logic up to JavacSingularizer --- src/core/lombok/javac/handlers/JavacSingularsRecipes.java | 7 +++++-- .../handlers/singulars/JavacJavaUtilListSetSingularizer.java | 8 ++------ .../javac/handlers/singulars/JavacJavaUtilMapSingularizer.java | 8 ++------ .../javac/handlers/singulars/JavacJavaUtilSingularizer.java | 4 ---- 4 files changed, 9 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java index 28f8c69c..6e910b71 100644 --- a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java +++ b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java @@ -32,6 +32,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; +import lombok.ConfigurationKeys; import lombok.core.LombokImmutableList; import lombok.core.SpiLoadUtil; import lombok.core.TypeLibrary; @@ -102,7 +103,9 @@ public class JavacSingularsRecipes { } public JavacSingularizer getSingularizer(String fqn, JavacNode node) { - return singularizers.get(fqn).getGuavaInsteadIfNeeded(node); + final JavacSingularizer singularizer = singularizers.get(fqn); + final boolean useGuavaInstead = Boolean.TRUE.equals(node.getAst().readConfiguration(ConfigurationKeys.SINGULAR_USE_GUAVA)); + return useGuavaInstead ? singularizer.getGuavaInstead(node) : singularizer; } public static final class SingularData { @@ -155,7 +158,7 @@ public class JavacSingularsRecipes { public static abstract class JavacSingularizer { public abstract LombokImmutableList getSupportedTypes(); - protected JavacSingularizer getGuavaInsteadIfNeeded(JavacNode node) { + protected JavacSingularizer getGuavaInstead(JavacNode node) { return this; } diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java index 856a2295..c5cd0738 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java @@ -45,12 +45,8 @@ import com.sun.tools.javac.util.Name; abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularizer { - @Override - protected JavacSingularizer getGuavaInsteadIfNeeded(JavacNode node) { - if (useGuavaInstead(node)) { - return guavaListSetSingularizer; - } - return this; + @Override protected JavacSingularizer getGuavaInstead(JavacNode node) { + return guavaListSetSingularizer; } @Override public java.util.List listFieldsToBeGenerated(SingularData data, JavacNode builderType) { diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java index c2c1f233..69215c11 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java @@ -53,12 +53,8 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { return LombokImmutableList.of("java.util.Map", "java.util.SortedMap", "java.util.NavigableMap"); } - @Override - protected JavacSingularizer getGuavaInsteadIfNeeded(JavacNode node) { - if (useGuavaInstead(node)) { - return guavaMapSingularizer; - } - return this; + @Override protected JavacSingularizer getGuavaInstead(JavacNode node) { + return guavaMapSingularizer; } @Override public java.util.List listFieldsToBeGenerated(SingularData data, JavacNode builderType) { diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilSingularizer.java index df521fd8..47098467 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilSingularizer.java @@ -42,10 +42,6 @@ abstract class JavacJavaUtilSingularizer extends JavacSingularizer { protected final JavacSingularizer guavaListSetSingularizer = new JavacGuavaSetListSingularizer(); protected final JavacSingularizer guavaMapSingularizer = new JavacGuavaMapSingularizer(); - protected boolean useGuavaInstead(JavacNode node) { - return Boolean.TRUE.equals(node.getAst().readConfiguration(ConfigurationKeys.SINGULAR_USE_GUAVA)); - } - protected List createJavaUtilSetMapInitialCapacitySwitchStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType, boolean mapMode, String emptyCollectionMethod, String singletonCollectionMethod, String targetType, JCTree source, String builderVariable) { List jceBlank = List.nil(); ListBuffer cases = new ListBuffer(); -- cgit From 258a9bf2886e841f2921208d44bd380d900ccc37 Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Sun, 13 Jan 2019 01:32:55 +0100 Subject: Push Guava singularizer instances down from JavacJavaUtilSingularizer --- .../javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java | 1 + .../lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java | 2 ++ src/core/lombok/javac/handlers/singulars/JavacJavaUtilSingularizer.java | 2 -- 3 files changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java index c5cd0738..26054203 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java @@ -44,6 +44,7 @@ import com.sun.tools.javac.util.ListBuffer; import com.sun.tools.javac.util.Name; abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularizer { + private final JavacSingularizer guavaListSetSingularizer = new JavacGuavaSetListSingularizer(); @Override protected JavacSingularizer getGuavaInstead(JavacNode node) { return guavaListSetSingularizer; diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java index 69215c11..1d4d8eee 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java @@ -49,6 +49,8 @@ import com.sun.tools.javac.util.Name; @ProviderFor(JavacSingularizer.class) public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { + private final JavacSingularizer guavaMapSingularizer = new JavacGuavaMapSingularizer(); + @Override public LombokImmutableList getSupportedTypes() { return LombokImmutableList.of("java.util.Map", "java.util.SortedMap", "java.util.NavigableMap"); } diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilSingularizer.java index 47098467..8c22a41e 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilSingularizer.java @@ -39,8 +39,6 @@ import lombok.javac.handlers.JavacSingularsRecipes.JavacSingularizer; import lombok.javac.handlers.JavacSingularsRecipes.SingularData; abstract class JavacJavaUtilSingularizer extends JavacSingularizer { - protected final JavacSingularizer guavaListSetSingularizer = new JavacGuavaSetListSingularizer(); - protected final JavacSingularizer guavaMapSingularizer = new JavacGuavaMapSingularizer(); protected List createJavaUtilSetMapInitialCapacitySwitchStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType, boolean mapMode, String emptyCollectionMethod, String singletonCollectionMethod, String targetType, JCTree source, String builderVariable) { List jceBlank = List.nil(); -- cgit From 92fc11fd0efdd841f488fda8c937577349dc713c Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Sun, 13 Jan 2019 01:34:24 +0100 Subject: Inline Guava singularizer instances into getGuavaInstead() --- .../javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java | 3 +-- .../lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java index 26054203..3aeab37a 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java @@ -44,10 +44,9 @@ import com.sun.tools.javac.util.ListBuffer; import com.sun.tools.javac.util.Name; abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularizer { - private final JavacSingularizer guavaListSetSingularizer = new JavacGuavaSetListSingularizer(); @Override protected JavacSingularizer getGuavaInstead(JavacNode node) { - return guavaListSetSingularizer; + return new JavacGuavaSetListSingularizer(); } @Override public java.util.List listFieldsToBeGenerated(SingularData data, JavacNode builderType) { diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java index 1d4d8eee..76068570 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java @@ -49,14 +49,13 @@ import com.sun.tools.javac.util.Name; @ProviderFor(JavacSingularizer.class) public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { - private final JavacSingularizer guavaMapSingularizer = new JavacGuavaMapSingularizer(); @Override public LombokImmutableList getSupportedTypes() { return LombokImmutableList.of("java.util.Map", "java.util.SortedMap", "java.util.NavigableMap"); } @Override protected JavacSingularizer getGuavaInstead(JavacNode node) { - return guavaMapSingularizer; + return new JavacGuavaMapSingularizer(); } @Override public java.util.List listFieldsToBeGenerated(SingularData data, JavacNode builderType) { -- cgit From 3285d83e1636c0a21c7aada3bb278419ec2bd83a Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Sun, 13 Jan 2019 02:11:02 +0100 Subject: Pull createConstructBuilderVarIfNeeded calls up to JavacSingularizer --- src/core/lombok/javac/handlers/JavacSingularsRecipes.java | 15 +++++++-------- .../javac/handlers/singulars/JavacGuavaSingularizer.java | 1 - .../singulars/JavacJavaUtilListSetSingularizer.java | 1 - .../handlers/singulars/JavacJavaUtilMapSingularizer.java | 2 -- 4 files changed, 7 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java index 6e910b71..7c707756 100644 --- a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java +++ b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java @@ -248,7 +248,7 @@ public class JavacSingularsRecipes { generateClearMethod(deprecate, maker, returnTypeMaker.make(), returnStatementMaker.make(), data, builderType, source); } - private void finishAndInjectMethod(JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, JavacNode builderType, JCTree source, boolean deprecate, ListBuffer statements, Name methodName, List jcVariableDecls) { + private void finishAndInjectMethod(JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean deprecate, ListBuffer statements, Name methodName, List jcVariableDecls) { if (returnStatement != null) statements.append(returnStatement); JCBlock body = maker.Block(0, statements.toList()); JCModifiers mods = makeMods(maker, builderType, deprecate); @@ -265,7 +265,7 @@ public class JavacSingularsRecipes { statements.add(clearStatement); Name methodName = builderType.toName(HandlerUtil.buildAccessorName("clear", data.getPluralName().toString())); - finishAndInjectMethod(maker, returnType, returnStatement, builderType, source, deprecate, statements, methodName, List.nil()); + finishAndInjectMethod(maker, returnType, returnStatement, data, builderType, source, deprecate, statements, methodName, List.nil()); } protected abstract JCStatement generateClearStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType); @@ -276,7 +276,8 @@ public class JavacSingularsRecipes { Name name = data.getSingularName(); if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName(getAddMethodName(), name.toString())); - finishAndInjectMethod(maker, returnType, returnStatement, builderType, source, deprecate, statements, name, params); + statements.prepend(createConstructBuilderVarIfNeeded(maker, data, builderType, source)); + finishAndInjectMethod(maker, returnType, returnStatement, data, builderType, source, deprecate, statements, name, params); } protected JCVariableDecl generateSingularMethodParameter(int typeIndex, JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source, Name name) { @@ -306,16 +307,14 @@ public class JavacSingularsRecipes { paramType = addTypeArgs(getTypeArgumentsCount(), true, builderType, paramType, data.getTypeArgs(), source); long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext()); JCVariableDecl param = maker.VarDef(maker.Modifiers(paramFlags), data.getPluralName(), paramType, null); - finishAndInjectMethod(maker, returnType, returnStatement, builderType, source, deprecate, statements, name, List.of(param)); + statements.prepend(createConstructBuilderVarIfNeeded(maker, data, builderType, source)); + finishAndInjectMethod(maker, returnType, returnStatement, data, builderType, source, deprecate, statements, name, List.of(param)); } protected ListBuffer generatePluralMethodStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) { - ListBuffer statements = new ListBuffer(); - statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, source)); JCExpression thisDotFieldDotAdd = chainDots(builderType, "this", data.getPluralName().toString(), getAddMethodName() + "All"); JCExpression invokeAdd = maker.Apply(List.nil(), thisDotFieldDotAdd, List.of(maker.Ident(data.getPluralName()))); - statements.append(maker.Exec(invokeAdd)); - return statements; + return new ListBuffer().append(maker.Exec(invokeAdd)); } protected abstract JCExpression getPluralMethodParamType(JavacNode builderType); diff --git a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java index 8b057875..cfdf26a8 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java @@ -91,7 +91,6 @@ abstract class JavacGuavaSingularizer extends JavacSingularizer { ListBuffer statements = new ListBuffer(); Name[] names = generateSingularMethodParameterNames(data, builderType); - statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, source)); JCExpression thisDotFieldDotAdd = chainDots(builderType, "this", data.getPluralName().toString(), getAddMethodName()); ListBuffer invokeAddExprBuilder = new ListBuffer(); for (Name name : names) { diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java index 3aeab37a..0d9d5d0f 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java @@ -85,7 +85,6 @@ abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularize @Override protected ListBuffer generateSingularMethodStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) { ListBuffer statements = new ListBuffer(); - statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, source)); statements.append(generateSingularMethodAddStatement(maker, builderType, data.getSingularName(), data.getPluralName().toString())); return statements; } diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java index 76068570..a35412e9 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java @@ -115,7 +115,6 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { Name keyName = builderType.toName(data.getSingularName().toString() + "Key"); Name valueName = builderType.toName(data.getSingularName().toString() + "Value"); - statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, source)); /* Generates: this.pluralname$key.add(singularnameKey); */ statements.append(generateSingularMethodAddStatement(maker, builderType, keyName, data.getPluralName() + "$key")); /* Generates: this.pluralname$value.add(singularnameValue); */ @@ -136,7 +135,6 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { protected ListBuffer generatePluralMethodStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) { List jceBlank = List.nil(); ListBuffer statements = new ListBuffer(); - statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, source)); long baseFlags = JavacHandlerUtil.addFinalIfNeeded(0, builderType.getContext()); Name entryName = builderType.toName("$lombokEntry"); -- cgit From 4ea8c439e1cc61bca6863ec8cf24e081b939689e Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Sun, 13 Jan 2019 02:42:00 +0100 Subject: Simplify List generateSingularMethodStatements to single expression --- .../javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java index 0d9d5d0f..bbe6eb63 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java @@ -84,9 +84,8 @@ abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularize @Override protected ListBuffer generateSingularMethodStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) { - ListBuffer statements = new ListBuffer(); - statements.append(generateSingularMethodAddStatement(maker, builderType, data.getSingularName(), data.getPluralName().toString())); - return statements; + return new ListBuffer() + .append(generateSingularMethodAddStatement(maker, builderType, data.getSingularName(), data.getPluralName().toString())); } @Override -- cgit From b48af8dce8e76ffb2fb26c8edec8ceafcddb73b6 Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Sun, 13 Jan 2019 02:43:06 +0100 Subject: Simplify Guava generateSingularMethodStatements return statement to single expression --- src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java index cfdf26a8..17be15dc 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java @@ -88,7 +88,6 @@ abstract class JavacGuavaSingularizer extends JavacSingularizer { @Override protected ListBuffer generateSingularMethodStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) { - ListBuffer statements = new ListBuffer(); Name[] names = generateSingularMethodParameterNames(data, builderType); JCExpression thisDotFieldDotAdd = chainDots(builderType, "this", data.getPluralName().toString(), getAddMethodName()); @@ -99,8 +98,8 @@ abstract class JavacGuavaSingularizer extends JavacSingularizer { List invokeAddExpr = invokeAddExprBuilder.toList(); JCExpression invokeAdd = maker.Apply(List.nil(), thisDotFieldDotAdd, invokeAddExpr); JCStatement st = maker.Exec(invokeAdd); - statements.append(st); - return statements; + + return new ListBuffer().append(st); } private Name[] generateSingularMethodParameterNames(SingularData data, JavacNode builderType) { -- cgit From 125b02e84b555d36dd3427919bd02da6ef41ab66 Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Sun, 13 Jan 2019 02:44:01 +0100 Subject: Colocate statements declaration with use in Map generateSingularMethodStatements --- .../lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java index a35412e9..71ddd01d 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java @@ -111,10 +111,10 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { @Override protected ListBuffer generateSingularMethodStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) { - ListBuffer statements = new ListBuffer(); Name keyName = builderType.toName(data.getSingularName().toString() + "Key"); Name valueName = builderType.toName(data.getSingularName().toString() + "Value"); + ListBuffer statements = new ListBuffer(); /* Generates: this.pluralname$key.add(singularnameKey); */ statements.append(generateSingularMethodAddStatement(maker, builderType, keyName, data.getPluralName() + "$key")); /* Generates: this.pluralname$value.add(singularnameValue); */ -- cgit