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; }
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; }
/** 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; }
/** 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); } }
/** Class enter visitor method for type parameters. * Enter a symbol for type parameter in local scope, after checking that it * is unique. */ @Override public void visitTypeParameter(JCTypeParameter tree) { TypeVar a = (tree.type != null) ? (TypeVar)tree.type : new TypeVar(tree.name, env.info.scope.owner, syms.botType); tree.type = a; if (chk.checkUnique(tree.pos(), a.tsym, env.info.scope)) { env.info.scope.enter(a.tsym); } result = a; }
public Type apply(Type t) { return new TypeVar(t.tsym, t.getUpperBound(), t.getLowerBound()); } };
/** Class enter visitor method for type parameters. * Enter a symbol for type parameter in local scope, after checking that it * is unique. */ @Override public void visitTypeParameter(JCTypeParameter tree) { TypeVar a = (tree.type != null) ? (TypeVar)tree.type : new TypeVar(tree.name, env.info.scope.owner, syms.botType); tree.type = a; if (chk.checkUnique(tree.pos(), a.tsym, env.info.scope)) { env.info.scope.enter(a.tsym); } result = a; }
public Type apply(Type t) { return new TypeVar(t.tsym, t.getUpperBound()); } };
public Type apply(Type t) { return new TypeVar(t.tsym, t.getUpperBound(), t.getLowerBound()); } };
public Type apply(Type t) { return new TypeVar(t.tsym, t.getUpperBound(), t.getLowerBound()); } };
/** Class enter visitor method for type parameters. * Enter a symbol for type parameter in local scope, after checking that it * is unique. */ public void visitTypeParameter(JCTypeParameter tree) { TypeVar a = (tree.type != null) ? (TypeVar)tree.type : new TypeVar(tree.name, env.info.scope.owner); tree.type = a; if (chk.checkUnique(tree.pos(), a.tsym, env.info.scope)) { env.info.scope.enter(a.tsym); } result = a; }
void synthesizeTyparams(ClassSymbol sym, int n) { ClassType ct = (ClassType) sym.type; Assert.check(ct.typarams_field.isEmpty()); if (n == 1) { TypeVar v = new TypeVar(names.fromString("T"), sym, syms.botType); ct.typarams_field = ct.typarams_field.prepend(v); } else { for (int i = n; i > 0; i--) { TypeVar v = new TypeVar(names.fromString("T" + i), sym, syms.botType); ct.typarams_field = ct.typarams_field.prepend(v); } } } }
public TypeVar substBound(TypeVar t, List<Type> from, List<Type> to) { Type bound1 = subst(t.bound, from, to); if (bound1 == t.bound) return t; else { // create new type variable without bounds TypeVar tv = new TypeVar(t.tsym, null, syms.botType); // the new bound should use the new type variable in place // of the old tv.bound = subst(bound1, List.<Type>of(t), List.<Type>of(tv)); return tv; } } // </editor-fold>
public TypeVar substBound(TypeVar t, List<Type> from, List<Type> to) { Type bound1 = subst(t.bound, from, to); if (bound1 == t.bound) return t; else { // create new type variable without bounds TypeVar tv = new TypeVar(t.tsym, null, syms.botType); // the new bound should use the new type variable in place // of the old tv.bound = subst(bound1, List.<Type>of(t), List.<Type>of(tv)); return tv; } } // </editor-fold>
void synthesizeTyparams(ClassSymbol sym, int n) { ClassType ct = (ClassType) sym.type; Assert.check(ct.typarams_field.isEmpty()); if (n == 1) { TypeVar v = new TypeVar(names.fromString("T"), sym, syms.botType); ct.typarams_field = ct.typarams_field.prepend(v); } else { for (int i = n; i > 0; i--) { TypeVar v = new TypeVar(names.fromString("T" + i), sym, syms.botType); ct.typarams_field = ct.typarams_field.prepend(v); } } } }
/** Class enter visitor method for type parameters. * Enter a symbol for type parameter in local scope, after checking that it * is unique. */ public void visitTypeParameter(JCTypeParameter tree) { TypeVar a = (tree.type != null) ? (TypeVar)tree.type : new TypeVar(tree.name, env.info.scope.owner, syms.botType); tree.type = a; if (chk.checkUnique(tree.pos(), a.tsym, env.info.scope)) { env.info.scope.enter(a.tsym); } result = a; }
public TypeVar substBound(TypeVar t, List<Type> from, List<Type> to) { Type bound1 = subst(t.bound, from, to); if (bound1 == t.bound) return t; else return new TypeVar(t.tsym, bound1, syms.botType); } // </editor-fold>
public TypeVar substBound(TypeVar t, List<Type> from, List<Type> to) { Type bound1 = subst(t.bound, from, to); if (bound1 == t.bound) return t; else return new TypeVar(t.tsym, bound1); } // </editor-fold>
@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 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 ); }