diff options
author | Emil Lundberg <emil@emlun.se> | 2019-01-13 02:11:02 +0100 |
---|---|---|
committer | Emil Lundberg <emil@emlun.se> | 2019-01-13 02:38:15 +0100 |
commit | 3285d83e1636c0a21c7aada3bb278419ec2bd83a (patch) | |
tree | c36a38cb1e55b2f0f84a7c1534a68c94227af8be /src/core/lombok/javac | |
parent | 92fc11fd0efdd841f488fda8c937577349dc713c (diff) | |
download | lombok-3285d83e1636c0a21c7aada3bb278419ec2bd83a.tar.gz lombok-3285d83e1636c0a21c7aada3bb278419ec2bd83a.tar.bz2 lombok-3285d83e1636c0a21c7aada3bb278419ec2bd83a.zip |
Pull createConstructBuilderVarIfNeeded calls up to JavacSingularizer
Diffstat (limited to 'src/core/lombok/javac')
4 files changed, 7 insertions, 12 deletions
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<JCStatement> statements, Name methodName, List<JCVariableDecl> jcVariableDecls) { + private void finishAndInjectMethod(JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean deprecate, ListBuffer<JCStatement> statements, Name methodName, List<JCVariableDecl> 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.<JCVariableDecl>nil()); + finishAndInjectMethod(maker, returnType, returnStatement, data, builderType, source, deprecate, statements, methodName, List.<JCVariableDecl>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<JCStatement> generatePluralMethodStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) { - 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)); - return statements; + return new ListBuffer<JCStatement>().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<JCStatement> statements = new ListBuffer<JCStatement>(); Name[] names = generateSingularMethodParameterNames(data, builderType); - statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, source)); JCExpression thisDotFieldDotAdd = chainDots(builderType, "this", data.getPluralName().toString(), getAddMethodName()); ListBuffer<JCExpression> invokeAddExprBuilder = new ListBuffer<JCExpression>(); 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<JCStatement> generateSingularMethodStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) { ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>(); - 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<JCStatement> generatePluralMethodStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) { List<JCExpression> jceBlank = List.nil(); ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>(); - statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, source)); long baseFlags = JavacHandlerUtil.addFinalIfNeeded(0, builderType.getContext()); Name entryName = builderType.toName("$lombokEntry"); |