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

📄 symbol.java

📁 java编译器gjc源码 java编译环境
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
      *                This must be a subclass of the member's owner.
      */
    public boolean isInheritedIn(Symbol clazz) {
        switch ((int)(flags_field & Flags.AccessFlags)) {
        case PUBLIC:
            return true;

        case PRIVATE:
            return this.owner == clazz;

        case PROTECTED:
            return (clazz.flags() & INTERFACE) == 0;

        case 0:
            PackageSymbol thisPackage = this.packge();
            for (Symbol sup = clazz; sup != null && sup != this.owner;
                    sup = sup.type.supertype().tsym)
                if (sup.packge() != thisPackage)
                    return false;
            return (clazz.flags() & INTERFACE) == 0;

        default:
            throw new AssertionError();

        }
    }

    /**
      * The (variable or method) symbol seen as a member of given
      *  class type`site' (this might change the symbol's type).
      */
    public Symbol asMemberOf(Type site) {
        throw new AssertionError();
    }

    /**
      * Complete the elaboration of this symbol's definition.
      */
    public void complete() throws CompletionFailure {
        if (completer != null) {
            Completer c = completer;
            completer = null;
            c.complete(this);
        }
    }

    /**
      * A class for type symbols. Type variables are represented by instances
      *  of this class, classes and packages by instances of subclasses.
      */
    public static class TypeSymbol extends Symbol {

        public TypeSymbol(long flags, Name name, Type type, Symbol owner) {
            super(TYP, flags, name, type, owner);
        }

        public String toString() {
            return "type variable " + name;
        }

        /**
          * form a fully qualified name from a name and an owner
          */
        public static Name formFullName(Name name, Symbol owner) {
            if (owner == null)
                return name;
            if (((owner.kind != ERR)) && ((owner.kind & (VAR | MTH)) != 0))
                return name;
            Name prefix = owner.fullName();
            if (prefix == null || prefix == prefix.table.empty ||
                    prefix == prefix.table.emptyPackage)
                return name;
            else
                return prefix.append('.', name);
        }

        /**
          * form a fully qualified name from a name and an owner, after
          *  converting to flat representation
          */
        public static Name formFlatName(Name name, Symbol owner) {
            if (owner == null || (owner.kind & (VAR | MTH)) != 0)
                return name;
            char sep = owner.kind == TYP ? '$' : '.';
            Name prefix = owner.flatName();
            if (prefix == null || prefix == prefix.table.empty ||
                    prefix == prefix.table.emptyPackage)
                return name;
            else
                return prefix.append(sep, name);
        }

        /**
          * The rank of a class is the length of the longest path
          *  between the class and java.lang.Object in the class inheritance
          *  graph. Undefined for all other type symbols.
          */
        public int rank() {
            throw new AssertionError();
        }

        /**
          * A total ordering between type symbols that refines the class
          *  inheritance graph. Typevariables always precede other type symbols.
          */
        public boolean precedes(TypeSymbol that) {
            return this != that;
        }

        /**
          * If symbol is a package, does it exist?
          *  Otherwise always true.
          */
        public boolean exists() {
            return true;
        }
    }

    /**
      * A class for package symbols
      */
    public static class PackageSymbol extends TypeSymbol {
        public Scope members_field;
        public Name fullname;

        public PackageSymbol(Name name, Type type, Symbol owner) {
            super(0, name, type, owner);
            this.kind = PCK;
            this.members_field = null;
            this.fullname = formFullName(name, owner);
        }

        public PackageSymbol(Name name, Symbol owner) {
            this(name, null, owner);
            this.type = new PackageType(this);
        }

        public String toString() {
            return "package " + fullname;
        }

        /**
          * The Java source which this symbol represents.  Use of this method
          *  will result in the loss of the plain-language description for
          *  the symbol.
          */
        public String toJava() {
            return fullname.toString();
        }

        public Name fullName() {
            return fullname;
        }

        public Scope members() {
            if (completer != null)
                complete();
            return members_field;
        }

        public long flags() {
            if (completer != null)
                complete();
            return flags_field;
        }

        /**
          * A package "exists" if a type or package that exists has
          *  been seen within it.
          */
        public boolean exists() {
            return (flags_field & EXISTS) != 0;
        }
    }

    /**
      * A class for class symbols
      */
    public static class ClassSymbol extends TypeSymbol {

        /**
         * a scope for all class members; variables, methods and inner classes
         *  type parameters are not part of this scope
         */
        public Scope members_field;

        /**
         * the fully qualified name of the class, i.e. pck.outer.inner.
         *  null for anonymous classes
         */
        public Name fullname;

        /**
         * the fully qualified name of the class after converting to flat
         *  representation, i.e. pck.outer$inner,
         *  set externally for local and anonymous classes
         */
        public Name flatname;

        /**
         * the sourcefile where the class came from
         */
        public Name sourcefile;

        /**
         * the classfile from where to load this class
         *  this will have extension .class or .java
         */
        public FileEntry classfile;

        /**
         * the constant pool of the class
         */
        public Pool pool;

        /**
         * a cache for the rank of the class. @see rank()
         */
        private int rank_field = -1;

        public ClassSymbol(long flags, Name name, Type type, Symbol owner) {
            super(flags, name, type, owner);
            this.members_field = null;
            this.fullname = formFullName(name, owner);
            this.flatname = formFlatName(name, owner);
            this.sourcefile = null;
            this.classfile = null;
            this.pool = null;
        }

        public ClassSymbol(long flags, Name name, Symbol owner) {
            this(flags, name, new ClassType(Type.noType, Type.emptyList, null),
                    owner);
            this.type.tsym = this;
        }
        public static final List emptyList = new List();

        public String toString() {
            if ((flags_field & COMPOUND) != 0)
                return "type variable " + name;
            else if ((flags_field & INTERFACE) != 0)
                return "interface " + className();
            else
                return "class " + className();
        }

        /**
          * The Java source which this symbol represents.  Use of this method
          *  will result in the loss of the plain-language description for
          *  the symbol.
          */
        public String toJava() {
            return className();
        }

        public long flags() {
            if (completer != null)
                complete();
            return flags_field;
        }

        public Scope members() {
            if (completer != null)
                complete();
            return members_field;
        }

        public Type erasure() {
            if (erasure_field == null)
                if (type.isParameterized())
                    erasure_field = new ClassType(type.outer().erasure(),
                            Type.emptyList, this);
                else
                    erasure_field = type;
            return erasure_field;
        }

        public String className() {
            if (name.len == 0)
                return Log.getLocalizedString("anonymous.class", flatname.toString());
            else
                return fullname.toString();
        }

        public Name fullName() {
            return fullname;
        }

        public Name flatName() {
            return flatname;
        }

        public boolean isSubClass(Symbol base) {
            if (this == base) {
                return true;
            } else if ((base.flags() & INTERFACE) != 0) {
                for (Type t = type; t.tag == CLASS; t = t.supertype())
                    for (List is = t.interfaces(); is.nonEmpty(); is = is.tail)
                        if (((Type) is.head).tsym.isSubClass(base))
                            return true;
            } else {
                for (Type t = type; t.tag == CLASS; t = t.supertype())
                    if (t.tsym == base)
                        return true;
            }
            return false;
        }

        /**
          * The rank of a class is the length of the longest path to Object
          *  in the class inheritance graph.
          */
        public int rank() {
            if (rank_field < 0) {
                Name fiulname = fullName();
                if (fullname == fullname.table.java_lang_Object || type.tag == ERROR)
                    rank_field = 0;
                else {
                    int r = type.supertype().tsym.rank();
                    for (List l = type.interfaces(); l.nonEmpty(); l = l.tail) {
                        if (((Type) l.head).tsym.rank() > r)
                            r = ((Type) l.head).tsym.rank();
                    }
                    rank_field = r + 1;
                }
            }
            return rank_field;
        }

⌨️ 快捷键说明

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