标签:符号 对象 java star turn base art 代码 exist
/**
* Return the (most specific) base type of t that starts with the
* given symbol. If none exists, return null.
*
* @param t a type
* @param sym a symbol
*/
public Type asSuper(Type t, Symbol sym) {
return asSuper.visit(t, sym);
}
asSuper对象的定义如下:
private SimpleVisitor<Type,Symbol> asSuper = new SimpleVisitor<Type,Symbol>() {
public Type visitType(Type t, Symbol sym) {
return null;
}
@Override
public Type visitClassType(ClassType t, Symbol sym) {
if (t.tsym == sym)
return t;
Type st = supertype(t);
if (st.tag == CLASS || st.tag == TYPEVAR || st.tag == ERROR) {
Type x = asSuper(st, sym);
if (x != null)
return x;
}
if ((sym.flags() & INTERFACE) != 0) {
for (List<Type> l = interfaces(t); l.nonEmpty(); l = l.tail) {
Type x = asSuper(l.head, sym);
if (x != null)
return x;
}
}
return null;
}
@Override
public Type visitArrayType(ArrayType t, Symbol sym) {
return isSubtype(t, sym.type) ? sym.type : null;
}
@Override
public Type visitTypeVar(TypeVar t, Symbol sym) {
if (t.tsym == sym)
return t;
else
return asSuper(t.bound, sym);
}
@Override
public Type visitErrorType(ErrorType t, Symbol sym) {
return t;
}
};
通过实现代码可以了解到,对ClassType、ArrayType与TypeVariable进行了处理。其中在t及其父类和实现的接口中查找sym符号时,由于t为数组类型,所以符号只能是Clonable与Serializable
标签:符号 对象 java star turn base art 代码 exist
原文地址:http://www.cnblogs.com/extjs4/p/7617338.html