1.1 --- a/src/share/classes/com/sun/tools/javac/code/Types.java Thu Oct 23 18:00:05 2008 +0100 1.2 +++ b/src/share/classes/com/sun/tools/javac/code/Types.java Thu Oct 23 18:10:23 2008 +0100 1.3 @@ -3367,33 +3367,67 @@ 1.4 * quantifiers) only 1.5 */ 1.6 private Type rewriteQuantifiers(Type t, boolean high, boolean rewriteTypeVars) { 1.7 - ListBuffer<Type> from = new ListBuffer<Type>(); 1.8 - ListBuffer<Type> to = new ListBuffer<Type>(); 1.9 - adaptSelf(t, from, to); 1.10 - ListBuffer<Type> rewritten = new ListBuffer<Type>(); 1.11 - List<Type> formals = from.toList(); 1.12 - boolean changed = false; 1.13 - for (Type arg : to.toList()) { 1.14 - Type bound; 1.15 - if (rewriteTypeVars && arg.tag == TYPEVAR) { 1.16 - TypeVar tv = (TypeVar)arg; 1.17 - bound = high ? tv.bound : syms.botType; 1.18 - } else { 1.19 - bound = high ? upperBound(arg) : lowerBound(arg); 1.20 + return new Rewriter(high, rewriteTypeVars).rewrite(t); 1.21 + } 1.22 + 1.23 + class Rewriter extends UnaryVisitor<Type> { 1.24 + 1.25 + boolean high; 1.26 + boolean rewriteTypeVars; 1.27 + 1.28 + Rewriter(boolean high, boolean rewriteTypeVars) { 1.29 + this.high = high; 1.30 + this.rewriteTypeVars = rewriteTypeVars; 1.31 + } 1.32 + 1.33 + Type rewrite(Type t) { 1.34 + ListBuffer<Type> from = new ListBuffer<Type>(); 1.35 + ListBuffer<Type> to = new ListBuffer<Type>(); 1.36 + adaptSelf(t, from, to); 1.37 + ListBuffer<Type> rewritten = new ListBuffer<Type>(); 1.38 + List<Type> formals = from.toList(); 1.39 + boolean changed = false; 1.40 + for (Type arg : to.toList()) { 1.41 + Type bound = visit(arg); 1.42 + if (arg != bound) { 1.43 + changed = true; 1.44 + bound = high ? makeExtendsWildcard(bound, (TypeVar)formals.head) 1.45 + : makeSuperWildcard(bound, (TypeVar)formals.head); 1.46 + } 1.47 + rewritten.append(bound); 1.48 + formals = formals.tail; 1.49 } 1.50 - Type newarg = bound; 1.51 - if (arg != bound) { 1.52 - changed = true; 1.53 - newarg = high ? makeExtendsWildcard(bound, (TypeVar)formals.head) 1.54 - : makeSuperWildcard(bound, (TypeVar)formals.head); 1.55 - } 1.56 - rewritten.append(newarg); 1.57 - formals = formals.tail; 1.58 + if (changed) 1.59 + return subst(t.tsym.type, from.toList(), rewritten.toList()); 1.60 + else 1.61 + return t; 1.62 } 1.63 - if (changed) 1.64 - return subst(t.tsym.type, from.toList(), rewritten.toList()); 1.65 - else 1.66 - return t; 1.67 + 1.68 + public Type visitType(Type t, Void s) { 1.69 + return high ? upperBound(t) : lowerBound(t); 1.70 + } 1.71 + 1.72 + @Override 1.73 + public Type visitCapturedType(CapturedType t, Void s) { 1.74 + return visitWildcardType(t.wildcard, null); 1.75 + } 1.76 + 1.77 + @Override 1.78 + public Type visitTypeVar(TypeVar t, Void s) { 1.79 + if (rewriteTypeVars) 1.80 + return high ? t.bound : syms.botType; 1.81 + else 1.82 + return t; 1.83 + } 1.84 + 1.85 + @Override 1.86 + public Type visitWildcardType(WildcardType t, Void s) { 1.87 + Type bound = high ? t.getExtendsBound() : 1.88 + t.getSuperBound(); 1.89 + if (bound == null) 1.90 + bound = high ? syms.objectType : syms.botType; 1.91 + return bound; 1.92 + } 1.93 } 1.94 1.95 /**