diff options
author | Reinier Zwitserloot <reinier@zwitserloot.com> | 2015-01-21 01:11:26 +0100 |
---|---|---|
committer | Reinier Zwitserloot <reinier@zwitserloot.com> | 2015-01-21 01:11:26 +0100 |
commit | cd139f46355ea01276c2ae13248a2aca5111678a (patch) | |
tree | 4216fb7f8aab71bc14496794562feb6106b1d07c /src/core | |
parent | ef60d1af001204622b428e78894c967a9aee7e91 (diff) | |
download | lombok-cd139f46355ea01276c2ae13248a2aca5111678a.tar.gz lombok-cd139f46355ea01276c2ae13248a2aca5111678a.tar.bz2 lombok-cd139f46355ea01276c2ae13248a2aca5111678a.zip |
[@Singular @Builder] Our recipe for guava builders did not work in javac 1.7 and below; fixed.
Diffstat (limited to 'src/core')
4 files changed, 32 insertions, 16 deletions
diff --git a/src/core/lombok/eclipse/handlers/EclipseSingularsRecipes.java b/src/core/lombok/eclipse/handlers/EclipseSingularsRecipes.java index df8bd665..4cb41d4f 100644 --- a/src/core/lombok/eclipse/handlers/EclipseSingularsRecipes.java +++ b/src/core/lombok/eclipse/handlers/EclipseSingularsRecipes.java @@ -239,8 +239,24 @@ public class EclipseSingularsRecipes { * @param source The source annotation that is the root cause of this code generation. */ protected TypeReference addTypeArgs(int count, boolean addExtends, EclipseNode node, TypeReference type, List<TypeReference> typeArgs) { + TypeReference[] clonedAndFixedArgs = createTypeArgs(count, addExtends, node, typeArgs); + if (type instanceof SingleTypeReference) { + type = new ParameterizedSingleTypeReference(((SingleTypeReference) type).token, clonedAndFixedArgs, 0, 0L); + } else if (type instanceof QualifiedTypeReference) { + QualifiedTypeReference qtr = (QualifiedTypeReference) type; + TypeReference[][] trs = new TypeReference[qtr.tokens.length][]; + trs[qtr.tokens.length - 1] = clonedAndFixedArgs; + type = new ParameterizedQualifiedTypeReference(((QualifiedTypeReference) type).tokens, trs, 0, NULL_POSS); + } else { + node.addError("Don't know how to clone-and-parameterize type: " + type); + } + + return type; + } + + protected TypeReference[] createTypeArgs(int count, boolean addExtends, EclipseNode node, List<TypeReference> typeArgs) { if (count < 0) throw new IllegalArgumentException("count is negative"); - if (count == 0) return type; + if (count == 0) return null; List<TypeReference> arguments = new ArrayList<TypeReference>(); if (typeArgs != null) for (TypeReference orig : typeArgs) { @@ -280,18 +296,8 @@ public class EclipseSingularsRecipes { } } - if (type instanceof SingleTypeReference) { - type = new ParameterizedSingleTypeReference(((SingleTypeReference) type).token, arguments.toArray(new TypeReference[arguments.size()]), 0, 0L); - } else if (type instanceof QualifiedTypeReference) { - QualifiedTypeReference qtr = (QualifiedTypeReference) type; - TypeReference[][] trs = new TypeReference[qtr.tokens.length][]; - trs[qtr.tokens.length - 1] = arguments.toArray(new TypeReference[arguments.size()]); - type = new ParameterizedQualifiedTypeReference(((QualifiedTypeReference) type).tokens, trs, 0, NULL_POSS); - } else { - node.addError("Don't know how to clone-and-parameterize type: " + type); - } - - return type; + if (arguments.isEmpty()) return null; + return arguments.toArray(new TypeReference[arguments.size()]); } private static final char[] SIZE_TEXT = new char[] {'s', 'i', 'z', 'e'}; diff --git a/src/core/lombok/eclipse/handlers/singulars/EclipseGuavaSingularizer.java b/src/core/lombok/eclipse/handlers/singulars/EclipseGuavaSingularizer.java index 8d54da6f..3b2ca875 100644 --- a/src/core/lombok/eclipse/handlers/singulars/EclipseGuavaSingularizer.java +++ b/src/core/lombok/eclipse/handlers/singulars/EclipseGuavaSingularizer.java @@ -205,6 +205,7 @@ abstract class EclipseGuavaSingularizer extends EclipseSingularizer { emptyInvoke = new MessageSend(); emptyInvoke.selector = new char[] {'o', 'f'}; emptyInvoke.receiver = new QualifiedNameReference(makeGuavaTypeName(getSimpleTargetTypeName(data), false), NULL_POSS, 0, 0); + emptyInvoke.typeArguments = createTypeArgs(mapMode ? 2 : 1, false, builderType, data.getTypeArgs()); } MessageSend invokeBuild; { 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 @@ -215,10 +215,17 @@ public class JavacSingularsRecipes { */ protected JCExpression addTypeArgs(int count, boolean addExtends, JavacNode node, JCExpression type, List<JCExpression> typeArgs, JCTree source) { JavacTreeMaker maker = node.getTreeMaker(); + List<JCExpression> clonedAndFixedTypeArgs = createTypeArgs(count, addExtends, node, typeArgs, source); + + return maker.TypeApply(type, clonedAndFixedTypeArgs); + } + + protected List<JCExpression> createTypeArgs(int count, boolean addExtends, JavacNode node, List<JCExpression> 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<JCExpression> arguments = new ListBuffer<JCExpression>(); 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.<em>name</em>.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<JCExpression> invokeTypeArgs = createTypeArgs(mapMode ? 2 : 1, false, builderType, data.getTypeArgs(), source); + empty = maker.Apply(invokeTypeArgs, emptyMethod, jceBlank); } JCExpression invokeBuild; { |