if (typeVar.getUpperBound() == null) { return "*"; } else { return getMappedDocType(context, null, typeVar.getUpperBound());
public TypeVar inlineAsVar(UTypeVar var) throws CouldNotResolveImportException { /* * In order to handle recursively bounded type variables without a stack overflow, * we first cache a type var with no bounds, then we inline the bounds. */ TypeVar typeVar = typeVarCache.get(var.getName()); if (typeVar != null) { return typeVar; } Name name = asName(var.getName()); TypeSymbol sym = new TypeVariableSymbol(0, name, null, symtab().noSymbol); typeVar = new TypeVar(sym, /* bound= */ null, /* lower= */ symtab().botType); sym.type = typeVar; typeVarCache.put(var.getName(), typeVar); // Any recursive uses of var will point to the same TypeVar object generated above. typeVar.bound = var.getUpperBound().inline(this); typeVar.lower = var.getLowerBound().inline(this); return typeVar; }
TypeMirrorHandle<? extends TypeMirror> uBound = typeMirrors.get(1); TypeMirror upperBound = uBound != null ? uBound.resolve(info, map) : null; TypeVar tv = new TypeVar((TypeSymbol)e, (Type)upperBound, (Type)lowerBound); pt = map.get(this); if (pt != null) {
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;
if (t.hasTag(TYPEVAR) && ((TypeVar)t).isCaptured()) { inferenceContext.addVar((TypeVar)t);
newTvars.append(new TypeVar(t.tsym, null, syms.botType));
newTvars.append(new TypeVar(t.tsym, null, syms.botType));
newTvars.append(new TypeVar(t.tsym, null));
newTvars.append(new TypeVar(t.tsym, null, syms.botType));
if (Type.containsAny(upperBounds, vars)) { TypeSymbol fresh_tvar = new TypeVariableSymbol(Flags.SYNTHETIC, uv.qtype.tsym.name, null, uv.qtype.tsym.owner); fresh_tvar.type = new TypeVar(fresh_tvar, types.makeIntersectionType(uv.getBounds(InferenceBound.UPPER)), null); todo.append(uv); uv.inst = fresh_tvar.type;
if (Type.containsAny(upperBounds, vars)) { TypeSymbol fresh_tvar = new TypeVariableSymbol(Flags.SYNTHETIC, uv.qtype.tsym.name, null, uv.qtype.tsym.owner); fresh_tvar.type = new TypeVar(fresh_tvar, types.makeCompoundType(uv.getBounds(InferenceBound.UPPER)), null); todo.append(uv); uv.inst = fresh_tvar.type;
if (t.hasTag(TYPEVAR) && ((TypeVar)t).isCaptured()) { inferenceContext.addVar((TypeVar)t);
/** Convert (implicit) signature to type parameter. */ Type sigToTypeParam() { int start = sigp; while (signature[sigp] != ':') sigp++; Name name = names.fromUtf(signature, start, sigp - start); TypeVar tvar; if (sigEnterPhase) { tvar = new TypeVar(name, currentOwner, syms.botType); typevars.enter(tvar.tsym); } else { tvar = (TypeVar)findTypeVar(name); } List<Type> bounds = List.nil(); boolean allInterfaces = false; if (signature[sigp] == ':' && signature[sigp+1] == ':') { sigp++; allInterfaces = true; } while (signature[sigp] == ':') { sigp++; bounds = bounds.prepend(sigToType()); } if (!sigEnterPhase) { types.setBounds(tvar, bounds.reverse(), allInterfaces); } return tvar; }
/** Convert (implicit) signature to type parameter. */ Type sigToTypeParam() { int start = sigp; while (signature[sigp] != ':') sigp++; Name name = names.fromUtf(signature, start, sigp - start); TypeVar tvar; if (sigEnterPhase) { tvar = new TypeVar(name, currentOwner, syms.botType); typevars.enter(tvar.tsym); } else { tvar = (TypeVar)findTypeVar(name); } List<Type> bounds = List.nil(); boolean allInterfaces = false; if (signature[sigp] == ':' && signature[sigp+1] == ':') { sigp++; allInterfaces = true; } while (signature[sigp] == ':') { sigp++; bounds = bounds.prepend(sigToType()); } if (!sigEnterPhase) { types.setBounds(tvar, bounds.reverse(), allInterfaces); } return tvar; }
/** Convert (implicit) signature to type parameter. */ Type sigToTypeParam() { int start = sigp; while (signature[sigp] != ':') sigp++; Name name = names.fromUtf(signature, start, sigp - start); TypeVar tvar; if (sigEnterPhase) { tvar = new TypeVar(name, currentOwner); typevars.enter(tvar.tsym); } else { tvar = (TypeVar)findTypeVar(name); } List<Type> bounds = List.nil(); Type st = null; if (signature[sigp] == ':' && signature[sigp+1] == ':') { sigp++; st = syms.objectType; } while (signature[sigp] == ':') { sigp++; bounds = bounds.prepend(sigToType()); } if (!sigEnterPhase) { types.setBounds(tvar, bounds.reverse(), st); } return tvar; }
/** Find type variable with given name in `typevars' scope. */ Type findTypeVar(Name name) { Scope.Entry e = typevars.lookup(name); if (e.scope != null) { return e.sym.type; } else { if (readingClassAttr) { // While reading the class attribute, the supertypes // might refer to a type variable from an enclosing element // (method or class). // If the type variable is defined in the enclosing class, // we can actually find it in // currentOwner.owner.type.getTypeArguments() // However, until we have read the enclosing method attribute // we don't know for sure if this owner is correct. It could // be a method and there is no way to tell before reading the // enclosing method attribute. TypeVar t = new TypeVar(name, currentOwner, syms.botType); missingTypeVariables = missingTypeVariables.prepend(t); // System.err.println("Missing type var " + name); return t; } throw badClassFile("undecl.type.var", name); } }
/** Find type variable with given name in `typevars' scope. */ Type findTypeVar(Name name) { Scope.Entry e = typevars.lookup(name); if (e.scope != null) { return e.sym.type; } else { if (readingClassAttr) { // While reading the class attribute, the supertypes // might refer to a type variable from an enclosing element // (method or class). // If the type variable is defined in the enclosing class, // we can actually find it in // currentOwner.owner.type.getTypeArguments() // However, until we have read the enclosing method attribute // we don't know for sure if this owner is correct. It could // be a method and there is no way to tell before reading the // enclosing method attribute. TypeVar t = new TypeVar(name, currentOwner); missingTypeVariables = missingTypeVariables.prepend(t); // System.err.println("Missing type var " + name); return t; } throw badClassFile("undecl.type.var", name); } }
/** 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); } }
/** Convert (implicit) signature to type parameter. */ Type sigToTypeParam() { int start = sigp; while (signature[sigp] != ':') sigp++; Name name = names.fromUtf(signature, start, sigp - start); TypeVar tvar; if (sigEnterPhase) { tvar = new TypeVar(name, currentOwner, syms.botType); typevars.enter(tvar.tsym); } else { tvar = (TypeVar)findTypeVar(name); } List<Type> bounds = List.nil(); Type st = null; if (signature[sigp] == ':' && signature[sigp+1] == ':') { sigp++; st = syms.objectType; } while (signature[sigp] == ':') { sigp++; bounds = bounds.prepend(sigToType()); } if (!sigEnterPhase) { types.setBounds(tvar, bounds.reverse(), st); } return tvar; }