⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 type.java

📁 javac是sun公司开发人员使用java语言编写的优秀的工业级java编译器
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            if (((flags & STATIC) == 0) && owner.type.isParameterized()) {                Type base = this.asOuterSuper(owner);                if (base != null) {                    List ownerParams = owner.type.allparams();                    List baseParams = base.allparams();                    if (ownerParams.nonEmpty()) {                        if (baseParams.isEmpty()) {                            return sym.type.erasure();                        } else {                            return sym.type.subst(ownerParams, baseParams);                        }                    }                }            }            return sym.type;        }        public Type subst(List from, List to) {            if (from.tail == null) {                return this;            } else if ((tsym.flags() & COMPOUND) == 0) {                Type outer = outer();                List typarams = typarams();                List typarams1 = subst(typarams, from, to);                Type outer1 = outer.subst(from, to);                if (typarams1 == typarams && outer1 == outer)                    return this;                else                    return new ClassType(outer1, typarams1, tsym);            } else {                Type st = supertype().subst(from, to);                List is = subst(interfaces(), from, to);                if (st == supertype() && is == interfaces())                    return this;                else                    return makeCompoundType(is.prepend(st), tsym);            }        }        public boolean isErroneous() {            return outer().isErroneous() || isErroneous(typarams()) ||                    this != tsym.type && tsym.type.isErroneous();        }        public boolean isParameterized() {            return allparams().tail != null;        }        public Type erasure() {            return tsym.erasure();        }        public Type map(Mapping f) {            Type outer = outer();            Type outer1 = f.apply(outer);            List typarams = typarams();            List typarams1 = map(typarams, f);            if (outer1 == outer && typarams1 == typarams)                return this;            else                return new ClassType(outer1, typarams1, tsym);        }        public boolean contains(Type elem) {            return elem == this || (isParameterized() &&                    (outer().contains(elem) || contains(typarams(), elem)));        }        public boolean isSameType(Type that) {            if (this == that)                return true;            if (that.tag >= firstPartialTag)                return that.isSameType(this);            return this.tsym == that.tsym && this.outer().isSameType(that.outer()) &&                    isSameTypes(this.typarams(), that.typarams());        }        public boolean isSubType(Type that) {            if (this == that)                return true;            if (that.tag >= firstPartialTag)                return that.isSuperType(this);            if (this.tsym == that.tsym)                return (!that.isParameterized() ||                        isSameTypes(this.typarams(), that.typarams())) &&                        this.outer().isSubType(that.outer());            if ((that.tsym.flags() & INTERFACE) != 0)                for (List is = this.interfaces(); is.nonEmpty(); is = is.tail)                    if (((Type) is.head).isSubType(that))                        return true;            Type st = this.supertype();            if (st.tag == CLASS && st.isSubType(that))                return true;            return st.isErroneous();        }        /**          * The rules for castability are extended to parameterized types          *  as follows:          *  (1) One may always cast to a supertype          *  (2) One may cast to a subtype C<...> provided there is only          *      one type with the subtype's class part, C, that is a subtype          *      of this type. (This is equivalent to: C<...> = this.asSub(C).          *  (3) One may cast an interface to an unparameterized class.          *  (4) One may cast a non-final class to an unparameterized interface.          */        public boolean isCastable(Type that) {            return that.tag == ERROR || (that.tag == CLASS || that.tag == ARRAY) &&                    (this.isSubType(that) || (that.isSubType(this) &&                    (that.tag == ARRAY || that.tsym.type == that ||                    (this.asSub(that.tsym) != null &&                    that.isSameType(this.asSub(that.tsym))))) ||                    that.tag == CLASS && that.allparams().isEmpty() &&                    ((that.tsym.flags() & INTERFACE) != 0 &&                    (this.tsym.flags() & FINAL) == 0 ||                    (this.tsym.flags() & INTERFACE) != 0 &&                    (that.tsym.flags() & FINAL) == 0));        }        public void complete() {            if (tsym.completer != null)                tsym.complete();        }    }    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 + -