📄 type.java
字号:
public static class ArrayType extends Type {
public Type elemtype;
public ArrayType(Type elemtype, TypeSymbol arrayClass) {
super(ARRAY, arrayClass);
this.elemtype = elemtype;
}
public String toString() {
return elemtype + "[]";
}
public String toJava() {
return toString();
}
public boolean equals(Object that) {
return this == that || (that instanceof ArrayType &&
this.elemtype.equals(((ArrayType) that).elemtype));
}
public int hashCode() {
return (ARRAY << 5) + elemtype.hashCode();
}
public Type elemtype() {
return elemtype;
}
public int dimensions() {
int result = 0;
for (Type t = this; t.tag == ARRAY; t = t.elemtype()) {
result++;
}
return result;
}
public List allparams() {
return elemtype.allparams();
}
public Type subst(List from, List to) {
if (from.tail == null) {
return this;
} else {
Type elemtype1 = elemtype.subst(from, to);
if (elemtype1 == elemtype)
return this;
else
return new ArrayType(elemtype1, tsym);
}
}
public boolean isErroneous() {
return elemtype.isErroneous();
}
public boolean isParameterized() {
return elemtype.isParameterized();
}
public Type map(Mapping f) {
Type elemtype1 = f.apply(elemtype);
if (elemtype1 == elemtype)
return this;
else
return new ArrayType(elemtype1, tsym);
}
public boolean contains(Type elem) {
return elem == this || elemtype.contains(elem);
}
public Type asSuper(Symbol sym) {
return (this.isSubType(sym.type)) ? sym.type : null;
}
public Type asOuterSuper(Symbol sym) {
return (this.isSubType(sym.type)) ? sym.type : null;
}
public boolean isSameType(Type that) {
if (this == that)
return true;
if (that.tag >= firstPartialTag)
return that.isSameType(this);
return that.tag == ARRAY && this.elemtype.isSameType(that.elemtype());
}
public boolean isSubType(Type that) {
if (this == that)
return true;
if (that.tag >= firstPartialTag)
return that.isSuperType(this);
if (that.tag == ARRAY) {
if (this.elemtype.tag <= lastBaseTag)
return this.elemtype.isSameType(that.elemtype());
else
return this.elemtype.isSubType(that.elemtype());
} else if (that.tag == CLASS) {
Name thatname = that.tsym.fullName();
Name.Table names = thatname.table;
return (thatname == names.java_lang_Object ||
thatname == names.java_lang_Cloneable ||
thatname == names.java_io_Serializable);
} else {
return false;
}
}
public boolean isCastable(Type that) {
return that.tag == ERROR || (that.tag == CLASS && this.isSubType(that)) ||
that.tag == ARRAY && (this.elemtype().tag <= lastBaseTag ?
this.elemtype().tag == that.elemtype().tag :
this.elemtype().isCastable(that.elemtype()));
}
public void complete() {
elemtype.complete();
}
}
public static class MethodType extends Type implements Cloneable {
public List argtypes;
public Type restype;
public List thrown;
public MethodType(List argtypes, Type restype, List thrown,
TypeSymbol methodClass) {
super(METHOD, methodClass);
this.argtypes = argtypes;
this.restype = restype;
this.thrown = thrown;
}
public String toString() {
return "(" + argtypes.toString() + ")" + restype;
}
/**
* The Java source which this type represents. Use of this method
* will result in the loss of the plain-language description for
* the type.
*
* XXX 06/09/99 iris This isn't correct Java syntax, but it probably
* should be.
*/
public String toJava() {
return "(" + argtypes.toString() + ")" + restype.toString();
}
public boolean equals(Object that) {
if (this == that)
return true;
if (!(that instanceof MethodType))
return false;
MethodType mthat = (MethodType) that;
List thisargs = this.argtypes;
List thatargs = mthat.argtypes;
while (thisargs.tail != null && thatargs.tail != null &&
((Type) thisargs.head).equals(thatargs.head)) {
thisargs = thisargs.tail;
thatargs = thatargs.tail;
}
if (thisargs.tail != null || thatargs.tail != null)
return false;
return this.restype.equals(mthat.restype);
}
public int hashCode() {
int h = METHOD;
for (List thisargs = this.argtypes; thisargs.tail != null;
thisargs = thisargs.tail)
h = (h << 5) + ((Type) thisargs.head).hashCode();
return (h << 5) + this.restype.hashCode();
}
public List argtypes() {
return argtypes;
}
public Type restype() {
return restype;
}
public List thrown() {
return thrown;
}
public void setThrown(List t) {
thrown = t;
}
public Type subst(List from, List to) {
if (from.tail == null) {
return this;
} else {
List argtypes1 = subst(argtypes, from, to);
Type restype1 = restype.subst(from, to);
List thrown1 = subst(thrown, from, to);
if (argtypes1 == argtypes && restype1 == restype && thrown1 == thrown)
return this;
else
return new MethodType(argtypes1, restype1, thrown1, tsym);
}
}
public boolean isErroneous() {
return isErroneous(argtypes) || restype.isErroneous();
}
public Type map(Mapping f) {
List argtypes1 = map(argtypes, f);
Type restype1 = f.apply(restype);
List thrown1 = map(thrown, f);
if (argtypes1 == argtypes && restype1 == restype && thrown1 == thrown)
return this;
else
return new MethodType(argtypes1, restype1, thrown1, tsym);
}
public boolean contains(Type elem) {
return elem == this || contains(argtypes, elem) || restype.contains(elem);
}
public MethodType asMethodType() {
return this;
}
public boolean hasSameArgs(Type that) {
return that.tag == METHOD && isSameTypes(this.argtypes, that.argtypes());
}
/**
* isSameType for methods does not take thrown exceptions into account!
*/
public boolean isSameType(Type that) {
return hasSameArgs(that) && restype.isSameType(that.restype());
}
public void complete() {
for (List l = argtypes; l.nonEmpty(); l = l.tail)
((Type) l.head).complete();
restype.complete();
for (List l = thrown; l.nonEmpty(); l = l.tail)
((Type) l.head).complete();
}
}
public static class PackageType extends Type {
PackageType(TypeSymbol tsym) {
super(PACKAGE, tsym);
}
public String toString() {
return tsym.fullName().toString();
}
public boolean isSameType(Type that) {
return this == that;
}
}
public static class ErrorType extends ClassType {
public ErrorType() {
super(noType, emptyList, null);
tag = ERROR;
}
public ErrorType(ClassSymbol c) {
this();
tsym = c;
c.type = this;
c.kind = ERR;
c.members_field = new Scope.ErrorScope(c);
}
public ErrorType(Name name, TypeSymbol container) {
this(new ClassSymbol(PUBLIC | STATIC, name, null, container));
}
public Type constType(Object constValue) {
return this;
}
public Type outer() {
return this;
}
public Type elemtype() {
return this;
}
public Type restype() {
return this;
}
public Type asSuper(Symbol sym) {
return this;
}
public Type asOuterSuper(Symbol sym) {
return this;
}
public Type asSub(Symbol sym) {
return this;
}
public Type memberType(Symbol sym) {
return this;
}
public Type classBound() {
return this;
}
public Type subst(List from, List to) {
return this;
}
public Type erasure() {
return this;
}
public Type unerasure() {
return this;
}
public boolean isGenType(Type that) {
return true;
}
public boolean isErroneous() {
return true;
}
public boolean isSameType(Type that) {
return true;
}
public boolean isSubType(Type that) {
return true;
}
public boolean isSuperType(Type that) {
return true;
}
public boolean isCastable(Type that) {
return true;
}
public boolean hasSameArgs(Type that) {
return false;
}
public boolean isAssignable(Type that) {
return true;
}
public List allparams() {
return emptyList;
}
public List typarams() {
return emptyList;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -