use of com.sun.tools.javac.code.Type in project ceylon-compiler by ceylon.
the class Printer method className.
/**
* Converts a class name into a (possibly localized) string. Anonymous
* inner classes gets converted into a localized string.
*
* @param t the type of the class whose name is to be rendered
* @param longform if set, the class' fullname is displayed - if unset the
* short name is chosen (w/o package)
* @param locale the locale in which the string is to be rendered
* @return localized string representation
*/
protected String className(ClassType t, boolean longform, Locale locale) {
Symbol sym = t.tsym;
if (sym.name.length() == 0 && (sym.flags() & COMPOUND) != 0) {
StringBuffer s = new StringBuffer(visit(t.supertype_field, locale));
for (List<Type> is = t.interfaces_field; is.nonEmpty(); is = is.tail) {
s.append("&");
s.append(visit(is.head, locale));
}
return s.toString();
} else if (sym.name.length() == 0) {
String s;
ClassType norm = (ClassType) t.tsym.type;
if (norm == null) {
s = localize(locale, "compiler.misc.anonymous.class", (Object) null);
} else if (norm.interfaces_field.nonEmpty()) {
s = localize(locale, "compiler.misc.anonymous.class", visit(norm.interfaces_field.head, locale));
} else {
s = localize(locale, "compiler.misc.anonymous.class", visit(norm.supertype_field, locale));
}
return s;
} else if (longform) {
return sym.getQualifiedName().toString();
} else {
return sym.name.toString();
}
}
use of com.sun.tools.javac.code.Type in project ceylon-compiler by ceylon.
the class Symbol method hiddenIn.
/** Check for hiding. Note that this doesn't handle multiple
* (interface) inheritance. */
private boolean hiddenIn(ClassSymbol clazz, Types types) {
if (kind == MTH && (flags() & STATIC) == 0)
return false;
while (true) {
if (owner == clazz)
return false;
Scope.Entry e = clazz.members().lookup(name);
while (e.scope != null) {
if (e.sym == this)
return false;
if (e.sym.kind == kind && (kind != MTH || (e.sym.flags() & STATIC) != 0 && types.isSubSignature(e.sym.type, type)))
return true;
e = e.next();
}
Type superType = types.supertype(clazz.type);
if (superType.tag != TypeTags.CLASS)
return false;
clazz = (ClassSymbol) superType.tsym;
}
}
use of com.sun.tools.javac.code.Type in project ceylon-compiler by ceylon.
the class Types method setBounds.
/**
* 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) {
Type supertype = (bounds.head.tsym.flags() & INTERFACE) != 0 ? syms.objectType : null;
setBounds(t, bounds, supertype);
t.rank_field = -1;
}
use of com.sun.tools.javac.code.Type in project ceylon-compiler by ceylon.
the class Types method sideCastFinal.
private boolean sideCastFinal(Type from, Type to, Warner warn) {
// We are casting from type $from$ to type $to$, which are
// unrelated types one of which is final and the other of
// which is an interface. This method
// tries to reject a cast by transferring type parameters
// from the final class to the interface.
boolean reverse = false;
Type target = to;
if ((to.tsym.flags() & INTERFACE) == 0) {
Assert.check((from.tsym.flags() & INTERFACE) != 0);
reverse = true;
to = from;
from = target;
}
Assert.check((from.tsym.flags() & FINAL) != 0);
Type t1 = asSuper(from, to.tsym);
if (t1 == null)
return false;
Type t2 = to;
if (disjointTypes(t1.getTypeArguments(), t2.getTypeArguments()))
return false;
if (!allowCovariantReturns)
// reject if there is a common method signature with
// incompatible return types.
chk.checkCompatibleAbstracts(warn.pos(), from, to);
if (!isReifiable(target) && (reverse ? giveWarning(t2, t1) : giveWarning(t1, t2)))
warn.warn(LintCategory.UNCHECKED);
return true;
}
use of com.sun.tools.javac.code.Type in project ceylon-compiler by ceylon.
the class Types method closure.
/**
* Returns the closure of a class or interface type.
*/
public List<Type> closure(Type t) {
List<Type> cl = closureCache.get(t);
if (cl == null) {
Type st = supertype(t);
if (!t.isCompound()) {
if (st.tag == CLASS) {
cl = insert(closure(st), t);
} else if (st.tag == TYPEVAR) {
cl = closure(st).prepend(t);
} else {
cl = List.of(t);
}
} else {
cl = closure(supertype(t));
}
for (List<Type> l = interfaces(t); l.nonEmpty(); l = l.tail) cl = union(cl, closure(l.head));
closureCache.put(t, cl);
}
return cl;
}
Aggregations