langtools/src/share/classes/com/sun/tools/javac/code/Types.java
changeset 8032 e1aa25ccdabb
parent 7681 1f0819a3341f
child 8230 b761a23e78d8
equal deleted inserted replaced
8031:d5fe2c1cecfc 8032:e1aa25ccdabb
     1 /*
     1 /*
     2  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
  1059                             bLow  = rewriteQuantifiers(b, LOW,  REWRITE_TYPEVARS);
  1059                             bLow  = rewriteQuantifiers(b, LOW,  REWRITE_TYPEVARS);
  1060                             lowSub = asSub(bLow, aLow.tsym);
  1060                             lowSub = asSub(bLow, aLow.tsym);
  1061                             highSub = (lowSub == null) ? null : asSub(bHigh, aHigh.tsym);
  1061                             highSub = (lowSub == null) ? null : asSub(bHigh, aHigh.tsym);
  1062                         }
  1062                         }
  1063                         if (highSub != null) {
  1063                         if (highSub != null) {
  1064                             assert a.tsym == highSub.tsym && a.tsym == lowSub.tsym
  1064                             if (!(a.tsym == highSub.tsym && a.tsym == lowSub.tsym)) {
  1065                                 : a.tsym + " != " + highSub.tsym + " != " + lowSub.tsym;
  1065                                 Assert.error(a.tsym + " != " + highSub.tsym + " != " + lowSub.tsym);
       
  1066                             }
  1066                             if (!disjointTypes(aHigh.allparams(), highSub.allparams())
  1067                             if (!disjointTypes(aHigh.allparams(), highSub.allparams())
  1067                                 && !disjointTypes(aHigh.allparams(), lowSub.allparams())
  1068                                 && !disjointTypes(aHigh.allparams(), lowSub.allparams())
  1068                                 && !disjointTypes(aLow.allparams(), highSub.allparams())
  1069                                 && !disjointTypes(aLow.allparams(), highSub.allparams())
  1069                                 && !disjointTypes(aLow.allparams(), lowSub.allparams())) {
  1070                                 && !disjointTypes(aLow.allparams(), lowSub.allparams())) {
  1070                                 if (upcast ? giveWarning(a, b) :
  1071                                 if (upcast ? giveWarning(a, b) :
  1701             bt.interfaces_field = bounds;
  1702             bt.interfaces_field = bounds;
  1702         } else {
  1703         } else {
  1703             bt.supertype_field = bounds.head;
  1704             bt.supertype_field = bounds.head;
  1704             bt.interfaces_field = bounds.tail;
  1705             bt.interfaces_field = bounds.tail;
  1705         }
  1706         }
  1706         assert bt.supertype_field.tsym.completer != null
  1707         Assert.check(bt.supertype_field.tsym.completer != null
  1707             || !bt.supertype_field.isInterface()
  1708                 || !bt.supertype_field.isInterface(),
  1708             : bt.supertype_field;
  1709             bt.supertype_field);
  1709         return bt;
  1710         return bt;
  1710     }
  1711     }
  1711 
  1712 
  1712     /**
  1713     /**
  1713      * Same as {@link #makeCompoundType(List,Type)}, except that the
  1714      * Same as {@link #makeCompoundType(List,Type)}, except that the
  1832                         // effect of calling
  1833                         // effect of calling
  1833                         // ClassSymbol.getInterfaces.  Since
  1834                         // ClassSymbol.getInterfaces.  Since
  1834                         // t.interfaces_field is null after
  1835                         // t.interfaces_field is null after
  1835                         // completion, we can assume that t is not the
  1836                         // completion, we can assume that t is not the
  1836                         // type of a class/interface declaration.
  1837                         // type of a class/interface declaration.
  1837                         assert t != t.tsym.type : t.toString();
  1838                         Assert.check(t != t.tsym.type, t);
  1838                         List<Type> actuals = t.allparams();
  1839                         List<Type> actuals = t.allparams();
  1839                         List<Type> formals = t.tsym.type.allparams();
  1840                         List<Type> formals = t.tsym.type.allparams();
  1840                         if (t.hasErasedSupertypes()) {
  1841                         if (t.hasErasedSupertypes()) {
  1841                             t.interfaces_field = erasureRecursive(interfaces);
  1842                             t.interfaces_field = erasureRecursive(interfaces);
  1842                         } else if (formals.nonEmpty()) {
  1843                         } else if (formals.nonEmpty()) {
  2644                 }
  2645                 }
  2645                 act1 = act1.tail;
  2646                 act1 = act1.tail;
  2646                 act2 = act2.tail;
  2647                 act2 = act2.tail;
  2647                 typarams = typarams.tail;
  2648                 typarams = typarams.tail;
  2648             }
  2649             }
  2649             assert(act1.isEmpty() && act2.isEmpty() && typarams.isEmpty());
  2650             Assert.check(act1.isEmpty() && act2.isEmpty() && typarams.isEmpty());
  2650             return new ClassType(class1.getEnclosingType(), merged.toList(), class1.tsym);
  2651             return new ClassType(class1.getEnclosingType(), merged.toList(), class1.tsym);
  2651         }
  2652         }
  2652 
  2653 
  2653     /**
  2654     /**
  2654      * Return the minimum type of a closure, a compound type if no
  2655      * Return the minimum type of a closure, a compound type if no
  2756 
  2757 
  2757         case CLASS_BOUND:
  2758         case CLASS_BOUND:
  2758             // calculate lub(A, B)
  2759             // calculate lub(A, B)
  2759             while (ts.head.tag != CLASS && ts.head.tag != TYPEVAR)
  2760             while (ts.head.tag != CLASS && ts.head.tag != TYPEVAR)
  2760                 ts = ts.tail;
  2761                 ts = ts.tail;
  2761             assert !ts.isEmpty();
  2762             Assert.check(!ts.isEmpty());
  2762             List<Type> cl = closure(ts.head);
  2763             List<Type> cl = closure(ts.head);
  2763             for (Type t : ts.tail) {
  2764             for (Type t : ts.tail) {
  2764                 if (t.tag == CLASS || t.tag == TYPEVAR)
  2765                 if (t.tag == CLASS || t.tag == TYPEVAR)
  2765                     cl = intersect(cl, closure(t));
  2766                     cl = intersect(cl, closure(t));
  2766             }
  2767             }
  3136         // tries to reject a cast by transferring type parameters
  3137         // tries to reject a cast by transferring type parameters
  3137         // from $to$ to $from$ by common superinterfaces.
  3138         // from $to$ to $from$ by common superinterfaces.
  3138         boolean reverse = false;
  3139         boolean reverse = false;
  3139         Type target = to;
  3140         Type target = to;
  3140         if ((to.tsym.flags() & INTERFACE) == 0) {
  3141         if ((to.tsym.flags() & INTERFACE) == 0) {
  3141             assert (from.tsym.flags() & INTERFACE) != 0;
  3142             Assert.check((from.tsym.flags() & INTERFACE) != 0);
  3142             reverse = true;
  3143             reverse = true;
  3143             to = from;
  3144             to = from;
  3144             from = target;
  3145             from = target;
  3145         }
  3146         }
  3146         List<Type> commonSupers = superClosure(to, erasure(from));
  3147         List<Type> commonSupers = superClosure(to, erasure(from));
  3171         // tries to reject a cast by transferring type parameters
  3172         // tries to reject a cast by transferring type parameters
  3172         // from the final class to the interface.
  3173         // from the final class to the interface.
  3173         boolean reverse = false;
  3174         boolean reverse = false;
  3174         Type target = to;
  3175         Type target = to;
  3175         if ((to.tsym.flags() & INTERFACE) == 0) {
  3176         if ((to.tsym.flags() & INTERFACE) == 0) {
  3176             assert (from.tsym.flags() & INTERFACE) != 0;
  3177             Assert.check((from.tsym.flags() & INTERFACE) != 0);
  3177             reverse = true;
  3178             reverse = true;
  3178             to = from;
  3179             to = from;
  3179             from = target;
  3180             from = target;
  3180         }
  3181         }
  3181         assert (from.tsym.flags() & FINAL) != 0;
  3182         Assert.check((from.tsym.flags() & FINAL) != 0);
  3182         Type t1 = asSuper(from, to.tsym);
  3183         Type t1 = asSuper(from, to.tsym);
  3183         if (t1 == null) return false;
  3184         if (t1 == null) return false;
  3184         Type t2 = to;
  3185         Type t2 = to;
  3185         if (disjointTypes(t1.getTypeArguments(), t2.getTypeArguments()))
  3186         if (disjointTypes(t1.getTypeArguments(), t2.getTypeArguments()))
  3186             return false;
  3187             return false;