--- a/langtools/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java Sat Nov 05 00:02:33 2011 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java Tue Nov 08 11:51:05 2011 -0800
@@ -35,6 +35,9 @@
import com.sun.tools.javac.tree.JCTree.*;
import static com.sun.tools.javac.code.Flags.*;
+import static com.sun.tools.javac.tree.JCTree.Tag.*;
+import static com.sun.tools.javac.tree.JCTree.Tag.BLOCK;
+import static com.sun.tools.javac.tree.JCTree.Tag.SYNCHRONIZED;
/** Utility class containing inspector methods for trees.
*
@@ -56,53 +59,60 @@
/** The names of all operators.
*/
- private Name[] opname = new Name[JCTree.MOD - JCTree.POS + 1];
+ private Name[] opname = new Name[Tag.getNumberOfOperators()];
+
+ private void setOpname(Tag tag, String name, Names names) {
+ setOpname(tag, names.fromString(name));
+ }
+ private void setOpname(Tag tag, Name name) {
+ opname[tag.operatorIndex()] = name;
+ }
private TreeInfo(Context context) {
context.put(treeInfoKey, this);
Names names = Names.instance(context);
- opname[JCTree.POS - JCTree.POS] = names.fromString("+");
- opname[JCTree.NEG - JCTree.POS] = names.hyphen;
- opname[JCTree.NOT - JCTree.POS] = names.fromString("!");
- opname[JCTree.COMPL - JCTree.POS] = names.fromString("~");
- opname[JCTree.PREINC - JCTree.POS] = names.fromString("++");
- opname[JCTree.PREDEC - JCTree.POS] = names.fromString("--");
- opname[JCTree.POSTINC - JCTree.POS] = names.fromString("++");
- opname[JCTree.POSTDEC - JCTree.POS] = names.fromString("--");
- opname[JCTree.NULLCHK - JCTree.POS] = names.fromString("<*nullchk*>");
- opname[JCTree.OR - JCTree.POS] = names.fromString("||");
- opname[JCTree.AND - JCTree.POS] = names.fromString("&&");
- opname[JCTree.EQ - JCTree.POS] = names.fromString("==");
- opname[JCTree.NE - JCTree.POS] = names.fromString("!=");
- opname[JCTree.LT - JCTree.POS] = names.fromString("<");
- opname[JCTree.GT - JCTree.POS] = names.fromString(">");
- opname[JCTree.LE - JCTree.POS] = names.fromString("<=");
- opname[JCTree.GE - JCTree.POS] = names.fromString(">=");
- opname[JCTree.BITOR - JCTree.POS] = names.fromString("|");
- opname[JCTree.BITXOR - JCTree.POS] = names.fromString("^");
- opname[JCTree.BITAND - JCTree.POS] = names.fromString("&");
- opname[JCTree.SL - JCTree.POS] = names.fromString("<<");
- opname[JCTree.SR - JCTree.POS] = names.fromString(">>");
- opname[JCTree.USR - JCTree.POS] = names.fromString(">>>");
- opname[JCTree.PLUS - JCTree.POS] = names.fromString("+");
- opname[JCTree.MINUS - JCTree.POS] = names.hyphen;
- opname[JCTree.MUL - JCTree.POS] = names.asterisk;
- opname[JCTree.DIV - JCTree.POS] = names.slash;
- opname[JCTree.MOD - JCTree.POS] = names.fromString("%");
+ setOpname(POS, "+", names);
+ setOpname(NEG, names.hyphen);
+ setOpname(NOT, "!", names);
+ setOpname(COMPL, "~", names);
+ setOpname(PREINC, "++", names);
+ setOpname(PREDEC, "--", names);
+ setOpname(POSTINC, "++", names);
+ setOpname(POSTDEC, "--", names);
+ setOpname(NULLCHK, "<*nullchk*>", names);
+ setOpname(OR, "||", names);
+ setOpname(AND, "&&", names);
+ setOpname(EQ, "==", names);
+ setOpname(NE, "!=", names);
+ setOpname(LT, "<", names);
+ setOpname(GT, ">", names);
+ setOpname(LE, "<=", names);
+ setOpname(GE, ">=", names);
+ setOpname(BITOR, "|", names);
+ setOpname(BITXOR, "^", names);
+ setOpname(BITAND, "&", names);
+ setOpname(SL, "<<", names);
+ setOpname(SR, ">>", names);
+ setOpname(USR, ">>>", names);
+ setOpname(PLUS, "+", names);
+ setOpname(MINUS, names.hyphen);
+ setOpname(MUL, names.asterisk);
+ setOpname(DIV, names.slash);
+ setOpname(MOD, "%", names);
}
/** Return name of operator with given tree tag.
*/
- public Name operatorName(int tag) {
- return opname[tag - JCTree.POS];
+ public Name operatorName(JCTree.Tag tag) {
+ return opname[tag.operatorIndex()];
}
/** Is tree a constructor declaration?
*/
public static boolean isConstructor(JCTree tree) {
- if (tree.getTag() == JCTree.METHODDEF) {
+ if (tree.hasTag(METHODDEF)) {
Name name = ((JCMethodDecl) tree).name;
return name == name.table.names.init;
} else {
@@ -119,17 +129,17 @@
}
public static boolean isMultiCatch(JCCatch catchClause) {
- return catchClause.param.vartype.getTag() == JCTree.TYPEUNION;
+ return catchClause.param.vartype.hasTag(TYPEUNION);
}
/** Is statement an initializer for a synthetic field?
*/
public static boolean isSyntheticInit(JCTree stat) {
- if (stat.getTag() == JCTree.EXEC) {
+ if (stat.hasTag(EXEC)) {
JCExpressionStatement exec = (JCExpressionStatement)stat;
- if (exec.expr.getTag() == JCTree.ASSIGN) {
+ if (exec.expr.hasTag(ASSIGN)) {
JCAssign assign = (JCAssign)exec.expr;
- if (assign.lhs.getTag() == JCTree.SELECT) {
+ if (assign.lhs.hasTag(SELECT)) {
JCFieldAccess select = (JCFieldAccess)assign.lhs;
if (select.sym != null &&
(select.sym.flags() & SYNTHETIC) != 0) {
@@ -146,9 +156,9 @@
/** If the expression is a method call, return the method name, null
* otherwise. */
public static Name calledMethodName(JCTree tree) {
- if (tree.getTag() == JCTree.EXEC) {
+ if (tree.hasTag(EXEC)) {
JCExpressionStatement exec = (JCExpressionStatement)tree;
- if (exec.expr.getTag() == JCTree.APPLY) {
+ if (exec.expr.hasTag(APPLY)) {
Name mname = TreeInfo.name(((JCMethodInvocation) exec.expr).meth);
return mname;
}
@@ -192,7 +202,7 @@
/** Return the first call in a constructor definition. */
public static JCMethodInvocation firstConstructorCall(JCTree tree) {
- if (tree.getTag() != JCTree.METHODDEF) return null;
+ if (!tree.hasTag(METHODDEF)) return null;
JCMethodDecl md = (JCMethodDecl) tree;
Names names = md.name.table.names;
if (md.name != names.init) return null;
@@ -202,24 +212,24 @@
while (stats.nonEmpty() && isSyntheticInit(stats.head))
stats = stats.tail;
if (stats.isEmpty()) return null;
- if (stats.head.getTag() != JCTree.EXEC) return null;
+ if (!stats.head.hasTag(EXEC)) return null;
JCExpressionStatement exec = (JCExpressionStatement) stats.head;
- if (exec.expr.getTag() != JCTree.APPLY) return null;
+ if (!exec.expr.hasTag(APPLY)) return null;
return (JCMethodInvocation)exec.expr;
}
/** Return true if a tree represents a diamond new expr. */
public static boolean isDiamond(JCTree tree) {
switch(tree.getTag()) {
- case JCTree.TYPEAPPLY: return ((JCTypeApply)tree).getTypeArguments().isEmpty();
- case JCTree.NEWCLASS: return isDiamond(((JCNewClass)tree).clazz);
+ case TYPEAPPLY: return ((JCTypeApply)tree).getTypeArguments().isEmpty();
+ case NEWCLASS: return isDiamond(((JCNewClass)tree).clazz);
default: return false;
}
}
/** Return true if a tree represents the null literal. */
public static boolean isNull(JCTree tree) {
- if (tree.getTag() != JCTree.LITERAL)
+ if (!tree.hasTag(LITERAL))
return false;
JCLiteral lit = (JCLiteral) tree;
return (lit.typetag == TypeTags.BOT);
@@ -229,7 +239,7 @@
* the block itself if it is empty.
*/
public static int firstStatPos(JCTree tree) {
- if (tree.getTag() == JCTree.BLOCK && ((JCBlock) tree).stats.nonEmpty())
+ if (tree.hasTag(BLOCK) && ((JCBlock) tree).stats.nonEmpty())
return ((JCBlock) tree).stats.head.pos;
else
return tree.pos;
@@ -239,11 +249,11 @@
* defined endpos.
*/
public static int endPos(JCTree tree) {
- if (tree.getTag() == JCTree.BLOCK && ((JCBlock) tree).endpos != Position.NOPOS)
+ if (tree.hasTag(BLOCK) && ((JCBlock) tree).endpos != Position.NOPOS)
return ((JCBlock) tree).endpos;
- else if (tree.getTag() == JCTree.SYNCHRONIZED)
+ else if (tree.hasTag(SYNCHRONIZED))
return endPos(((JCSynchronized) tree).body);
- else if (tree.getTag() == JCTree.TRY) {
+ else if (tree.hasTag(TRY)) {
JCTry t = (JCTry) tree;
return endPos((t.finalizer != null)
? t.finalizer
@@ -263,73 +273,73 @@
return Position.NOPOS;
switch(tree.getTag()) {
- case(JCTree.APPLY):
- return getStartPos(((JCMethodInvocation) tree).meth);
- case(JCTree.ASSIGN):
- return getStartPos(((JCAssign) tree).lhs);
- case(JCTree.BITOR_ASG): case(JCTree.BITXOR_ASG): case(JCTree.BITAND_ASG):
- case(JCTree.SL_ASG): case(JCTree.SR_ASG): case(JCTree.USR_ASG):
- case(JCTree.PLUS_ASG): case(JCTree.MINUS_ASG): case(JCTree.MUL_ASG):
- case(JCTree.DIV_ASG): case(JCTree.MOD_ASG):
- return getStartPos(((JCAssignOp) tree).lhs);
- case(JCTree.OR): case(JCTree.AND): case(JCTree.BITOR):
- case(JCTree.BITXOR): case(JCTree.BITAND): case(JCTree.EQ):
- case(JCTree.NE): case(JCTree.LT): case(JCTree.GT):
- case(JCTree.LE): case(JCTree.GE): case(JCTree.SL):
- case(JCTree.SR): case(JCTree.USR): case(JCTree.PLUS):
- case(JCTree.MINUS): case(JCTree.MUL): case(JCTree.DIV):
- case(JCTree.MOD):
- return getStartPos(((JCBinary) tree).lhs);
- case(JCTree.CLASSDEF): {
- JCClassDecl node = (JCClassDecl)tree;
- if (node.mods.pos != Position.NOPOS)
- return node.mods.pos;
- break;
- }
- case(JCTree.CONDEXPR):
- return getStartPos(((JCConditional) tree).cond);
- case(JCTree.EXEC):
- return getStartPos(((JCExpressionStatement) tree).expr);
- case(JCTree.INDEXED):
- return getStartPos(((JCArrayAccess) tree).indexed);
- case(JCTree.METHODDEF): {
- JCMethodDecl node = (JCMethodDecl)tree;
- if (node.mods.pos != Position.NOPOS)
- return node.mods.pos;
- if (node.typarams.nonEmpty()) // List.nil() used for no typarams
- return getStartPos(node.typarams.head);
- return node.restype == null ? node.pos : getStartPos(node.restype);
- }
- case(JCTree.SELECT):
- return getStartPos(((JCFieldAccess) tree).selected);
- case(JCTree.TYPEAPPLY):
- return getStartPos(((JCTypeApply) tree).clazz);
- case(JCTree.TYPEARRAY):
- return getStartPos(((JCArrayTypeTree) tree).elemtype);
- case(JCTree.TYPETEST):
- return getStartPos(((JCInstanceOf) tree).expr);
- case(JCTree.POSTINC):
- case(JCTree.POSTDEC):
- return getStartPos(((JCUnary) tree).arg);
- case(JCTree.NEWCLASS): {
- JCNewClass node = (JCNewClass)tree;
- if (node.encl != null)
- return getStartPos(node.encl);
- break;
- }
- case(JCTree.VARDEF): {
- JCVariableDecl node = (JCVariableDecl)tree;
- if (node.mods.pos != Position.NOPOS) {
- return node.mods.pos;
- } else {
- return getStartPos(node.vartype);
+ case APPLY:
+ return getStartPos(((JCMethodInvocation) tree).meth);
+ case ASSIGN:
+ return getStartPos(((JCAssign) tree).lhs);
+ case BITOR_ASG: case BITXOR_ASG: case BITAND_ASG:
+ case SL_ASG: case SR_ASG: case USR_ASG:
+ case PLUS_ASG: case MINUS_ASG: case MUL_ASG:
+ case DIV_ASG: case MOD_ASG:
+ return getStartPos(((JCAssignOp) tree).lhs);
+ case OR: case AND: case BITOR:
+ case BITXOR: case BITAND: case EQ:
+ case NE: case LT: case GT:
+ case LE: case GE: case SL:
+ case SR: case USR: case PLUS:
+ case MINUS: case MUL: case DIV:
+ case MOD:
+ return getStartPos(((JCBinary) tree).lhs);
+ case CLASSDEF: {
+ JCClassDecl node = (JCClassDecl)tree;
+ if (node.mods.pos != Position.NOPOS)
+ return node.mods.pos;
+ break;
}
- }
- case(JCTree.ERRONEOUS): {
- JCErroneous node = (JCErroneous)tree;
- if (node.errs != null && node.errs.nonEmpty())
- return getStartPos(node.errs.head);
- }
+ case CONDEXPR:
+ return getStartPos(((JCConditional) tree).cond);
+ case EXEC:
+ return getStartPos(((JCExpressionStatement) tree).expr);
+ case INDEXED:
+ return getStartPos(((JCArrayAccess) tree).indexed);
+ case METHODDEF: {
+ JCMethodDecl node = (JCMethodDecl)tree;
+ if (node.mods.pos != Position.NOPOS)
+ return node.mods.pos;
+ if (node.typarams.nonEmpty()) // List.nil() used for no typarams
+ return getStartPos(node.typarams.head);
+ return node.restype == null ? node.pos : getStartPos(node.restype);
+ }
+ case SELECT:
+ return getStartPos(((JCFieldAccess) tree).selected);
+ case TYPEAPPLY:
+ return getStartPos(((JCTypeApply) tree).clazz);
+ case TYPEARRAY:
+ return getStartPos(((JCArrayTypeTree) tree).elemtype);
+ case TYPETEST:
+ return getStartPos(((JCInstanceOf) tree).expr);
+ case POSTINC:
+ case POSTDEC:
+ return getStartPos(((JCUnary) tree).arg);
+ case NEWCLASS: {
+ JCNewClass node = (JCNewClass)tree;
+ if (node.encl != null)
+ return getStartPos(node.encl);
+ break;
+ }
+ case VARDEF: {
+ JCVariableDecl node = (JCVariableDecl)tree;
+ if (node.mods.pos != Position.NOPOS) {
+ return node.mods.pos;
+ } else {
+ return getStartPos(node.vartype);
+ }
+ }
+ case ERRONEOUS: {
+ JCErroneous node = (JCErroneous)tree;
+ if (node.errs != null && node.errs.nonEmpty())
+ return getStartPos(node.errs.head);
+ }
}
return tree.pos;
}
@@ -350,75 +360,75 @@
return mapPos;
switch(tree.getTag()) {
- case(JCTree.BITOR_ASG): case(JCTree.BITXOR_ASG): case(JCTree.BITAND_ASG):
- case(JCTree.SL_ASG): case(JCTree.SR_ASG): case(JCTree.USR_ASG):
- case(JCTree.PLUS_ASG): case(JCTree.MINUS_ASG): case(JCTree.MUL_ASG):
- case(JCTree.DIV_ASG): case(JCTree.MOD_ASG):
- return getEndPos(((JCAssignOp) tree).rhs, endPositions);
- case(JCTree.OR): case(JCTree.AND): case(JCTree.BITOR):
- case(JCTree.BITXOR): case(JCTree.BITAND): case(JCTree.EQ):
- case(JCTree.NE): case(JCTree.LT): case(JCTree.GT):
- case(JCTree.LE): case(JCTree.GE): case(JCTree.SL):
- case(JCTree.SR): case(JCTree.USR): case(JCTree.PLUS):
- case(JCTree.MINUS): case(JCTree.MUL): case(JCTree.DIV):
- case(JCTree.MOD):
- return getEndPos(((JCBinary) tree).rhs, endPositions);
- case(JCTree.CASE):
- return getEndPos(((JCCase) tree).stats.last(), endPositions);
- case(JCTree.CATCH):
- return getEndPos(((JCCatch) tree).body, endPositions);
- case(JCTree.CONDEXPR):
- return getEndPos(((JCConditional) tree).falsepart, endPositions);
- case(JCTree.FORLOOP):
- return getEndPos(((JCForLoop) tree).body, endPositions);
- case(JCTree.FOREACHLOOP):
- return getEndPos(((JCEnhancedForLoop) tree).body, endPositions);
- case(JCTree.IF): {
- JCIf node = (JCIf)tree;
- if (node.elsepart == null) {
- return getEndPos(node.thenpart, endPositions);
- } else {
- return getEndPos(node.elsepart, endPositions);
+ case BITOR_ASG: case BITXOR_ASG: case BITAND_ASG:
+ case SL_ASG: case SR_ASG: case USR_ASG:
+ case PLUS_ASG: case MINUS_ASG: case MUL_ASG:
+ case DIV_ASG: case MOD_ASG:
+ return getEndPos(((JCAssignOp) tree).rhs, endPositions);
+ case OR: case AND: case BITOR:
+ case BITXOR: case BITAND: case EQ:
+ case NE: case LT: case GT:
+ case LE: case GE: case SL:
+ case SR: case USR: case PLUS:
+ case MINUS: case MUL: case DIV:
+ case MOD:
+ return getEndPos(((JCBinary) tree).rhs, endPositions);
+ case CASE:
+ return getEndPos(((JCCase) tree).stats.last(), endPositions);
+ case CATCH:
+ return getEndPos(((JCCatch) tree).body, endPositions);
+ case CONDEXPR:
+ return getEndPos(((JCConditional) tree).falsepart, endPositions);
+ case FORLOOP:
+ return getEndPos(((JCForLoop) tree).body, endPositions);
+ case FOREACHLOOP:
+ return getEndPos(((JCEnhancedForLoop) tree).body, endPositions);
+ case IF: {
+ JCIf node = (JCIf)tree;
+ if (node.elsepart == null) {
+ return getEndPos(node.thenpart, endPositions);
+ } else {
+ return getEndPos(node.elsepart, endPositions);
+ }
}
- }
- case(JCTree.LABELLED):
- return getEndPos(((JCLabeledStatement) tree).body, endPositions);
- case(JCTree.MODIFIERS):
- return getEndPos(((JCModifiers) tree).annotations.last(), endPositions);
- case(JCTree.SYNCHRONIZED):
- return getEndPos(((JCSynchronized) tree).body, endPositions);
- case(JCTree.TOPLEVEL):
- return getEndPos(((JCCompilationUnit) tree).defs.last(), endPositions);
- case(JCTree.TRY): {
- JCTry node = (JCTry)tree;
- if (node.finalizer != null) {
- return getEndPos(node.finalizer, endPositions);
- } else if (!node.catchers.isEmpty()) {
- return getEndPos(node.catchers.last(), endPositions);
- } else {
- return getEndPos(node.body, endPositions);
+ case LABELLED:
+ return getEndPos(((JCLabeledStatement) tree).body, endPositions);
+ case MODIFIERS:
+ return getEndPos(((JCModifiers) tree).annotations.last(), endPositions);
+ case SYNCHRONIZED:
+ return getEndPos(((JCSynchronized) tree).body, endPositions);
+ case TOPLEVEL:
+ return getEndPos(((JCCompilationUnit) tree).defs.last(), endPositions);
+ case TRY: {
+ JCTry node = (JCTry)tree;
+ if (node.finalizer != null) {
+ return getEndPos(node.finalizer, endPositions);
+ } else if (!node.catchers.isEmpty()) {
+ return getEndPos(node.catchers.last(), endPositions);
+ } else {
+ return getEndPos(node.body, endPositions);
+ }
}
- }
- case(JCTree.WILDCARD):
- return getEndPos(((JCWildcard) tree).inner, endPositions);
- case(JCTree.TYPECAST):
- return getEndPos(((JCTypeCast) tree).expr, endPositions);
- case(JCTree.TYPETEST):
- return getEndPos(((JCInstanceOf) tree).clazz, endPositions);
- case(JCTree.POS):
- case(JCTree.NEG):
- case(JCTree.NOT):
- case(JCTree.COMPL):
- case(JCTree.PREINC):
- case(JCTree.PREDEC):
- return getEndPos(((JCUnary) tree).arg, endPositions);
- case(JCTree.WHILELOOP):
- return getEndPos(((JCWhileLoop) tree).body, endPositions);
- case(JCTree.ERRONEOUS): {
- JCErroneous node = (JCErroneous)tree;
- if (node.errs != null && node.errs.nonEmpty())
- return getEndPos(node.errs.last(), endPositions);
- }
+ case WILDCARD:
+ return getEndPos(((JCWildcard) tree).inner, endPositions);
+ case TYPECAST:
+ return getEndPos(((JCTypeCast) tree).expr, endPositions);
+ case TYPETEST:
+ return getEndPos(((JCInstanceOf) tree).clazz, endPositions);
+ case POS:
+ case NEG:
+ case NOT:
+ case COMPL:
+ case PREINC:
+ case PREDEC:
+ return getEndPos(((JCUnary) tree).arg, endPositions);
+ case WHILELOOP:
+ return getEndPos(((JCWhileLoop) tree).body, endPositions);
+ case ERRONEOUS: {
+ JCErroneous node = (JCErroneous)tree;
+ if (node.errs != null && node.errs.nonEmpty())
+ return getEndPos(node.errs.last(), endPositions);
+ }
}
return Position.NOPOS;
}
@@ -443,11 +453,11 @@
/** The position of the finalizer of given try/synchronized statement.
*/
public static int finalizerPos(JCTree tree) {
- if (tree.getTag() == JCTree.TRY) {
+ if (tree.hasTag(TRY)) {
JCTry t = (JCTry) tree;
Assert.checkNonNull(t.finalizer);
return firstStatPos(t.finalizer);
- } else if (tree.getTag() == JCTree.SYNCHRONIZED) {
+ } else if (tree.hasTag(SYNCHRONIZED)) {
return endPos(((JCSynchronized) tree).body);
} else {
throw new AssertionError();
@@ -547,9 +557,9 @@
public static JCTree referencedStatement(JCLabeledStatement tree) {
JCTree t = tree;
do t = ((JCLabeledStatement) t).body;
- while (t.getTag() == JCTree.LABELLED);
+ while (t.hasTag(LABELLED));
switch (t.getTag()) {
- case JCTree.DOLOOP: case JCTree.WHILELOOP: case JCTree.FORLOOP: case JCTree.FOREACHLOOP: case JCTree.SWITCH:
+ case DOLOOP: case WHILELOOP: case FORLOOP: case FOREACHLOOP: case SWITCH:
return t;
default:
return tree;
@@ -559,7 +569,7 @@
/** Skip parens and return the enclosed expression
*/
public static JCExpression skipParens(JCExpression tree) {
- while (tree.getTag() == JCTree.PARENS) {
+ while (tree.hasTag(PARENS)) {
tree = ((JCParens) tree).expr;
}
return tree;
@@ -568,7 +578,7 @@
/** Skip parens and return the enclosed expression
*/
public static JCTree skipParens(JCTree tree) {
- if (tree.getTag() == JCTree.PARENS)
+ if (tree.hasTag(PARENS))
return skipParens((JCParens)tree);
else
return tree;
@@ -588,11 +598,11 @@
*/
public static Name name(JCTree tree) {
switch (tree.getTag()) {
- case JCTree.IDENT:
+ case IDENT:
return ((JCIdent) tree).name;
- case JCTree.SELECT:
+ case SELECT:
return ((JCFieldAccess) tree).name;
- case JCTree.TYPEAPPLY:
+ case TYPEAPPLY:
return name(((JCTypeApply) tree).clazz);
default:
return null;
@@ -605,9 +615,9 @@
public static Name fullName(JCTree tree) {
tree = skipParens(tree);
switch (tree.getTag()) {
- case JCTree.IDENT:
+ case IDENT:
return ((JCIdent) tree).name;
- case JCTree.SELECT:
+ case SELECT:
Name sname = fullName(((JCFieldAccess) tree).selected);
return sname == null ? null : sname.append('.', name(tree));
default:
@@ -618,11 +628,11 @@
public static Symbol symbolFor(JCTree node) {
node = skipParens(node);
switch (node.getTag()) {
- case JCTree.CLASSDEF:
+ case CLASSDEF:
return ((JCClassDecl) node).sym;
- case JCTree.METHODDEF:
+ case METHODDEF:
return ((JCMethodDecl) node).sym;
- case JCTree.VARDEF:
+ case VARDEF:
return ((JCVariableDecl) node).sym;
default:
return null;
@@ -632,9 +642,9 @@
public static boolean isDeclaration(JCTree node) {
node = skipParens(node);
switch (node.getTag()) {
- case JCTree.CLASSDEF:
- case JCTree.METHODDEF:
- case JCTree.VARDEF:
+ case CLASSDEF:
+ case METHODDEF:
+ case VARDEF:
return true;
default:
return false;
@@ -647,11 +657,11 @@
public static Symbol symbol(JCTree tree) {
tree = skipParens(tree);
switch (tree.getTag()) {
- case JCTree.IDENT:
+ case IDENT:
return ((JCIdent) tree).sym;
- case JCTree.SELECT:
+ case SELECT:
return ((JCFieldAccess) tree).sym;
- case JCTree.TYPEAPPLY:
+ case TYPEAPPLY:
return symbol(((JCTypeApply) tree).clazz);
default:
return null;
@@ -661,7 +671,7 @@
/** Return true if this is a nonstatic selection. */
public static boolean nonstaticSelect(JCTree tree) {
tree = skipParens(tree);
- if (tree.getTag() != JCTree.SELECT) return false;
+ if (!tree.hasTag(SELECT)) return false;
JCFieldAccess s = (JCFieldAccess) tree;
Symbol e = symbol(s.selected);
return e == null || (e.kind != Kinds.PCK && e.kind != Kinds.TYP);
@@ -672,9 +682,9 @@
public static void setSymbol(JCTree tree, Symbol sym) {
tree = skipParens(tree);
switch (tree.getTag()) {
- case JCTree.IDENT:
+ case IDENT:
((JCIdent) tree).sym = sym; break;
- case JCTree.SELECT:
+ case SELECT:
((JCFieldAccess) tree).sym = sym; break;
default:
}
@@ -685,13 +695,13 @@
*/
public static long flags(JCTree tree) {
switch (tree.getTag()) {
- case JCTree.VARDEF:
+ case VARDEF:
return ((JCVariableDecl) tree).mods.flags;
- case JCTree.METHODDEF:
+ case METHODDEF:
return ((JCMethodDecl) tree).mods.flags;
- case JCTree.CLASSDEF:
+ case CLASSDEF:
return ((JCClassDecl) tree).mods.flags;
- case JCTree.BLOCK:
+ case BLOCK:
return ((JCBlock) tree).flags;
default:
return 0;
@@ -739,155 +749,155 @@
/** Map operators to their precedence levels.
*/
- public static int opPrec(int op) {
+ public static int opPrec(JCTree.Tag op) {
switch(op) {
- case JCTree.POS:
- case JCTree.NEG:
- case JCTree.NOT:
- case JCTree.COMPL:
- case JCTree.PREINC:
- case JCTree.PREDEC: return prefixPrec;
- case JCTree.POSTINC:
- case JCTree.POSTDEC:
- case JCTree.NULLCHK: return postfixPrec;
- case JCTree.ASSIGN: return assignPrec;
- case JCTree.BITOR_ASG:
- case JCTree.BITXOR_ASG:
- case JCTree.BITAND_ASG:
- case JCTree.SL_ASG:
- case JCTree.SR_ASG:
- case JCTree.USR_ASG:
- case JCTree.PLUS_ASG:
- case JCTree.MINUS_ASG:
- case JCTree.MUL_ASG:
- case JCTree.DIV_ASG:
- case JCTree.MOD_ASG: return assignopPrec;
- case JCTree.OR: return orPrec;
- case JCTree.AND: return andPrec;
- case JCTree.EQ:
- case JCTree.NE: return eqPrec;
- case JCTree.LT:
- case JCTree.GT:
- case JCTree.LE:
- case JCTree.GE: return ordPrec;
- case JCTree.BITOR: return bitorPrec;
- case JCTree.BITXOR: return bitxorPrec;
- case JCTree.BITAND: return bitandPrec;
- case JCTree.SL:
- case JCTree.SR:
- case JCTree.USR: return shiftPrec;
- case JCTree.PLUS:
- case JCTree.MINUS: return addPrec;
- case JCTree.MUL:
- case JCTree.DIV:
- case JCTree.MOD: return mulPrec;
- case JCTree.TYPETEST: return ordPrec;
+ case POS:
+ case NEG:
+ case NOT:
+ case COMPL:
+ case PREINC:
+ case PREDEC: return prefixPrec;
+ case POSTINC:
+ case POSTDEC:
+ case NULLCHK: return postfixPrec;
+ case ASSIGN: return assignPrec;
+ case BITOR_ASG:
+ case BITXOR_ASG:
+ case BITAND_ASG:
+ case SL_ASG:
+ case SR_ASG:
+ case USR_ASG:
+ case PLUS_ASG:
+ case MINUS_ASG:
+ case MUL_ASG:
+ case DIV_ASG:
+ case MOD_ASG: return assignopPrec;
+ case OR: return orPrec;
+ case AND: return andPrec;
+ case EQ:
+ case NE: return eqPrec;
+ case LT:
+ case GT:
+ case LE:
+ case GE: return ordPrec;
+ case BITOR: return bitorPrec;
+ case BITXOR: return bitxorPrec;
+ case BITAND: return bitandPrec;
+ case SL:
+ case SR:
+ case USR: return shiftPrec;
+ case PLUS:
+ case MINUS: return addPrec;
+ case MUL:
+ case DIV:
+ case MOD: return mulPrec;
+ case TYPETEST: return ordPrec;
default: throw new AssertionError();
}
}
- static Tree.Kind tagToKind(int tag) {
+ static Tree.Kind tagToKind(JCTree.Tag tag) {
switch (tag) {
// Postfix expressions
- case JCTree.POSTINC: // _ ++
+ case POSTINC: // _ ++
return Tree.Kind.POSTFIX_INCREMENT;
- case JCTree.POSTDEC: // _ --
+ case POSTDEC: // _ --
return Tree.Kind.POSTFIX_DECREMENT;
// Unary operators
- case JCTree.PREINC: // ++ _
+ case PREINC: // ++ _
return Tree.Kind.PREFIX_INCREMENT;
- case JCTree.PREDEC: // -- _
+ case PREDEC: // -- _
return Tree.Kind.PREFIX_DECREMENT;
- case JCTree.POS: // +
+ case POS: // +
return Tree.Kind.UNARY_PLUS;
- case JCTree.NEG: // -
+ case NEG: // -
return Tree.Kind.UNARY_MINUS;
- case JCTree.COMPL: // ~
+ case COMPL: // ~
return Tree.Kind.BITWISE_COMPLEMENT;
- case JCTree.NOT: // !
+ case NOT: // !
return Tree.Kind.LOGICAL_COMPLEMENT;
// Binary operators
// Multiplicative operators
- case JCTree.MUL: // *
+ case MUL: // *
return Tree.Kind.MULTIPLY;
- case JCTree.DIV: // /
+ case DIV: // /
return Tree.Kind.DIVIDE;
- case JCTree.MOD: // %
+ case MOD: // %
return Tree.Kind.REMAINDER;
// Additive operators
- case JCTree.PLUS: // +
+ case PLUS: // +
return Tree.Kind.PLUS;
- case JCTree.MINUS: // -
+ case MINUS: // -
return Tree.Kind.MINUS;
// Shift operators
- case JCTree.SL: // <<
+ case SL: // <<
return Tree.Kind.LEFT_SHIFT;
- case JCTree.SR: // >>
+ case SR: // >>
return Tree.Kind.RIGHT_SHIFT;
- case JCTree.USR: // >>>
+ case USR: // >>>
return Tree.Kind.UNSIGNED_RIGHT_SHIFT;
// Relational operators
- case JCTree.LT: // <
+ case LT: // <
return Tree.Kind.LESS_THAN;
- case JCTree.GT: // >
+ case GT: // >
return Tree.Kind.GREATER_THAN;
- case JCTree.LE: // <=
+ case LE: // <=
return Tree.Kind.LESS_THAN_EQUAL;
- case JCTree.GE: // >=
+ case GE: // >=
return Tree.Kind.GREATER_THAN_EQUAL;
// Equality operators
- case JCTree.EQ: // ==
+ case EQ: // ==
return Tree.Kind.EQUAL_TO;
- case JCTree.NE: // !=
+ case NE: // !=
return Tree.Kind.NOT_EQUAL_TO;
// Bitwise and logical operators
- case JCTree.BITAND: // &
+ case BITAND: // &
return Tree.Kind.AND;
- case JCTree.BITXOR: // ^
+ case BITXOR: // ^
return Tree.Kind.XOR;
- case JCTree.BITOR: // |
+ case BITOR: // |
return Tree.Kind.OR;
// Conditional operators
- case JCTree.AND: // &&
+ case AND: // &&
return Tree.Kind.CONDITIONAL_AND;
- case JCTree.OR: // ||
+ case OR: // ||
return Tree.Kind.CONDITIONAL_OR;
// Assignment operators
- case JCTree.MUL_ASG: // *=
+ case MUL_ASG: // *=
return Tree.Kind.MULTIPLY_ASSIGNMENT;
- case JCTree.DIV_ASG: // /=
+ case DIV_ASG: // /=
return Tree.Kind.DIVIDE_ASSIGNMENT;
- case JCTree.MOD_ASG: // %=
+ case MOD_ASG: // %=
return Tree.Kind.REMAINDER_ASSIGNMENT;
- case JCTree.PLUS_ASG: // +=
+ case PLUS_ASG: // +=
return Tree.Kind.PLUS_ASSIGNMENT;
- case JCTree.MINUS_ASG: // -=
+ case MINUS_ASG: // -=
return Tree.Kind.MINUS_ASSIGNMENT;
- case JCTree.SL_ASG: // <<=
+ case SL_ASG: // <<=
return Tree.Kind.LEFT_SHIFT_ASSIGNMENT;
- case JCTree.SR_ASG: // >>=
+ case SR_ASG: // >>=
return Tree.Kind.RIGHT_SHIFT_ASSIGNMENT;
- case JCTree.USR_ASG: // >>>=
+ case USR_ASG: // >>>=
return Tree.Kind.UNSIGNED_RIGHT_SHIFT_ASSIGNMENT;
- case JCTree.BITAND_ASG: // &=
+ case BITAND_ASG: // &=
return Tree.Kind.AND_ASSIGNMENT;
- case JCTree.BITXOR_ASG: // ^=
+ case BITXOR_ASG: // ^=
return Tree.Kind.XOR_ASSIGNMENT;
- case JCTree.BITOR_ASG: // |=
+ case BITOR_ASG: // |=
return Tree.Kind.OR_ASSIGNMENT;
// Null check (implementation detail), for example, __.getClass()
- case JCTree.NULLCHK:
+ case NULLCHK:
return Tree.Kind.OTHER;
default:
@@ -901,13 +911,13 @@
*/
public static JCExpression typeIn(JCExpression tree) {
switch (tree.getTag()) {
- case JCTree.IDENT: /* simple names */
- case JCTree.TYPEIDENT: /* primitive name */
- case JCTree.SELECT: /* qualified name */
- case JCTree.TYPEARRAY: /* array types */
- case JCTree.WILDCARD: /* wild cards */
- case JCTree.TYPEPARAMETER: /* type parameters */
- case JCTree.TYPEAPPLY: /* parameterized types */
+ case IDENT: /* simple names */
+ case TYPEIDENT: /* primitive name */
+ case SELECT: /* qualified name */
+ case TYPEARRAY: /* array types */
+ case WILDCARD: /* wild cards */
+ case TYPEPARAMETER: /* type parameters */
+ case TYPEAPPLY: /* parameterized types */
return tree;
default:
throw new AssertionError("Unexpected type tree: " + tree);
@@ -916,9 +926,9 @@
public static JCTree innermostType(JCTree type) {
switch (type.getTag()) {
- case JCTree.TYPEARRAY:
+ case TYPEARRAY:
return innermostType(((JCArrayTypeTree)type).elemtype);
- case JCTree.WILDCARD:
+ case WILDCARD:
return innermostType(((JCWildcard)type).inner);
default:
return type;