aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok/javac/handlers
diff options
context:
space:
mode:
authorEmil Lundberg <emil@emlun.se>2019-01-10 05:16:46 +0100
committerEmil Lundberg <emil@emlun.se>2019-01-13 02:26:56 +0100
commit749b8a5d1472ff49ca2ad5219d0c7f5f0b98d6a3 (patch)
treece7beceaa7fb753f9273209fa9a62b7f0cd498d4 /src/core/lombok/javac/handlers
parentf4b77187afede3f30b4b82939b806b88772c3990 (diff)
downloadlombok-749b8a5d1472ff49ca2ad5219d0c7f5f0b98d6a3.tar.gz
lombok-749b8a5d1472ff49ca2ad5219d0c7f5f0b98d6a3.tar.bz2
lombok-749b8a5d1472ff49ca2ad5219d0c7f5f0b98d6a3.zip
Extract method getPluralMethodParamType
Diffstat (limited to 'src/core/lombok/javac/handlers')
-rw-r--r--src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java18
-rw-r--r--src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java6
-rw-r--r--src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java8
3 files changed, 23 insertions, 9 deletions
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.<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) {
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<JCStatement> statements, Name targetVariableName, String builderVariable) {
JavacTreeMaker maker = builderType.getTreeMaker();
List<JCExpression> 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<JCStatement> statements, Name targetVariableName, String builderVariable) {
if (useGuavaInstead(builderType)) {
guavaMapSingularizer.appendBuildCode(data, builderType, source, statements, targetVariableName, builderVariable);