type.java

来自「是一款用JAVA 编写的编译器 具有很强的编译功能」· Java 代码 · 共 1,249 行 · 第 1/3 页

JAVA
1,249
字号
        public int hashCode() {            int h = METHOD;            for (List<Type> thisargs = this.argtypes;                 thisargs.tail != null; /*inlined: thisargs.nonEmpty()*/                 thisargs = thisargs.tail)                h = (h << 5) + thisargs.head.hashCode();            return (h << 5) + this.restype.hashCode();        }        public List<Type>        getParameterTypes() { return argtypes; }        public Type              getReturnType()     { return restype; }        public List<Type>        getThrownTypes()    { return thrown; }        public void setThrown(List<Type> t) {            thrown = t;        }        public boolean isErroneous() {            return                isErroneous(argtypes) ||                restype != null && restype.isErroneous();        }        public Type map(Mapping f) {            List<Type> argtypes1 = map(argtypes, f);            Type restype1 = f.apply(restype);            List<Type> 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 void complete() {            for (List<Type> l = argtypes; l.nonEmpty(); l = l.tail)                l.head.complete();            restype.complete();            for (List<Type> l = thrown; l.nonEmpty(); l = l.tail)                l.head.complete();        }        public List<TypeVar> getTypeVariables() {            return List.nil();        }	public TypeSymbol asElement() {	    return null;	}        public TypeKind getKind() {            return TypeKind.EXECUTABLE;        }        public <R, P> R accept(TypeVisitor<R, P> v, P p) {            return v.visitExecutable(this, p);        }    }    public static class PackageType extends Type implements NoType {        PackageType(TypeSymbol tsym) {            super(PACKAGE, tsym);        }        @Override        public <R,S> R accept(Type.Visitor<R,S> v, S s) {            return v.visitPackageType(this, s);        }        public String toString() {            return tsym.getQualifiedName().toString();        }        public TypeKind getKind() {            return TypeKind.PACKAGE;        }        public <R, P> R accept(TypeVisitor<R, P> v, P p) {            return v.visitNoType(this, p);        }    }    public static class TypeVar extends Type implements TypeVariable {        /** The bound of this type variable; set from outside.         *  Must be nonempty once it is set.         *  For a bound, `bound' is the bound type itself.         *  Multiple bounds are expressed as a single class type which has the         *  individual bounds as superclass, respectively interfaces.         *  The class type then has as `tsym' a compiler generated class `c',         *  which has a flag COMPOUND and whose owner is the type variable         *  itself. Furthermore, the erasure_field of the class         *  points to the first class or interface bound.         */        public Type bound = null;        public Type lower;        public TypeVar(Name name, Symbol owner, Type lower) {            super(TYPEVAR, null);            tsym = new TypeSymbol(0, name, this, owner);            this.lower = lower;        }        public TypeVar(TypeSymbol tsym, Type bound, Type lower) {            super(TYPEVAR, tsym);            this.bound = bound;            this.lower = lower;        }        @Override        public <R,S> R accept(Type.Visitor<R,S> v, S s) {            return v.visitTypeVar(this, s);        }        public Type getUpperBound() { return bound; }        int rank_field = -1;        public Type getLowerBound() {            return lower;        }        public TypeKind getKind() {            return TypeKind.TYPEVAR;        }        public <R, P> R accept(TypeVisitor<R, P> v, P p) {            return v.visitTypeVariable(this, p);        }    }    /** A captured type variable comes from wildcards which can have     *  both upper and lower bound.  CapturedType extends TypeVar with     *  a lower bound.     */    public static class CapturedType extends TypeVar {        public Type lower;        public WildcardType wildcard;        public CapturedType(Name name,			    Symbol owner,			    Type upper,			    Type lower,			    WildcardType wildcard) {            super(name, owner, lower);            assert lower != null;            this.bound = upper;            this.lower = lower;	    this.wildcard = wildcard;        }        @Override        public <R,S> R accept(Type.Visitor<R,S> v, S s) {            return v.visitCapturedType(this, s);        }        public Type getLowerBound() {            return lower;        }	@Override	public String toString() {            return "capture#"		+ (hashCode() & 0xFFFFFFFFL) % PRIME		+ " of "		+ wildcard;        }	static final int PRIME = 997;  // largest prime less than 1000    }    public static abstract class DelegatedType extends Type {        public Type qtype;        public DelegatedType(int tag, Type qtype) {            super(tag, qtype.tsym);            this.qtype = qtype;        }        public String toString() { return qtype.toString(); }        public List<Type> getTypeArguments() { return qtype.getTypeArguments(); }        public Type getEnclosingType() { return qtype.getEnclosingType(); }        public List<Type> getParameterTypes() { return qtype.getParameterTypes(); }        public Type getReturnType() { return qtype.getReturnType(); }        public List<Type> getThrownTypes() { return qtype.getThrownTypes(); }        public List<Type> allparams() { return qtype.allparams(); }        public Type getUpperBound() { return qtype.getUpperBound(); }        public Object clone() { DelegatedType t = (DelegatedType)super.clone(); t.qtype = (Type)qtype.clone(); return t; }        public boolean isErroneous() { return qtype.isErroneous(); }    }    public static class ForAll extends DelegatedType            implements Cloneable, ExecutableType {        public List<Type> tvars;        public ForAll(List<Type> tvars, Type qtype) {            super(FORALL, qtype);            this.tvars = tvars;        }        @Override        public <R,S> R accept(Type.Visitor<R,S> v, S s) {            return v.visitForAll(this, s);        }        public String toString() {            return "<" + tvars + ">" + qtype;        }        public List<Type> getTypeArguments()   { return tvars; }        public void setThrown(List<Type> t) {            qtype.setThrown(t);        }        public Object clone() {            ForAll result = (ForAll)super.clone();            result.qtype = (Type)result.qtype.clone();            return result;        }        public boolean isErroneous()  {            return qtype.isErroneous();        }        public Type map(Mapping f) {            return f.apply(qtype);        }        public boolean contains(Type elem) {            return qtype.contains(elem);        }        public MethodType asMethodType() {            return qtype.asMethodType();        }        public void complete() {            for (List<Type> l = tvars; l.nonEmpty(); l = l.tail) {                ((TypeVar)l.head).bound.complete();            }            qtype.complete();        }        public List<TypeVar> getTypeVariables() {            return List.convert(TypeVar.class, getTypeArguments());        }        public TypeKind getKind() {            return TypeKind.EXECUTABLE;        }        public <R, P> R accept(TypeVisitor<R, P> v, P p) {            return v.visitExecutable(this, p);        }    }    /** A class for instantiatable variables, for use during type     *  inference.     */    public static class UndetVar extends DelegatedType {        public List<Type> lobounds = List.nil();        public List<Type> hibounds = List.nil();        public Type inst = null;        @Override        public <R,S> R accept(Type.Visitor<R,S> v, S s) {            return v.visitUndetVar(this, s);        }        public UndetVar(Type origin) {            super(UNDETVAR, origin);        }        public String toString() {            if (inst != null) return inst.toString();            else return qtype + "?";        }        public Type baseType() {            if (inst != null) return inst.baseType();            else return this;        }    }    /** Represents VOID or NONE.     */    static class JCNoType extends Type implements NoType {	public JCNoType(int tag) {	    super(tag, null);	}	@Override        public TypeKind getKind() {	    switch (tag) {	    case VOID:  return TypeKind.VOID;	    case NONE:  return TypeKind.NONE;            default:		throw new AssertionError("Unexpected tag: " + tag);	    }        }	@Override        public <R, P> R accept(TypeVisitor<R, P> v, P p) {            return v.visitNoType(this, p);        }    }    static class BottomType extends Type implements NullType {	public BottomType() {	    super(TypeTags.BOT, null);	}	@Override        public TypeKind getKind() {            return TypeKind.NULL;        }	@Override        public <R, P> R accept(TypeVisitor<R, P> v, P p) {            return v.visitNull(this, p);        }		@Override	public Type constType(Object value) {	    return this;	}		@Override 	public String stringValue() {	    return "null";	}    }    public static class ErrorType extends ClassType            implements javax.lang.model.type.ErrorType {        public ErrorType() {            super(noType, List.<Type>nil(), 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|ACYCLIC, name, null, container));        }        @Override        public <R,S> R accept(Type.Visitor<R,S> v, S s) {            return v.visitErrorType(this, s);        }        public Type constType(Object constValue) { return this; }        public Type getEnclosingType()          { return this; }        public Type getReturnType()              { return this; }        public Type asSub(Symbol sym)            { return this; }        public Type map(Mapping f)               { return this; }        public boolean isGenType(Type t)         { return true; }        public boolean isErroneous()             { return true; }        public boolean isCompound()              { return false; }        public boolean isInterface()             { return false; }        public List<Type> allparams()            { return List.nil(); }        public List<Type> getTypeArguments()     { return List.nil(); }        public TypeKind getKind() {            return TypeKind.ERROR;        }        public <R, P> R accept(TypeVisitor<R, P> v, P p) {            return v.visitError(this, p);        }    }    /**     * A visitor for types.  A visitor is used to implement operations     * (or relations) on types.  Most common operations on types are     * binary relations and this interface is designed for binary     * relations, that is, operations on the form     * Type&nbsp;&times;&nbsp;S&nbsp;&rarr;&nbsp;R.     * <!-- In plain text: Type x S -> R -->     *     * @param <R> the return type of the operation implemented by this     * visitor; use Void if no return type is needed.     * @param <S> the type of the second argument (the first being the     * type itself) of the operation implemented by this visitor; use     * Void if a second argument is not needed.     */    public interface Visitor<R,S> {        R visitClassType(ClassType t, S s);        R visitWildcardType(WildcardType t, S s);        R visitArrayType(ArrayType t, S s);        R visitMethodType(MethodType t, S s);        R visitPackageType(PackageType t, S s);        R visitTypeVar(TypeVar t, S s);        R visitCapturedType(CapturedType t, S s);        R visitForAll(ForAll t, S s);        R visitUndetVar(UndetVar t, S s);        R visitErrorType(ErrorType t, S s);        R visitType(Type t, S s);    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?