aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEmil Lundberg <emil@emlun.se>2019-01-10 05:34:24 +0100
committerEmil Lundberg <emil@emlun.se>2019-01-13 02:27:33 +0100
commitb227bcb487471631fffb6e33999986d4fa1013b2 (patch)
tree5129bc8dcbbd77d16f727ef3935050bf2a15edc3 /src
parentaf3226ffaaf1277a217fc8c9fbe3c1259a561c78 (diff)
downloadlombok-b227bcb487471631fffb6e33999986d4fa1013b2.tar.gz
lombok-b227bcb487471631fffb6e33999986d4fa1013b2.tar.bz2
lombok-b227bcb487471631fffb6e33999986d4fa1013b2.zip
Pull generatePluralMethod implementation up to JavacSingularizer
Diffstat (limited to 'src')
-rw-r--r--src/core/lombok/javac/handlers/JavacSingularsRecipes.java22
-rw-r--r--src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java23
-rw-r--r--src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java23
-rw-r--r--src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java6
4 files changed, 31 insertions, 43 deletions
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<JCVariableDecl> 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<JCStatement> statements = new ListBuffer<JCStatement>();
+ statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, source));
+ JCExpression thisDotFieldDotAdd = chainDots(builderType, "this", data.getPluralName().toString(), getAddMethodName() + "All");
+ JCExpression invokeAdd = maker.Apply(List.<JCExpression>nil(), thisDotFieldDotAdd, List.<JCExpression>of(maker.Ident(data.getPluralName())));
+ statements.append(maker.Exec(invokeAdd));
+
+ 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<JCStatement> statements = new ListBuffer<JCStatement>();
- statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, source));
- JCExpression thisDotFieldDotAddAll = chainDots(builderType, "this", data.getPluralName().toString(), getAddMethodName() + "All");
- JCExpression invokeAddAll = maker.Apply(List.<JCExpression>nil(), thisDotFieldDotAddAll, List.<JCExpression>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<String> 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<JCStatement> statements = new ListBuffer<JCStatement>();
- statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, source));
- JCExpression thisDotFieldDotAdd = chainDots(builderType, "this", data.getPluralName().toString(), getAddMethodName() + "All");
- JCExpression invokeAdd = maker.Apply(List.<JCExpression>nil(), thisDotFieldDotAdd, List.<JCExpression>of(maker.Ident(data.getPluralName())));
- statements.append(maker.Exec(invokeAdd));
-
- 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;
}
}