private static String canonicalize(TypeMirror typeMirror) { if (typeMirror instanceof TypeVar) { return ((TypeVar) typeMirror).getUpperBound().toString(); } else if (typeMirror instanceof ArrayType) { return canonicalize(((ArrayType) typeMirror).elemtype) + "[]"; } else { return typeMirror.toString(); } }
if (typeVar.getUpperBound() == null) { return "*"; } else { return getMappedDocType(context, null, typeVar.getUpperBound());
/** * Since type-variable bounds can be recursive, we need to protect against * infinite loops - where the same bounds are checked over and over recursively. */ private boolean checkSameBounds(TypeVar tv1, TypeVar tv2) { TypePair p = new TypePair(tv1, tv2, true); if (cache.add(p)) { try { return visit(tv1.getUpperBound(), tv2.getUpperBound()); } finally { cache.remove(p); } } else { return false; } } };
extending, implementing, List.<JCTree>nil()); ClassSymbol c = (ClassSymbol)a.getUpperBound().tsym; assert (c.flags() & COMPOUND) != 0; cd.sym = c;
extending, implementing, List.<JCTree>nil()); ClassSymbol c = (ClassSymbol)a.getUpperBound().tsym; assert (c.flags() & COMPOUND) != 0; cd.sym = c;
/** Check that a type is within some bounds. * * Used in TypeApply to verify that, e.g., X in V<X> is a valid * type argument. * @param pos Position to be used for error reporting. * @param a The type that should be bounded by bs. * @param bs The bound. */ private void checkExtends(DiagnosticPosition pos, Type a, TypeVar bs) { if (a.isUnbound()) { return; } else if (a.tag != WILDCARD) { a = types.upperBound(a); for (List<Type> l = types.getBounds(bs); l.nonEmpty(); l = l.tail) { if (!types.isSubtype(a, l.head)) { log.error(pos, "not.within.bounds", a); return; } } } else if (a.isExtendsBound()) { if (!types.isCastable(bs.getUpperBound(), types.upperBound(a), Warner.noWarnings)) log.error(pos, "not.within.bounds", a); } else if (a.isSuperBound()) { if (types.notSoftSubtype(types.lowerBound(a), bs.getUpperBound())) log.error(pos, "not.within.bounds", a); } }
/** Check that a type is within some bounds. * * Used in TypeApply to verify that, e.g., X in V<X> is a valid * type argument. * @param pos Position to be used for error reporting. * @param a The type that should be bounded by bs. * @param bs The bound. */ private void checkExtends(DiagnosticPosition pos, Type a, TypeVar bs) { if (a.isUnbound()) { return; } else if (a.tag != WILDCARD) { a = types.upperBound(a); for (List<Type> l = types.getBounds(bs); l.nonEmpty(); l = l.tail) { if (!types.isSubtype(a, l.head)) { log.error(pos, "not.within.bounds", a); return; } } } else if (a.isExtendsBound()) { if (!types.isCastable(bs.getUpperBound(), types.upperBound(a), Warner.noWarnings)) log.error(pos, "not.within.bounds", a); } else if (a.isSuperBound()) { if (types.notSoftSubtype(types.lowerBound(a), bs.getUpperBound())) log.error(pos, "not.within.bounds", a); } }
public List<Type> getBounds() { TypeVar t = (TypeVar)type; Type bound = t.getUpperBound(); if (!bound.isCompound()) return List.of(bound); ClassType ct = (ClassType)bound; if (!ct.tsym.erasure_field.isInterface()) { return ct.interfaces_field.prepend(ct.supertype_field); } else { // No superclass was given in bounds. // In this case, supertype is Object, erasure is first interface. return ct.interfaces_field; } } }
public List<Type> getBounds() { TypeVar t = (TypeVar)type; Type bound = t.getUpperBound(); if (!bound.isCompound()) return List.of(bound); ClassType ct = (ClassType)bound; if (!ct.tsym.erasure_field.isInterface()) { return ct.interfaces_field.prepend(ct.supertype_field); } else { // No superclass was given in bounds. // In this case, supertype is Object, erasure is first interface. return ct.interfaces_field; } } }
public List<Type> getBounds() { TypeVar t = (TypeVar)type; Type bound = t.getUpperBound(); if (!bound.isCompound()) return List.of(bound); ClassType ct = (ClassType)bound; if (!ct.tsym.erasure_field.isInterface()) { return ct.interfaces_field.prepend(ct.supertype_field); } else { // No superclass was given in bounds. // In this case, supertype is Object, erasure is first interface. return ct.interfaces_field; } }
/** * Get the bounds of a type variable as listed in the "extends" clause. */ private static List<Type> getBounds(TypeVar v, DocEnv env) { final Type upperBound = v.getUpperBound(); Name boundname = upperBound.tsym.getQualifiedName(); if (boundname == boundname.table.names.java_lang_Object && !upperBound.isAnnotated()) { return List.nil(); } else { return env.types.getBounds(v); } }
public List<Type> getBounds() { TypeVar t = (TypeVar)type; Type bound = t.getUpperBound(); if (!bound.isCompound()) return List.of(bound); ClassType ct = (ClassType)bound; if (!ct.tsym.erasure_field.isInterface()) { return ct.interfaces_field.prepend(ct.supertype_field); } else { // No superclass was given in bounds. // In this case, supertype is Object, erasure is first interface. return ct.interfaces_field; } }
@Override public CompoundScope visitTypeVar(TypeVar t, Void _unused) { return visit(t.getUpperBound(), null); } }
public static boolean checkTypesAssignable(CompilationInfo info, TypeMirror from, TypeMirror to) { Context c = ((JavacTaskImpl) info.impl.getJavacTask()).getContext(); if (from.getKind() == TypeKind.TYPEVAR) { Types types = Types.instance(c); TypeVar t = types.substBound((TypeVar)from, com.sun.tools.javac.util.List.of((Type)from), com.sun.tools.javac.util.List.of(types.boxedTypeOrType((Type)to))); return info.getTypes().isAssignable(t.getUpperBound(), to) || info.getTypes().isAssignable(to, t.getUpperBound()); } if (from.getKind() == TypeKind.WILDCARD) { from = Types.instance(c).wildUpperBound((Type)from); } return Check.instance(c).checkType(null, (Type)from, (Type)to).getKind() != TypeKind.ERROR; }
@Override boolean sameTypeVars(TypeVar tv1, TypeVar tv2) { return tv1.tsym == tv2.tsym && visit(tv1.getUpperBound(), tv2.getUpperBound()); } @Override
@Override public Type visitTypeVar( Type.TypeVar t, Void s ) { Type bound = eraseBound( t, t.getUpperBound() ); Type lower = eraseBound( t, t.lower ); if( bound == t.getUpperBound() && lower == t.lower ) { return t; } return new Type.TypeVar( t.tsym, bound, lower ); }
@Override public CompoundScope visitTypeVar(TypeVar t, Boolean skipInterface) { return visit(t.getUpperBound(), skipInterface); } }
@Override public Type visitTypeVar( Type.TypeVar t, Void s ) { Type bound = eraseBound( t, t.getUpperBound() ); Type lower = eraseBound( t, t.lower ); if( bound == t.getUpperBound() && lower == t.lower ) { return t; } return new Type.TypeVar( t.tsym, bound, lower ); }