jctree.java

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

JAVA
2,048
字号
     * @param pid              The tree representing the package clause.     * @param sourcefile       The source file name.     * @param defs             All definitions in this file (ClassDef, Import, and Skip)     * @param packge           The package it belongs to.     * @param namedImportScope A scope for all named imports.     * @param starImportScope  A scope for all import-on-demands.     * @param lineMap          Line starting positions, defined only     *                         if option -g is set.     * @param docComments      A hashtable that stores all documentation comments     *                         indexed by the tree nodes they refer to.     *                         defined only if option -s is set.     * @param endPositions     A hashtable that stores ending positions of source     *                         ranges indexed by the tree nodes they belong to.     *                         Defined only if option -Xjcov is set.     */    public static class JCCompilationUnit extends JCTree implements CompilationUnitTree {        public List<JCAnnotation> packageAnnotations;        public JCExpression pid;        public List<JCTree> defs;        public JavaFileObject sourcefile;        public PackageSymbol packge;        public Scope namedImportScope;        public Scope starImportScope;        public long flags;        public Position.LineMap lineMap = null;        public Map<JCTree, String> docComments = null;        public Map<JCTree, Integer> endPositions = null;        protected JCCompilationUnit(List<JCAnnotation> packageAnnotations,                        JCExpression pid,                        List<JCTree> defs,                        JavaFileObject sourcefile,                        PackageSymbol packge,                        Scope namedImportScope,                        Scope starImportScope) {            this.packageAnnotations = packageAnnotations;            this.pid = pid;            this.defs = defs;            this.sourcefile = sourcefile;            this.packge = packge;            this.namedImportScope = namedImportScope;            this.starImportScope = starImportScope;        }        @Override        public void accept(Visitor v) { v.visitTopLevel(this); }        public Kind getKind() { return Kind.COMPILATION_UNIT; }        public List<JCAnnotation> getPackageAnnotations() {            return packageAnnotations;        }        public List<JCImport> getImports() {            ListBuffer<JCImport> imports = new ListBuffer<JCImport>();            for (JCTree tree : defs) {                if (tree.getTag() == IMPORT)                    imports.append((JCImport)tree);                else                    break;            }            return imports.toList();        }        public JCExpression getPackageName() { return pid; }        public JavaFileObject getSourceFile() {            return sourcefile;        }	public Position.LineMap getLineMap() {	    return lineMap;        }          public List<JCTree> getTypeDecls() {            List<JCTree> typeDefs;            for (typeDefs = defs; !typeDefs.isEmpty(); typeDefs = typeDefs.tail)                if (typeDefs.head.getTag() != IMPORT)                    break;            return typeDefs;        }        @Override        public <R,D> R accept(TreeVisitor<R,D> v, D d) {            return v.visitCompilationUnit(this, d);        }        @Override        public int getTag() {            return TOPLEVEL;        }    }    /**     * An import clause.     * @param qualid    The imported class(es).     */    public static class JCImport extends JCTree implements ImportTree {        public boolean staticImport;        public JCTree qualid;        protected JCImport(JCTree qualid, boolean importStatic) {            this.qualid = qualid;            this.staticImport = importStatic;        }        @Override        public void accept(Visitor v) { v.visitImport(this); }        public boolean isStatic() { return staticImport; }        public JCTree getQualifiedIdentifier() { return qualid; }        public Kind getKind() { return Kind.IMPORT; }        @Override        public <R,D> R accept(TreeVisitor<R,D> v, D d) {            return v.visitImport(this, d);        }        @Override        public int getTag() {            return IMPORT;        }    }    public static abstract class JCStatement extends JCTree implements StatementTree {        @Override        public JCStatement setType(Type type) {            super.setType(type);            return this;        }        @Override        public JCStatement setPos(int pos) {            super.setPos(pos);            return this;        }    }    public static abstract class JCExpression extends JCTree implements ExpressionTree {        @Override        public JCExpression setType(Type type) {            super.setType(type);            return this;        }        @Override        public JCExpression setPos(int pos) {            super.setPos(pos);            return this;        }    }    /**     * A class definition.     * @param modifiers the modifiers     * @param name the name of the class     * @param typarams formal class parameters     * @param extending the classes this class extends     * @param implementing the interfaces implemented by this class     * @param defs all variables and methods defined in this class     * @param sym the symbol     */    public static class JCClassDecl extends JCStatement implements ClassTree {        public JCModifiers mods;        public Name name;        public List<JCTypeParameter> typarams;        public JCTree extending;        public List<JCExpression> implementing;        public List<JCTree> defs;        public ClassSymbol sym;        protected JCClassDecl(JCModifiers mods,			   Name name,			   List<JCTypeParameter> typarams,			   JCTree extending,			   List<JCExpression> implementing,			   List<JCTree> defs,			   ClassSymbol sym)	{            this.mods = mods;            this.name = name;            this.typarams = typarams;            this.extending = extending;            this.implementing = implementing;            this.defs = defs;            this.sym = sym;        }        @Override        public void accept(Visitor v) { v.visitClassDef(this); }        public Kind getKind() { return Kind.CLASS; }        public JCModifiers getModifiers() { return mods; }        public Name getSimpleName() { return name; }        public List<JCTypeParameter> getTypeParameters() {            return typarams;        }        public JCTree getExtendsClause() { return extending; }        public List<JCExpression> getImplementsClause() {            return implementing;        }        public List<JCTree> getMembers() {            return defs;        }        @Override        public <R,D> R accept(TreeVisitor<R,D> v, D d) {            return v.visitClass(this, d);        }        @Override        public int getTag() {            return CLASSDEF;        }    }    /**     * A method definition.     * @param modifiers method modifiers     * @param name method name     * @param restype type of method return value     * @param typarams type parameters     * @param params value parameters     * @param thrown exceptions thrown by this method     * @param stats statements in the method     * @param sym method symbol     */    public static class JCMethodDecl extends JCTree implements MethodTree {        public JCModifiers mods;        public Name name;        public JCExpression restype;        public List<JCTypeParameter> typarams;        public List<JCVariableDecl> params;        public List<JCExpression> thrown;        public JCBlock body;        public JCExpression defaultValue; // for annotation types        public MethodSymbol sym;        protected JCMethodDecl(JCModifiers mods,                            Name name,                            JCExpression restype,                            List<JCTypeParameter> typarams,                            List<JCVariableDecl> params,                            List<JCExpression> thrown,                            JCBlock body,                            JCExpression defaultValue,                            MethodSymbol sym)        {            this.mods = mods;            this.name = name;            this.restype = restype;            this.typarams = typarams;            this.params = params;            this.thrown = thrown;            this.body = body;            this.defaultValue = defaultValue;            this.sym = sym;        }        @Override        public void accept(Visitor v) { v.visitMethodDef(this); }        public Kind getKind() { return Kind.METHOD; }        public JCModifiers getModifiers() { return mods; }        public Name getName() { return name; }        public JCTree getReturnType() { return restype; }        public List<JCTypeParameter> getTypeParameters() {            return typarams;        }        public List<JCVariableDecl> getParameters() {            return params;        }        public List<JCExpression> getThrows() {            return thrown;        }        public JCBlock getBody() { return body; }        public JCTree getDefaultValue() { // for annotation types            return defaultValue;        }        @Override        public <R,D> R accept(TreeVisitor<R,D> v, D d) {            return v.visitMethod(this, d);        }        @Override        public int getTag() {            return METHODDEF;        }  }    /**     * A variable definition.     * @param modifiers variable modifiers     * @param name variable name     * @param vartype type of the variable     * @param init variables initial value     * @param sym symbol     */    public static class JCVariableDecl extends JCStatement implements VariableTree {        public JCModifiers mods;        public Name name;        public JCExpression vartype;        public JCExpression init;        public VarSymbol sym;        protected JCVariableDecl(JCModifiers mods,			 Name name,			 JCExpression vartype,			 JCExpression init,			 VarSymbol sym) {            this.mods = mods;            this.name = name;            this.vartype = vartype;            this.init = init;            this.sym = sym;        }        @Override        public void accept(Visitor v) { v.visitVarDef(this); }        public Kind getKind() { return Kind.VARIABLE; }        public JCModifiers getModifiers() { return mods; }        public Name getName() { return name; }        public JCTree getType() { return vartype; }        public JCExpression getInitializer() {            return init;        }        @Override        public <R,D> R accept(TreeVisitor<R,D> v, D d) {            return v.visitVariable(this, d);        }        @Override        public int getTag() {            return VARDEF;        }    }      /**     * A no-op statement ";".     */    public static class JCSkip extends JCStatement implements EmptyStatementTree {        protected JCSkip() {        }        @Override        public void accept(Visitor v) { v.visitSkip(this); }        public Kind getKind() { return Kind.EMPTY_STATEMENT; }        @Override        public <R,D> R accept(TreeVisitor<R,D> v, D d) {            return v.visitEmptyStatement(this, d);        }        @Override        public int getTag() {            return SKIP;        }    }    /**     * A statement block.     * @param stats statements     * @param flags flags     */    public static class JCBlock extends JCStatement implements BlockTree {        public long flags;        public List<JCStatement> stats;        /** Position of closing brace, optional. */        public int endpos = Position.NOPOS;        protected JCBlock(long flags, List<JCStatement> stats) {            this.stats = stats;            this.flags = flags;        }        @Override        public void accept(Visitor v) { v.visitBlock(this); }        public Kind getKind() { return Kind.BLOCK; }        public List<JCStatement> getStatements() {            return stats;        }        public boolean isStatic() { return (flags & Flags.STATIC) != 0; }        @Override        public <R,D> R accept(TreeVisitor<R,D> v, D d) {            return v.visitBlock(this, d);        }        @Override        public int getTag() {            return BLOCK;        }    }    /**     * A do loop     */    public static class JCDoWhileLoop extends JCStatement implements DoWhileLoopTree {        public JCStatement body;        public JCExpression cond;        protected JCDoWhileLoop(JCStatement body, JCExpression cond) {            this.body = body;            this.cond = cond;        }        @Override        public void accept(Visitor v) { v.visitDoLoop(this); }        public Kind getKind() { return Kind.DO_WHILE_LOOP; }        public JCExpression getCondition() { return cond; }        public JCStatement getStatement() { return body; }        @Override        public <R,D> R accept(TreeVisitor<R,D> v, D d) {            return v.visitDoWhileLoop(this, d);        }        @Override        public int getTag() {            return DOLOOP;        }    }    /**     * A while loop     */    public static class JCWhileLoop extends JCStatement implements WhileLoopTree {        public JCExpression cond;        public JCStatement body;        protected JCWhileLoop(JCExpression cond, JCStatement body) {            this.cond = cond;            this.body = body;        }        @Override

⌨️ 快捷键说明

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