diff options
author | Jan Rieke <rieke@subshell.com> | 2018-04-27 16:59:42 +0200 |
---|---|---|
committer | Jan Rieke <rieke@subshell.com> | 2018-04-27 16:59:42 +0200 |
commit | 0b789291e42706f8772eafcd2510233f22f6ad76 (patch) | |
tree | 3dbe555b06f391448a2534662a0395b0117d9b17 /src/core/lombok/javac/handlers/HandleSuperBuilder.java | |
parent | 9f3e8509f7564b82eb13d3e4d7d0fc22a6d13cc3 (diff) | |
download | lombok-0b789291e42706f8772eafcd2510233f22f6ad76.tar.gz lombok-0b789291e42706f8772eafcd2510233f22f6ad76.tar.bz2 lombok-0b789291e42706f8772eafcd2510233f22f6ad76.zip |
fixed generation problem caused by reusing expressions
Diffstat (limited to 'src/core/lombok/javac/handlers/HandleSuperBuilder.java')
-rw-r--r-- | src/core/lombok/javac/handlers/HandleSuperBuilder.java | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/core/lombok/javac/handlers/HandleSuperBuilder.java b/src/core/lombok/javac/handlers/HandleSuperBuilder.java index bd0f3b70..0004ddcb 100644 --- a/src/core/lombok/javac/handlers/HandleSuperBuilder.java +++ b/src/core/lombok/javac/handlers/HandleSuperBuilder.java @@ -26,6 +26,7 @@ import static lombok.javac.Javac.*; import static lombok.javac.handlers.JavacHandlerUtil.*; import java.util.ArrayList; +import java.util.function.Supplier; import org.mangosdk.spi.ProviderFor; @@ -214,7 +215,7 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> { return; } - // Check that all builder fields for @Singular and @ObtainVia. + // Check validity of @ObtainVia fields, and add check if adding cleaning for @Singular is necessary. for (BuilderFieldData bfd : builderFields) { if (bfd.singularData != null && bfd.singularData.getSingularizer() != null) { if (bfd.singularData.getSingularizer().requiresCleaning()) { @@ -365,6 +366,7 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> { // Now add the <?, ?>. JCWildcard wildcard = maker.Wildcard(maker.TypeBoundKind(BoundKind.UNBOUND), null); typeParamsForBuilderParameter.add(wildcard); + wildcard = maker.Wildcard(maker.TypeBoundKind(BoundKind.UNBOUND), null); typeParamsForBuilderParameter.add(wildcard); JCTypeApply paramType = maker.TypeApply(maker.Ident(builderClassname), typeParamsForBuilderParameter.toList()); JCVariableDecl param = maker.VarDef(maker.Modifiers(flags), builderVariableName, paramType, null); @@ -546,13 +548,18 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> { } } - public void makeSetterMethodsForBuilder(JavacNode builderType, BuilderFieldData fieldNode, JavacNode source, String builderGenericName) { + public void makeSetterMethodsForBuilder(final JavacNode builderType, BuilderFieldData fieldNode, JavacNode source, final String builderGenericName) { boolean deprecate = isFieldDeprecated(fieldNode.originalFieldNode); - JavacTreeMaker maker = builderType.getTreeMaker(); - JCExpression returnType = maker.Ident(builderType.toName(builderGenericName)); - JCReturn returnStatement = maker.Return(maker.Apply(List.<JCExpression>nil(), maker.Ident(builderType.toName(SELF_METHOD)), List.<JCExpression>nil())); + final JavacTreeMaker maker = builderType.getTreeMaker(); + // TODO: Make these lambdas when switching to a source level >= 1.8. + Supplier<JCExpression> returnType = new Supplier<JCExpression>() { @Override public JCExpression get() { + return maker.Ident(builderType.toName(builderGenericName)); + }}; + Supplier<? extends JCReturn> returnStatement = new Supplier<JCReturn>() { @Override public JCReturn get() { + return maker.Return(maker.Apply(List.<JCExpression>nil(), maker.Ident(builderType.toName(SELF_METHOD)), List.<JCExpression>nil())); + }}; if (fieldNode.singularData == null || fieldNode.singularData.getSingularizer() == null) { - makeSimpleSetterMethodForBuilder(builderType, deprecate, fieldNode.createdFields.get(0), fieldNode.nameOfSetFlag, source, true, true, returnType, returnStatement); + makeSimpleSetterMethodForBuilder(builderType, deprecate, fieldNode.createdFields.get(0), fieldNode.nameOfSetFlag, source, true, true, returnType.get(), returnStatement.get()); } else { fieldNode.singularData.getSingularizer().generateMethods(fieldNode.singularData, deprecate, builderType, source.get(), true, returnType, returnStatement); } |