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/core/lombok/javac/handlers') 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