diff options
author | Emil Lundberg <emil@emlun.se> | 2019-01-10 05:34:24 +0100 |
---|---|---|
committer | Emil Lundberg <emil@emlun.se> | 2019-01-13 02:27:33 +0100 |
commit | b227bcb487471631fffb6e33999986d4fa1013b2 (patch) | |
tree | 5129bc8dcbbd77d16f727ef3935050bf2a15edc3 /src/core/lombok/javac/handlers/singulars | |
parent | af3226ffaaf1277a217fc8c9fbe3c1259a561c78 (diff) | |
download | lombok-b227bcb487471631fffb6e33999986d4fa1013b2.tar.gz lombok-b227bcb487471631fffb6e33999986d4fa1013b2.tar.bz2 lombok-b227bcb487471631fffb6e33999986d4fa1013b2.zip |
Pull generatePluralMethod implementation up to JavacSingularizer
Diffstat (limited to 'src/core/lombok/javac/handlers/singulars')
3 files changed, 10 insertions, 42 deletions
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; } } |