From 3285d83e1636c0a21c7aada3bb278419ec2bd83a Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Sun, 13 Jan 2019 02:11:02 +0100 Subject: Pull createConstructBuilderVarIfNeeded calls up to JavacSingularizer --- src/core/lombok/javac/handlers/JavacSingularsRecipes.java | 15 +++++++-------- .../javac/handlers/singulars/JavacGuavaSingularizer.java | 1 - .../singulars/JavacJavaUtilListSetSingularizer.java | 1 - .../handlers/singulars/JavacJavaUtilMapSingularizer.java | 2 -- 4 files changed, 7 insertions(+), 12 deletions(-) (limited to 'src/core/lombok/javac') 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 statements, Name methodName, List jcVariableDecls) { + private void finishAndInjectMethod(JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean deprecate, ListBuffer statements, Name methodName, List 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.nil()); + finishAndInjectMethod(maker, returnType, returnStatement, data, builderType, source, deprecate, statements, methodName, List.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 generatePluralMethodStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) { - ListBuffer statements = new ListBuffer(); - statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, source)); JCExpression thisDotFieldDotAdd = chainDots(builderType, "this", data.getPluralName().toString(), getAddMethodName() + "All"); JCExpression invokeAdd = maker.Apply(List.nil(), thisDotFieldDotAdd, List.of(maker.Ident(data.getPluralName()))); - statements.append(maker.Exec(invokeAdd)); - return statements; + return new ListBuffer().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 statements = new ListBuffer(); Name[] names = generateSingularMethodParameterNames(data, builderType); - statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, source)); JCExpression thisDotFieldDotAdd = chainDots(builderType, "this", data.getPluralName().toString(), getAddMethodName()); ListBuffer invokeAddExprBuilder = new ListBuffer(); 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 generateSingularMethodStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) { ListBuffer statements = new ListBuffer(); - 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 generatePluralMethodStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) { List jceBlank = List.nil(); ListBuffer statements = new ListBuffer(); - statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, source)); long baseFlags = JavacHandlerUtil.addFinalIfNeeded(0, builderType.getContext()); Name entryName = builderType.toName("$lombokEntry"); -- cgit