?? treemaker.java
字號(hào):
} public TypeTest TypeTest(Tree expr, Tree clazz) { TypeTest tree = new TypeTest(expr, clazz); tree.pos = pos; return tree; } public Indexed Indexed(Tree indexed, Tree index) { Indexed tree = new Indexed(indexed, index); tree.pos = pos; return tree; } public Select Select(Tree selected, Name selector) { Select tree = new Select(selected, selector, null); tree.pos = pos; return tree; } public Ident Ident(Name name) { Ident tree = new Ident(name, null); tree.pos = pos; return tree; } public Literal Literal(int tag, Object value) { Literal tree = new Literal(tag, value); tree.pos = pos; return tree; } public TypeIdent TypeIdent(int typetag) { TypeIdent tree = new TypeIdent(typetag); tree.pos = pos; return tree; } public TypeArray TypeArray(Tree elemtype) { TypeArray tree = new TypeArray(elemtype); tree.pos = pos; return tree; } public Erroneous Erroneous() { Erroneous tree = new Erroneous(); tree.pos = pos; return tree; } /** * Create an identifier from a symbol. */ public Tree Ident(Symbol sym) { return new Ident(sym.name, sym).setPos(pos).setType(sym.type); } /** * Create a selection node from a qualifier tree and a symbol. * @param base The qualifier tree. */ public Tree Select(Tree base, Symbol sym) { return new Select(base, sym.name, sym).setPos(pos).setType(sym.type); } /** * Create a qualified identifier from a symbol, adding enough qualifications * to make the reference unique. */ public Tree QualIdent(Symbol sym) { return isUnqualifiable(sym) ? Ident(sym) : Select(QualIdent(sym.owner), sym); } /** * Create an identifier that refers to the variable declared in given variable * declaration. */ public Tree Ident(VarDef param) { return Ident(param.sym); } /** * Create a list of identifiers referring to the variables declared * in given list of variable declarations. */ public List Idents(List params) { ListBuffer ids = new ListBuffer(); for (List l = params; l.nonEmpty(); l = l.tail) ids.append(Ident((VarDef) l.head)); return ids.toList(); } /** * Create a tree representing `this', given its type. */ public Tree This(Type t) { return Ident(new VarSymbol(FINAL, names._this, t, t.tsym)); } /** * Create a tree representing `super', given its type and owner. */ public Tree Super(Type t, TypeSymbol owner) { return Ident(new VarSymbol(FINAL, names._super, t, owner)); } /** * Create a method invocation from a method tree and a list of argument trees. */ public Tree App(Tree meth, List args) { return Apply(meth, args).setType(meth.type.restype()); } /** * Create a tree representing given type. */ public Tree Type(Type t) { if (t == null) return null; Tree tp; switch (t.tag) { case BYTE: case CHAR: case SHORT: case INT: case LONG: case FLOAT: case DOUBLE: case BOOLEAN: case VOID: tp = TypeIdent(t.tag); break; case CLASS: Type outer = t.outer(); Tree clazz = outer.tag == CLASS && t.tsym.owner.kind == TYP ? Select(Type(outer), t.tsym) : QualIdent(t.tsym); tp = clazz; break; case ARRAY: tp = TypeArray(Type(t.elemtype())); break; case ERROR: tp = TypeIdent(ERROR); break; default: throw new AssertionError("unexpected type: " + t); } return tp.setType(t); } private Tree Selectors(Tree base, Symbol sym, Symbol limit) { if (sym == limit) return base; else return Select(Selectors(base, sym.owner, limit), sym); } /** * Create a list of trees representing given list of types. */ public List Types(List ts) { ListBuffer types = new ListBuffer(); for (List l = ts; l.nonEmpty(); l = l.tail) types.append(Type((Type) l.head)); return types.toList(); } /** * Create a variable definition from a variable symbol and an initializer * expression. */ public VarDef VarDef(VarSymbol v, Tree init) { return (VarDef) new VarDef(v.flags(), v.name, Type(v.type), init, v).setPos(pos).setType(v.type); } /** * Create a method definition from a method symbol and a method body. */ public MethodDef MethodDef(MethodSymbol m, Block body) { return MethodDef(m, m.type, body); } /** * Create a method definition from a method symbol, method type * and a method body. */ public MethodDef MethodDef(MethodSymbol m, Type mtype, Block body) { return (MethodDef) new MethodDef(m.flags(), m.name, Type(mtype.restype()), TypeParameter.emptyList, Params(mtype.argtypes(), m), Types(mtype.thrown()), body, m).setPos(pos).setType(mtype); } /** * Create a value parameter tree from its name, type, and owner. */ public VarDef Param(Name name, Type argtype, Symbol owner) { return VarDef(new VarSymbol(0, name, argtype, owner), null); } /** * Create a a list of value parameter trees x0, ..., xn from a list of * their types and an their owner. */ public List Params(List argtypes, Symbol owner) { ListBuffer params = new ListBuffer(); int i = 0; for (List l = argtypes; l.nonEmpty(); l = l.tail) params.append(Param(paramName(i++), (Type) l.head, owner)); return params.toList(); } /** * Wrap a method invocation in an expression statement or return statement, * depending on whether the method invocation expression's type is void. */ public Tree Call(Tree apply) { return apply.type.tag == VOID ? (Tree) Exec(apply) : (Tree) Return(apply); } /** * Construct an assignment from a variable symbol and a right hand side. */ public Tree Assignment(Symbol v, Tree rhs) { return Exec(Assign(Ident(v), rhs).setType(v.type)); } /** * Can given symbol be referred to in unqualified form? */ boolean isUnqualifiable(Symbol sym) { if (sym.owner == null || sym.owner.kind == MTH || sym.owner.kind == VAR || sym.owner.name == names.empty) { return true; } else if (sym.kind == TYP && toplevel != null) { Scope.Entry e; e = toplevel.namedImportScope.lookup(sym.name); if (e.scope != null) { return e.scope.owner == e.sym.owner && e.sym == sym && e.next().scope == null; } e = toplevel.packge.members().lookup(sym.name); if (e.scope != null) { return e.scope.owner == e.sym.owner && e.sym == sym && e.next().scope == null; } e = toplevel.starImportScope.lookup(sym.name); if (e.scope != null) { return e.scope.owner == e.sym.owner && e.sym == sym && e.next().scope == null; } } return false; } /** * The name of synthetic parameter number `i'. */ public Name paramName(int i) { return names.fromString("x" + i); } /** * The name of synthetic type parameter number `i'. */ public Name typaramName(int i) { return names.fromString("A" + i); }}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -