From cd139f46355ea01276c2ae13248a2aca5111678a Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Wed, 21 Jan 2015 01:11:26 +0100 Subject: [@Singular @Builder] Our recipe for guava builders did not work in javac 1.7 and below; fixed. --- src/core/lombok/javac/handlers/JavacSingularsRecipes.java | 12 ++++++++++-- .../javac/handlers/singulars/JavacGuavaSingularizer.java | 3 ++- 2 files changed, 12 insertions(+), 3 deletions(-) (limited to 'src/core/lombok/javac/handlers') diff --git a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java index e60bc247..53e01ebb 100644 --- a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java +++ b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java @@ -214,11 +214,18 @@ public class JavacSingularsRecipes { * @param source The source annotation that is the root cause of this code generation. */ protected JCExpression addTypeArgs(int count, boolean addExtends, JavacNode node, JCExpression type, List typeArgs, JCTree source) { + JavacTreeMaker maker = node.getTreeMaker(); + List clonedAndFixedTypeArgs = createTypeArgs(count, addExtends, node, typeArgs, source); + + return maker.TypeApply(type, clonedAndFixedTypeArgs); + } + + protected List createTypeArgs(int count, boolean addExtends, JavacNode node, List typeArgs, JCTree source) { JavacTreeMaker maker = node.getTreeMaker(); Context context = node.getContext(); if (count < 0) throw new IllegalArgumentException("count is negative"); - if (count == 0) return type; + if (count == 0) return List.nil(); ListBuffer arguments = new ListBuffer(); if (typeArgs != null) for (JCExpression orig : typeArgs) { @@ -255,7 +262,8 @@ public class JavacSingularsRecipes { arguments.append(chainDots(node, "java", "lang", "Object")); } } - return maker.TypeApply(type, arguments.toList()); + + return arguments.toList(); } /** Generates 'this.name.size()' as an expression; if nullGuard is true, it's this.name == null ? 0 : this.name.size(). */ diff --git a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java index a45faae4..2474ce7b 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java @@ -159,7 +159,8 @@ abstract class JavacGuavaSingularizer extends JavacSingularizer { JCExpression empty; { //ImmutableX.of() JCExpression emptyMethod = chainDots(builderType, "com", "google", "common", "collect", getSimpleTargetTypeName(data), "of"); - empty = maker.Apply(jceBlank, emptyMethod, jceBlank); + List invokeTypeArgs = createTypeArgs(mapMode ? 2 : 1, false, builderType, data.getTypeArgs(), source); + empty = maker.Apply(invokeTypeArgs, emptyMethod, jceBlank); } JCExpression invokeBuild; { -- cgit