src/share/classes/com/sun/tools/javac/code/Types.java

Print this page

        

*** 1537,1548 **** } else { return false; } } ! if (t.isCompound() || s.isCompound()) { ! return !t.isCompound() ? visitIntersectionType((IntersectionClassType)s.unannotatedType(), t, true) : visitIntersectionType((IntersectionClassType)t.unannotatedType(), s, false); } if (s.hasTag(CLASS) || s.hasTag(ARRAY)) { --- 1537,1548 ---- } else { return false; } } ! if (t.isIntersection() || s.isIntersection()) { ! return !t.isIntersection() ? visitIntersectionType((IntersectionClassType)s.unannotatedType(), t, true) : visitIntersectionType((IntersectionClassType)t.unannotatedType(), s, false); } if (s.hasTag(CLASS) || s.hasTag(ARRAY)) {
*** 2253,2275 **** public List<Type> erasureRecursive(List<Type> ts) { return Type.map(ts, erasureRecFun); } // </editor-fold> ! // <editor-fold defaultstate="collapsed" desc="makeCompoundType"> /** ! * Make a compound type from non-empty list of types. The list should be ! * ordered according to {@link Symbol#precedes(TypeSymbol,Types)}. * ! * @param bounds the types from which the compound type is formed ! * @param supertype is objectType if all bounds are interfaces, ! * null otherwise. */ ! public Type makeCompoundType(List<Type> bounds) { ! return makeCompoundType(bounds, bounds.head.tsym.isInterface()); } ! public Type makeCompoundType(List<Type> bounds, boolean allInterfaces) { Assert.check(bounds.nonEmpty()); Type firstExplicitBound = bounds.head; if (allInterfaces) { bounds = bounds.prepend(syms.objectType); } --- 2253,2284 ---- public List<Type> erasureRecursive(List<Type> ts) { return Type.map(ts, erasureRecFun); } // </editor-fold> ! // <editor-fold defaultstate="collapsed" desc="makeIntersectionType"> /** ! * Make an intersection type from non-empty list of types. The list should be ordered according to ! * {@link TypeSymbol#precedes(TypeSymbol, Types)}. Note that this might cause a symbol completion. ! * Hence, this version of makeIntersectionType may not be called during a classfile read. * ! * @param bounds the types from which the intersection type is formed */ ! public IntersectionClassType makeIntersectionType(List<Type> bounds) { ! return makeIntersectionType(bounds, bounds.head.tsym.isInterface()); } ! ! /** ! * Make an intersection type from non-empty list of types. The list should be ordered according to ! * {@link TypeSymbol#precedes(TypeSymbol, Types)}. This does not cause symbol completion as ! * an extra parameter indicates as to whether all bounds are interfaces - in which case the ! * supertype is implicitly assumed to be 'Object'. ! * ! * @param bounds the types from which the intersection type is formed ! * @param allInterfaces are all bounds interface types? ! */ ! public IntersectionClassType makeIntersectionType(List<Type> bounds, boolean allInterfaces) { Assert.check(bounds.nonEmpty()); Type firstExplicitBound = bounds.head; if (allInterfaces) { bounds = bounds.prepend(syms.objectType); }
*** 2278,2304 **** Type.moreInfo ? names.fromString(bounds.toString()) : names.empty, null, syms.noSymbol); ! bc.type = new IntersectionClassType(bounds, bc, allInterfaces); bc.erasure_field = (bounds.head.hasTag(TYPEVAR)) ? syms.objectType : // error condition, recover erasure(firstExplicitBound); bc.members_field = new Scope(bc); ! return bc.type; } /** ! * A convenience wrapper for {@link #makeCompoundType(List)}; the * arguments are converted to a list and passed to the other * method. Note that this might cause a symbol completion. ! * Hence, this version of makeCompoundType may not be called * during a classfile read. */ ! public Type makeCompoundType(Type bound1, Type bound2) { ! return makeCompoundType(List.of(bound1, bound2)); } // </editor-fold> // <editor-fold defaultstate="collapsed" desc="supertype"> public Type supertype(Type t) { --- 2287,2314 ---- Type.moreInfo ? names.fromString(bounds.toString()) : names.empty, null, syms.noSymbol); ! IntersectionClassType intersectionType = new IntersectionClassType(bounds, bc, allInterfaces); ! bc.type = intersectionType; bc.erasure_field = (bounds.head.hasTag(TYPEVAR)) ? syms.objectType : // error condition, recover erasure(firstExplicitBound); bc.members_field = new Scope(bc); ! return intersectionType; } /** ! * A convenience wrapper for {@link #makeIntersectionType(List)}; the * arguments are converted to a list and passed to the other * method. Note that this might cause a symbol completion. ! * Hence, this version of makeIntersectionType may not be called * during a classfile read. */ ! public Type makeIntersectionType(Type bound1, Type bound2) { ! return makeIntersectionType(List.of(bound1, bound2)); } // </editor-fold> // <editor-fold defaultstate="collapsed" desc="supertype"> public Type supertype(Type t) {
*** 2434,2444 **** } // where private final UnaryVisitor<List<Type>> directSupertypes = new UnaryVisitor<List<Type>>() { public List<Type> visitType(final Type type, final Void ignored) { ! if (!type.isCompound()) { final Type sup = supertype(type); return (sup == Type.noType || sup == type || sup == null) ? interfaces(type) : interfaces(type).prepend(sup); } else { --- 2444,2454 ---- } // where private final UnaryVisitor<List<Type>> directSupertypes = new UnaryVisitor<List<Type>>() { public List<Type> visitType(final Type type, final Void ignored) { ! if (!type.isIntersection()) { final Type sup = supertype(type); return (sup == Type.noType || sup == type || sup == null) ? interfaces(type) : interfaces(type).prepend(sup); } else {
*** 2488,2521 **** } // </editor-fold> // <editor-fold defaultstate="collapsed" desc="setBounds"> /** ! * Set the bounds field of the given type variable to reflect a ! * (possibly multiple) list of bounds. * @param t a type variable * @param bounds the bounds, must be nonempty - * @param supertype is objectType if all bounds are interfaces, - * null otherwise. */ public void setBounds(TypeVar t, List<Type> bounds) { setBounds(t, bounds, bounds.head.tsym.isInterface()); } /** ! * Same as {@link #setBounds(Type.TypeVar,List,Type)}, except that ! * third parameter is computed directly, as follows: if all ! * all bounds are interface types, the computed supertype is Object, ! * otherwise the supertype is simply left null (in this case, the supertype ! * is assumed to be the head of the bound list passed as second argument). ! * Note that this check might cause a symbol completion. Hence, this version of ! * setBounds may not be called during a classfile read. */ public void setBounds(TypeVar t, List<Type> bounds, boolean allInterfaces) { t.bound = bounds.tail.isEmpty() ? bounds.head : ! makeCompoundType(bounds, allInterfaces); t.rank_field = -1; } // </editor-fold> // <editor-fold defaultstate="collapsed" desc="getBounds"> --- 2498,2533 ---- } // </editor-fold> // <editor-fold defaultstate="collapsed" desc="setBounds"> /** ! * Same as {@link Types#setBounds(TypeVar, List, boolean)}, except that third parameter is computed directly, ! * as follows: if all all bounds are interface types, the computed supertype is Object,otherwise ! * the supertype is simply left null (in this case, the supertype is assumed to be the head of ! * the bound list passed as second argument). Note that this check might cause a symbol completion. ! * Hence, this version of setBounds may not be called during a classfile read. ! * * @param t a type variable * @param bounds the bounds, must be nonempty */ public void setBounds(TypeVar t, List<Type> bounds) { setBounds(t, bounds, bounds.head.tsym.isInterface()); } /** ! * Set the bounds field of the given type variable to reflect a (possibly multiple) list of bounds. ! * This does not cause symbol completion as an extra parameter indicates as to whether all bounds ! * are interfaces - in which case the supertype is implicitly assumed to be 'Object'. ! * ! * @param t a type variable ! * @param bounds the bounds, must be nonempty ! * @param allInterfaces are all bounds interface types? */ public void setBounds(TypeVar t, List<Type> bounds, boolean allInterfaces) { t.bound = bounds.tail.isEmpty() ? bounds.head : ! makeIntersectionType(bounds, allInterfaces); t.rank_field = -1; } // </editor-fold> // <editor-fold defaultstate="collapsed" desc="getBounds">
*** 3061,3071 **** Type st = subst(supertype(t)); List<Type> is = subst(interfaces(t)); if (st == supertype(t) && is == interfaces(t)) return t; else ! return makeCompoundType(is.prepend(st)); } } @Override public Type visitWildcardType(WildcardType t, Void ignored) { --- 3073,3083 ---- Type st = subst(supertype(t)); List<Type> is = subst(interfaces(t)); if (st == supertype(t) && is == interfaces(t)) return t; else ! return makeIntersectionType(is.prepend(st)); } } @Override public Type visitWildcardType(WildcardType t, Void ignored) {
*** 3564,3574 **** if (compound.isEmpty()) return null; else if (compound.tail.isEmpty()) return compound.head; else ! return makeCompoundType(compound); } /** * Return the minimum types of a closure, suitable for computing * compoundMin or glb. --- 3576,3586 ---- if (compound.isEmpty()) return null; else if (compound.tail.isEmpty()) return compound.head; else ! return makeIntersectionType(compound); } /** * Return the minimum types of a closure, suitable for computing * compoundMin or glb.
*** 3742,3752 **** // initialized lazily to avoid problems during compiler startup if (arraySuperType == null) { synchronized (this) { if (arraySuperType == null) { // JLS 10.8: all arrays implement Cloneable and Serializable. ! arraySuperType = makeCompoundType(List.of(syms.serializableType, syms.cloneableType), true); } } } return arraySuperType; --- 3754,3764 ---- // initialized lazily to avoid problems during compiler startup if (arraySuperType == null) { synchronized (this) { if (arraySuperType == null) { // JLS 10.8: all arrays implement Cloneable and Serializable. ! arraySuperType = makeIntersectionType(List.of(syms.serializableType, syms.cloneableType), true); } } } return arraySuperType;
*** 3809,3819 **** return createErrorType(errT); else return glbFlattened(union(bounds, lowers), errT); } } ! return makeCompoundType(bounds); } // </editor-fold> // <editor-fold defaultstate="collapsed" desc="hashCode"> /** --- 3821,3831 ---- return createErrorType(errT); else return glbFlattened(union(bounds, lowers), errT); } } ! return makeIntersectionType(bounds); } // </editor-fold> // <editor-fold defaultstate="collapsed" desc="hashCode"> /**