From eba2a515fa3f4c773f3b38ef3510c70f941210cc Mon Sep 17 00:00:00 2001 From: Roel Spilker Date: Thu, 21 Aug 2014 22:23:17 +0200 Subject: [i731] javac resolution broken by 1.8.0_20; fixed with some reflection voodoo. -R&R --- src/core/lombok/javac/JavacResolution.java | 35 ++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/JavacResolution.java b/src/core/lombok/javac/JavacResolution.java index ec455b18..23d7d482 100644 --- a/src/core/lombok/javac/JavacResolution.java +++ b/src/core/lombok/javac/JavacResolution.java @@ -24,11 +24,15 @@ package lombok.javac; import static lombok.javac.Javac.*; import static lombok.javac.JavacTreeMaker.TypeTag.typeTag; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.util.ArrayDeque; import java.util.Map; import javax.lang.model.type.TypeKind; +import lombok.Lombok; + import com.sun.tools.javac.code.BoundKind; import com.sun.tools.javac.code.Symbol.TypeSymbol; import com.sun.tools.javac.code.Symtab; @@ -179,10 +183,37 @@ public class JavacResolution { } } + private static class ReflectiveAccess { + private static Method UPPER_BOUND; + + static { + Method upperBound = null; + try { + upperBound = Types.class.getMethod("upperBound", Type.class); + } catch (Throwable ignore) {} + if (upperBound == null) try { + upperBound = Types.class.getMethod("wildUpperBound", Type.class); + } catch (Throwable ignore) {} + + UPPER_BOUND = upperBound; + } + + public static Type Types_upperBound(Types types, Type type) { + try { + return (Type) UPPER_BOUND.invoke(types, type); + } catch (InvocationTargetException e) { + throw Lombok.sneakyThrow(e.getCause()); + } catch (Exception e) { + throw Lombok.sneakyThrow(e); + } + } + } + public static Type ifTypeIsIterableToComponent(Type type, JavacAST ast) { Types types = Types.instance(ast.getContext()); Symtab syms = Symtab.instance(ast.getContext()); - Type boundType = types.upperBound(type); + Type boundType = ReflectiveAccess.Types_upperBound(types, type); +// Type boundType = types.upperBound(type); Type elemTypeIfArray = types.elemtype(boundType); if (elemTypeIfArray != null) return elemTypeIfArray; @@ -190,7 +221,7 @@ public class JavacResolution { if (base == null) return syms.objectType; List iterableParams = base.allparams(); - return iterableParams.isEmpty() ? syms.objectType : types.upperBound(iterableParams.head); + return iterableParams.isEmpty() ? syms.objectType : ReflectiveAccess.Types_upperBound(types, iterableParams.head); } public static JCExpression typeToJCTree(Type type, JavacAST ast, boolean allowVoid) throws TypeNotConvertibleException { -- cgit