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 | |
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')
6 files changed, 41 insertions, 25 deletions
diff --git a/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java b/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java index cf2e0fbb..7e6daa17 100644 --- a/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java +++ b/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java @@ -225,7 +225,7 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler<SuperBuilder> { // You can use it to check whether to inherit or not. returnType = namePlusTypeParamsToTypeReference(td.name, td.typeParameters, p); - typeParams = td.typeParameters; + typeParams = td.typeParameters != null ? td.typeParameters : new TypeParameter[0]; // <C, B> are the generics for our builder. String classGenericName = "C"; 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); } diff --git a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java index ea5d1a54..d6b1df44 100644 --- a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java +++ b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java @@ -29,6 +29,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.Map; +import java.util.function.Supplier; import lombok.core.LombokImmutableList; import lombok.core.SpiLoadUtil; @@ -203,12 +204,17 @@ public class JavacSingularsRecipes { * control over the return type and value, use * {@link #generateMethods(SingularData, boolean, JavacNode, JCTree, boolean, JCExpression, JCStatement)}. */ - public void generateMethods(SingularData data, boolean deprecate, JavacNode builderType, JCTree source, boolean fluent, boolean chain) { - JavacTreeMaker maker = builderType.getTreeMaker(); - JCExpression returnType = chain ? - cloneSelfType(builderType) : + public void generateMethods(SingularData data, boolean deprecate, final JavacNode builderType, JCTree source, boolean fluent, final boolean chain) { + 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 chain ? + cloneSelfType(builderType) : maker.Type(createVoidType(builderType.getSymbolTable(), CTC_VOID)); - JCStatement returnStatement = chain ? maker.Return(maker.Ident(builderType.toName("this"))) : null; + }}; + Supplier<JCStatement> returnStatement = new Supplier<JCStatement>() { @Override public JCStatement get() { + return chain ? maker.Return(maker.Ident(builderType.toName("this"))) : null; + }}; generateMethods(data, deprecate, builderType, source, fluent, returnType, returnStatement); } /** @@ -216,7 +222,7 @@ public class JavacSingularsRecipes { * {@link SingularData}.<br> * Uses the given <code>returnType</code> and <code>returnStatement</code> for the generated methods. */ - public abstract void generateMethods(SingularData data, boolean deprecate, JavacNode builderType, JCTree source, boolean fluent, JCExpression returnType, JCStatement returnStatement); + public abstract void generateMethods(SingularData data, boolean deprecate, JavacNode builderType, JCTree source, boolean fluent, Supplier<JCExpression> returnType, Supplier<? extends JCStatement> returnStatement); public abstract void appendBuildCode(SingularData data, JavacNode builderType, JCTree source, ListBuffer<JCStatement> statements, Name targetVariableName, String builderVariable); diff --git a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java index 9a6a46f2..ecaf5c87 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java @@ -25,6 +25,7 @@ import static lombok.javac.Javac.*; import static lombok.javac.handlers.JavacHandlerUtil.*; import java.util.Collections; +import java.util.function.Supplier; import lombok.core.GuavaTypeMap; import lombok.core.LombokImmutableList; @@ -69,11 +70,11 @@ abstract class JavacGuavaSingularizer extends JavacSingularizer { return Collections.singletonList(injectFieldAndMarkGenerated(builderType, buildField)); } - @Override public void generateMethods(SingularData data, boolean deprecate, JavacNode builderType, JCTree source, boolean fluent, JCExpression returnType, JCStatement returnStatement) { + @Override public void generateMethods(SingularData data, boolean deprecate, JavacNode builderType, JCTree source, boolean fluent, Supplier<JCExpression> returnType, Supplier<? extends JCStatement> returnStatement) { JavacTreeMaker maker = builderType.getTreeMaker(); - generateSingularMethod(deprecate, maker, returnType, returnStatement, data, builderType, source, fluent); - generatePluralMethod(deprecate, maker, returnType, returnStatement, data, builderType, source, fluent); - generateClearMethod(deprecate, maker, returnType, returnStatement, data, builderType, source); + generateSingularMethod(deprecate, maker, returnType.get(), returnStatement.get(), data, builderType, source, fluent); + generatePluralMethod(deprecate, maker, returnType.get(), returnStatement.get(), data, builderType, source, fluent); + generateClearMethod(deprecate, maker, returnType.get(), returnStatement.get(), data, builderType, source); } private void generateClearMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source) { diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java index dfffb06b..bd0f740e 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java @@ -25,6 +25,7 @@ import static lombok.javac.Javac.*; import static lombok.javac.handlers.JavacHandlerUtil.*; import java.util.Collections; +import java.util.function.Supplier; import lombok.core.handlers.HandlerUtil; import lombok.javac.JavacNode; @@ -75,16 +76,16 @@ abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularize return Collections.singletonList(injectFieldAndMarkGenerated(builderType, buildField)); } - @Override public void generateMethods(SingularData data, boolean deprecate, JavacNode builderType, JCTree source, boolean fluent, JCExpression returnType, JCStatement returnStatement) { + @Override public void generateMethods(SingularData data, boolean deprecate, JavacNode builderType, JCTree source, boolean fluent, Supplier<JCExpression> returnType, Supplier<? extends JCStatement> returnStatement) { if (useGuavaInstead(builderType)) { guavaListSetSingularizer.generateMethods(data, deprecate, builderType, source, fluent, returnType, returnStatement); return; } JavacTreeMaker maker = builderType.getTreeMaker(); - generateSingularMethod(deprecate, maker, returnType, returnStatement, data, builderType, source, fluent); - generatePluralMethod(deprecate, maker, returnType, returnStatement, data, builderType, source, fluent); - generateClearMethod(deprecate, maker, returnType, returnStatement, data, builderType, source); + generateSingularMethod(deprecate, maker, returnType.get(), returnStatement.get(), data, builderType, source, fluent); + generatePluralMethod(deprecate, maker, returnType.get(), returnStatement.get(), data, builderType, source, fluent); + generateClearMethod(deprecate, maker, returnType.get(), returnStatement.get(), data, builderType, source); } private void generateClearMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source) { diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java index 930ec3a4..1b4dd960 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java @@ -25,6 +25,7 @@ import static lombok.javac.Javac.*; import static lombok.javac.handlers.JavacHandlerUtil.*; import java.util.Arrays; +import java.util.function.Supplier; import lombok.core.LombokImmutableList; import lombok.core.handlers.HandlerUtil; @@ -100,16 +101,16 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { return Arrays.asList(keyFieldNode, valueFieldNode); } - @Override public void generateMethods(SingularData data, boolean deprecate, JavacNode builderType, JCTree source, boolean fluent, JCExpression returnType, JCStatement returnStatement) { + @Override public void generateMethods(SingularData data, boolean deprecate, JavacNode builderType, JCTree source, boolean fluent, Supplier<JCExpression> returnType, Supplier<? extends JCStatement> returnStatement) { if (useGuavaInstead(builderType)) { guavaMapSingularizer.generateMethods(data, deprecate, builderType, source, fluent, returnType, returnStatement); return; } JavacTreeMaker maker = builderType.getTreeMaker(); - generateSingularMethod(deprecate, maker, returnType, returnStatement, data, builderType, source, fluent); - generatePluralMethod(deprecate, maker, returnType, returnStatement, data, builderType, source, fluent); - generateClearMethod(deprecate, maker, returnType, returnStatement, data, builderType, source); + generateSingularMethod(deprecate, maker, returnType.get(), returnStatement.get(), data, builderType, source, fluent); + generatePluralMethod(deprecate, maker, returnType.get(), returnStatement.get(), data, builderType, source, fluent); + generateClearMethod(deprecate, maker, returnType.get(), returnStatement.get(), data, builderType, source); } private void generateClearMethod(boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source) { |