6921494: provide way to print javac tree tag values

Reviewed-by: jjg, mcimadamore
This commit is contained in:
Vicente Romero 2011-11-08 11:51:05 -08:00 committed by Jonathan Gibbons
parent e31aa294c3
commit 399b71b9f0
28 changed files with 1030 additions and 947 deletions

View file

@ -325,7 +325,7 @@ public class JavacTaskImpl extends JavacTask {
ListBuffer<TypeElement> elements = new ListBuffer<TypeElement>(); ListBuffer<TypeElement> elements = new ListBuffer<TypeElement>();
for (JCCompilationUnit unit : units) { for (JCCompilationUnit unit : units) {
for (JCTree node : unit.defs) { for (JCTree node : unit.defs) {
if (node.getTag() == JCTree.CLASSDEF) { if (node.hasTag(JCTree.Tag.CLASSDEF)) {
JCClassDecl cdef = (JCClassDecl) node; JCClassDecl cdef = (JCClassDecl) node;
if (cdef.sym != null) // maybe null if errors in anno processing if (cdef.sym != null) // maybe null if errors in anno processing
elements.append(cdef.sym); elements.append(cdef.sym);
@ -383,12 +383,12 @@ public class JavacTaskImpl extends JavacTask {
private void handleFlowResults(Queue<Env<AttrContext>> queue, ListBuffer<Element> elems) { private void handleFlowResults(Queue<Env<AttrContext>> queue, ListBuffer<Element> elems) {
for (Env<AttrContext> env: queue) { for (Env<AttrContext> env: queue) {
switch (env.tree.getTag()) { switch (env.tree.getTag()) {
case JCTree.CLASSDEF: case CLASSDEF:
JCClassDecl cdef = (JCClassDecl) env.tree; JCClassDecl cdef = (JCClassDecl) env.tree;
if (cdef.sym != null) if (cdef.sym != null)
elems.append(cdef.sym); elems.append(cdef.sym);
break; break;
case JCTree.TOPLEVEL: case TOPLEVEL:
JCCompilationUnit unit = (JCCompilationUnit) env.tree; JCCompilationUnit unit = (JCCompilationUnit) env.tree;
if (unit.packge != null) if (unit.packge != null)
elems.append(unit.packge); elems.append(unit.packge);

View file

@ -207,7 +207,7 @@ public class JavacTrees extends Trees {
if (sym == null && TreeInfo.isDeclaration(tree)) { if (sym == null && TreeInfo.isDeclaration(tree)) {
for (TreePath p = path; p != null; p = p.getParentPath()) { for (TreePath p = path; p != null; p = p.getParentPath()) {
JCTree t = (JCTree) p.getLeaf(); JCTree t = (JCTree) p.getLeaf();
if (t.getTag() == JCTree.CLASSDEF) { if (t.hasTag(JCTree.Tag.CLASSDEF)) {
JCClassDecl ct = (JCClassDecl) t; JCClassDecl ct = (JCClassDecl) t;
if (ct.sym != null) { if (ct.sym != null) {
if ((ct.sym.flags_field & Flags.UNATTRIBUTED) != 0) { if ((ct.sym.flags_field & Flags.UNATTRIBUTED) != 0) {

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -31,6 +31,8 @@ import com.sun.tools.javac.code.Symbol.*;
import com.sun.tools.javac.tree.*; import com.sun.tools.javac.tree.*;
import com.sun.tools.javac.tree.JCTree.*; import com.sun.tools.javac.tree.JCTree.*;
import static com.sun.tools.javac.tree.JCTree.Tag.*;
/** Enter annotations on symbols. Annotations accumulate in a queue, /** Enter annotations on symbols. Annotations accumulate in a queue,
* which is processed at the top level of any set of recursive calls * which is processed at the top level of any set of recursive calls
* requesting it be processed. * requesting it be processed.
@ -148,7 +150,7 @@ public class Annotate {
return new Attribute.Compound(a.type, List.<Pair<MethodSymbol,Attribute>>nil()); return new Attribute.Compound(a.type, List.<Pair<MethodSymbol,Attribute>>nil());
} }
List<JCExpression> args = a.args; List<JCExpression> args = a.args;
if (args.length() == 1 && args.head.getTag() != JCTree.ASSIGN) { if (args.length() == 1 && !args.head.hasTag(ASSIGN)) {
// special case: elided "value=" assumed // special case: elided "value=" assumed
args.head = make.at(args.head.pos). args.head = make.at(args.head.pos).
Assign(make.Ident(names.value), args.head); Assign(make.Ident(names.value), args.head);
@ -157,12 +159,12 @@ public class Annotate {
new ListBuffer<Pair<MethodSymbol,Attribute>>(); new ListBuffer<Pair<MethodSymbol,Attribute>>();
for (List<JCExpression> tl = args; tl.nonEmpty(); tl = tl.tail) { for (List<JCExpression> tl = args; tl.nonEmpty(); tl = tl.tail) {
JCExpression t = tl.head; JCExpression t = tl.head;
if (t.getTag() != JCTree.ASSIGN) { if (!t.hasTag(ASSIGN)) {
log.error(t.pos(), "annotation.value.must.be.name.value"); log.error(t.pos(), "annotation.value.must.be.name.value");
continue; continue;
} }
JCAssign assign = (JCAssign)t; JCAssign assign = (JCAssign)t;
if (assign.lhs.getTag() != JCTree.IDENT) { if (!assign.lhs.hasTag(IDENT)) {
log.error(t.pos(), "annotation.value.must.be.name.value"); log.error(t.pos(), "annotation.value.must.be.name.value");
continue; continue;
} }
@ -222,14 +224,14 @@ public class Annotate {
(((JCFieldAccess) tree).selected).type); (((JCFieldAccess) tree).selected).type);
} }
if ((expected.tsym.flags() & Flags.ANNOTATION) != 0) { if ((expected.tsym.flags() & Flags.ANNOTATION) != 0) {
if (tree.getTag() != JCTree.ANNOTATION) { if (!tree.hasTag(ANNOTATION)) {
log.error(tree.pos(), "annotation.value.must.be.annotation"); log.error(tree.pos(), "annotation.value.must.be.annotation");
expected = syms.errorType; expected = syms.errorType;
} }
return enterAnnotation((JCAnnotation)tree, expected, env); return enterAnnotation((JCAnnotation)tree, expected, env);
} }
if (expected.tag == TypeTags.ARRAY) { // should really be isArray() if (expected.tag == TypeTags.ARRAY) { // should really be isArray()
if (tree.getTag() != JCTree.NEWARRAY) { if (!tree.hasTag(NEWARRAY)) {
tree = make.at(tree.pos). tree = make.at(tree.pos).
NewArray(null, List.<JCExpression>nil(), List.of(tree)); NewArray(null, List.<JCExpression>nil(), List.of(tree));
} }

View file

@ -49,8 +49,13 @@ import com.sun.source.tree.TreeVisitor;
import com.sun.source.util.SimpleTreeVisitor; import com.sun.source.util.SimpleTreeVisitor;
import static com.sun.tools.javac.code.Flags.*; import static com.sun.tools.javac.code.Flags.*;
import static com.sun.tools.javac.code.Flags.ANNOTATION;
import static com.sun.tools.javac.code.Flags.BLOCK;
import static com.sun.tools.javac.code.Kinds.*; import static com.sun.tools.javac.code.Kinds.*;
import static com.sun.tools.javac.code.Kinds.ERRONEOUS;
import static com.sun.tools.javac.code.TypeTags.*; import static com.sun.tools.javac.code.TypeTags.*;
import static com.sun.tools.javac.code.TypeTags.WILDCARD;
import static com.sun.tools.javac.tree.JCTree.Tag.*;
/** This is the main context-dependent analysis phase in GJC. It /** This is the main context-dependent analysis phase in GJC. It
* encompasses name resolution, type checking and constant folding as * encompasses name resolution, type checking and constant folding as
@ -245,7 +250,7 @@ public class Attr extends JCTree.Visitor {
((v.flags() & HASINIT) != 0 ((v.flags() & HASINIT) != 0
|| ||
!((base == null || !((base == null ||
(base.getTag() == JCTree.IDENT && TreeInfo.name(base) == names._this)) && (base.hasTag(IDENT) && TreeInfo.name(base) == names._this)) &&
isAssignableAsBlankFinal(v, env)))) { isAssignableAsBlankFinal(v, env)))) {
if (v.isResourceVariable()) { //TWR resource if (v.isResourceVariable()) { //TWR resource
log.error(pos, "try.resource.may.not.be.assigned", v); log.error(pos, "try.resource.may.not.be.assigned", v);
@ -263,7 +268,7 @@ public class Attr extends JCTree.Visitor {
* @param tree The candidate tree. * @param tree The candidate tree.
*/ */
boolean isStaticReference(JCTree tree) { boolean isStaticReference(JCTree tree) {
if (tree.getTag() == JCTree.SELECT) { if (tree.hasTag(SELECT)) {
Symbol lsym = TreeInfo.symbol(((JCFieldAccess) tree).selected); Symbol lsym = TreeInfo.symbol(((JCFieldAccess) tree).selected);
if (lsym == null || lsym.kind != TYP) { if (lsym == null || lsym.kind != TYP) {
return false; return false;
@ -693,7 +698,7 @@ public class Attr extends JCTree.Visitor {
// disable implicit outer instance from being passed. // disable implicit outer instance from being passed.
// (This would be an illegal access to "this before super"). // (This would be an illegal access to "this before super").
if (env.info.isSelfCall && if (env.info.isSelfCall &&
env.tree.getTag() == JCTree.NEWCLASS && env.tree.hasTag(NEWCLASS) &&
((JCNewClass) env.tree).encl == null) ((JCNewClass) env.tree).encl == null)
{ {
c.flags_field |= NOOUTERTHIS; c.flags_field |= NOOUTERTHIS;
@ -863,7 +868,7 @@ public class Attr extends JCTree.Visitor {
chk.checkDeprecatedAnnotation(tree.pos(), v); chk.checkDeprecatedAnnotation(tree.pos(), v);
if (tree.init != null) { if (tree.init != null) {
if ((v.flags_field & FINAL) != 0 && tree.init.getTag() != JCTree.NEWCLASS) { if ((v.flags_field & FINAL) != 0 && !tree.init.hasTag(NEWCLASS)) {
// In this case, `v' is final. Ensure that it's initializer is // In this case, `v' is final. Ensure that it's initializer is
// evaluated. // evaluated.
v.getConstValue(); // ensure initializer is evaluated v.getConstValue(); // ensure initializer is evaluated
@ -971,8 +976,8 @@ public class Attr extends JCTree.Visitor {
public void visitLabelled(JCLabeledStatement tree) { public void visitLabelled(JCLabeledStatement tree) {
// Check that label is not used in an enclosing statement // Check that label is not used in an enclosing statement
Env<AttrContext> env1 = env; Env<AttrContext> env1 = env;
while (env1 != null && env1.tree.getTag() != JCTree.CLASSDEF) { while (env1 != null && !env1.tree.hasTag(CLASSDEF)) {
if (env1.tree.getTag() == JCTree.LABELLED && if (env1.tree.hasTag(LABELLED) &&
((JCLabeledStatement) env1.tree).label == tree.label) { ((JCLabeledStatement) env1.tree).label == tree.label) {
log.error(tree.pos(), "label.already.in.use", log.error(tree.pos(), "label.already.in.use",
tree.label); tree.label);
@ -1052,14 +1057,14 @@ public class Attr extends JCTree.Visitor {
private static void addVars(List<JCStatement> stats, Scope switchScope) { private static void addVars(List<JCStatement> stats, Scope switchScope) {
for (;stats.nonEmpty(); stats = stats.tail) { for (;stats.nonEmpty(); stats = stats.tail) {
JCTree stat = stats.head; JCTree stat = stats.head;
if (stat.getTag() == JCTree.VARDEF) if (stat.hasTag(VARDEF))
switchScope.enter(((JCVariableDecl) stat).sym); switchScope.enter(((JCVariableDecl) stat).sym);
} }
} }
// where // where
/** Return the selected enumeration constant symbol, or null. */ /** Return the selected enumeration constant symbol, or null. */
private Symbol enumConstant(JCTree tree, Type enumType) { private Symbol enumConstant(JCTree tree, Type enumType) {
if (tree.getTag() != JCTree.IDENT) { if (!tree.hasTag(IDENT)) {
log.error(tree.pos(), "enum.label.must.be.unqualified.enum"); log.error(tree.pos(), "enum.label.must.be.unqualified.enum");
return syms.errSymbol; return syms.errSymbol;
} }
@ -1094,7 +1099,7 @@ public class Attr extends JCTree.Visitor {
localEnv; localEnv;
// Attribute resource declarations // Attribute resource declarations
for (JCTree resource : tree.resources) { for (JCTree resource : tree.resources) {
if (resource.getTag() == JCTree.VARDEF) { if (resource.hasTag(VARDEF)) {
attribStat(resource, tryEnv); attribStat(resource, tryEnv);
chk.checkType(resource, resource.type, syms.autoCloseableType, "try.not.applicable.to.type"); chk.checkType(resource, resource.type, syms.autoCloseableType, "try.not.applicable.to.type");
@ -1312,7 +1317,7 @@ public class Attr extends JCTree.Visitor {
* @param env The environment current at the jump statement. * @param env The environment current at the jump statement.
*/ */
private JCTree findJumpTarget(DiagnosticPosition pos, private JCTree findJumpTarget(DiagnosticPosition pos,
int tag, JCTree.Tag tag,
Name label, Name label,
Env<AttrContext> env) { Env<AttrContext> env) {
// Search environments outwards from the point of jump. // Search environments outwards from the point of jump.
@ -1320,15 +1325,15 @@ public class Attr extends JCTree.Visitor {
LOOP: LOOP:
while (env1 != null) { while (env1 != null) {
switch (env1.tree.getTag()) { switch (env1.tree.getTag()) {
case JCTree.LABELLED: case LABELLED:
JCLabeledStatement labelled = (JCLabeledStatement)env1.tree; JCLabeledStatement labelled = (JCLabeledStatement)env1.tree;
if (label == labelled.label) { if (label == labelled.label) {
// If jump is a continue, check that target is a loop. // If jump is a continue, check that target is a loop.
if (tag == JCTree.CONTINUE) { if (tag == CONTINUE) {
if (labelled.body.getTag() != JCTree.DOLOOP && if (!labelled.body.hasTag(DOLOOP) &&
labelled.body.getTag() != JCTree.WHILELOOP && !labelled.body.hasTag(WHILELOOP) &&
labelled.body.getTag() != JCTree.FORLOOP && !labelled.body.hasTag(FORLOOP) &&
labelled.body.getTag() != JCTree.FOREACHLOOP) !labelled.body.hasTag(FOREACHLOOP))
log.error(pos, "not.loop.label", label); log.error(pos, "not.loop.label", label);
// Found labelled statement target, now go inwards // Found labelled statement target, now go inwards
// to next non-labelled tree. // to next non-labelled tree.
@ -1338,17 +1343,17 @@ public class Attr extends JCTree.Visitor {
} }
} }
break; break;
case JCTree.DOLOOP: case DOLOOP:
case JCTree.WHILELOOP: case WHILELOOP:
case JCTree.FORLOOP: case FORLOOP:
case JCTree.FOREACHLOOP: case FOREACHLOOP:
if (label == null) return env1.tree; if (label == null) return env1.tree;
break; break;
case JCTree.SWITCH: case SWITCH:
if (label == null && tag == JCTree.BREAK) return env1.tree; if (label == null && tag == BREAK) return env1.tree;
break; break;
case JCTree.METHODDEF: case METHODDEF:
case JCTree.CLASSDEF: case CLASSDEF:
break LOOP; break LOOP;
default: default:
} }
@ -1356,7 +1361,7 @@ public class Attr extends JCTree.Visitor {
} }
if (label != null) if (label != null)
log.error(pos, "undef.label", label); log.error(pos, "undef.label", label);
else if (tag == JCTree.CONTINUE) else if (tag == CONTINUE)
log.error(pos, "cont.outside.loop"); log.error(pos, "cont.outside.loop");
else else
log.error(pos, "break.outside.switch.loop"); log.error(pos, "break.outside.switch.loop");
@ -1452,7 +1457,7 @@ public class Attr extends JCTree.Visitor {
if (encl.tag == CLASS) { if (encl.tag == CLASS) {
// we are calling a nested class // we are calling a nested class
if (tree.meth.getTag() == JCTree.SELECT) { if (tree.meth.hasTag(SELECT)) {
JCTree qualifier = ((JCFieldAccess) tree.meth).selected; JCTree qualifier = ((JCFieldAccess) tree.meth).selected;
// We are seeing a prefixed call, of the form // We are seeing a prefixed call, of the form
@ -1468,7 +1473,7 @@ public class Attr extends JCTree.Visitor {
rs.resolveImplicitThis(tree.meth.pos(), rs.resolveImplicitThis(tree.meth.pos(),
localEnv, site, true); localEnv, site, true);
} }
} else if (tree.meth.getTag() == JCTree.SELECT) { } else if (tree.meth.hasTag(SELECT)) {
log.error(tree.meth.pos(), "illegal.qual.not.icls", log.error(tree.meth.pos(), "illegal.qual.not.icls",
site.tsym); site.tsym);
} }
@ -1522,7 +1527,7 @@ public class Attr extends JCTree.Visitor {
// as a special case, array.clone() has a result that is // as a special case, array.clone() has a result that is
// the same as static type of the array being cloned // the same as static type of the array being cloned
if (tree.meth.getTag() == JCTree.SELECT && if (tree.meth.hasTag(SELECT) &&
allowCovariantReturns && allowCovariantReturns &&
methName == names.clone && methName == names.clone &&
types.isArray(((JCFieldAccess) tree.meth).selected.type)) types.isArray(((JCFieldAccess) tree.meth).selected.type))
@ -1531,7 +1536,7 @@ public class Attr extends JCTree.Visitor {
// as a special case, x.getClass() has type Class<? extends |X|> // as a special case, x.getClass() has type Class<? extends |X|>
if (allowGenerics && if (allowGenerics &&
methName == names.getClass && tree.args.isEmpty()) { methName == names.getClass && tree.args.isEmpty()) {
Type qualifier = (tree.meth.getTag() == JCTree.SELECT) Type qualifier = (tree.meth.hasTag(SELECT))
? ((JCFieldAccess) tree.meth).selected.type ? ((JCFieldAccess) tree.meth).selected.type
: env.enclClass.sym.type; : env.enclClass.sym.type;
restype = new restype = new
@ -1560,7 +1565,7 @@ public class Attr extends JCTree.Visitor {
JCMethodDecl enclMethod = env.enclMethod; JCMethodDecl enclMethod = env.enclMethod;
if (enclMethod != null && enclMethod.name == names.init) { if (enclMethod != null && enclMethod.name == names.init) {
JCBlock body = enclMethod.body; JCBlock body = enclMethod.body;
if (body.stats.head.getTag() == JCTree.EXEC && if (body.stats.head.hasTag(EXEC) &&
((JCExpressionStatement) body.stats.head).expr == tree) ((JCExpressionStatement) body.stats.head).expr == tree)
return true; return true;
} }
@ -1591,7 +1596,7 @@ public class Attr extends JCTree.Visitor {
// complete class name to be fully qualified // complete class name to be fully qualified
JCExpression clazz = tree.clazz; // Class field following new JCExpression clazz = tree.clazz; // Class field following new
JCExpression clazzid = // Identifier in class field JCExpression clazzid = // Identifier in class field
(clazz.getTag() == JCTree.TYPEAPPLY) (clazz.hasTag(TYPEAPPLY))
? ((JCTypeApply) clazz).clazz ? ((JCTypeApply) clazz).clazz
: clazz; : clazz;
@ -1610,7 +1615,7 @@ public class Attr extends JCTree.Visitor {
attribExpr(tree.encl, env)); attribExpr(tree.encl, env));
clazzid1 = make.at(clazz.pos).Select(make.Type(encltype), clazzid1 = make.at(clazz.pos).Select(make.Type(encltype),
((JCIdent) clazzid).name); ((JCIdent) clazzid).name);
if (clazz.getTag() == JCTree.TYPEAPPLY) if (clazz.hasTag(TYPEAPPLY))
clazz = make.at(tree.pos). clazz = make.at(tree.pos).
TypeApply(clazzid1, TypeApply(clazzid1,
((JCTypeApply) clazz).arguments); ((JCTypeApply) clazz).arguments);
@ -1689,7 +1694,7 @@ public class Attr extends JCTree.Visitor {
// Enums may not be instantiated except implicitly // Enums may not be instantiated except implicitly
if (allowEnums && if (allowEnums &&
(clazztype.tsym.flags_field&Flags.ENUM) != 0 && (clazztype.tsym.flags_field&Flags.ENUM) != 0 &&
(env.tree.getTag() != JCTree.VARDEF || (!env.tree.hasTag(VARDEF) ||
(((JCVariableDecl) env.tree).mods.flags&Flags.ENUM) == 0 || (((JCVariableDecl) env.tree).mods.flags&Flags.ENUM) == 0 ||
((JCVariableDecl) env.tree).init != tree)) ((JCVariableDecl) env.tree).init != tree))
log.error(tree.pos(), "enum.cant.be.instantiated"); log.error(tree.pos(), "enum.cant.be.instantiated");
@ -1930,7 +1935,7 @@ public class Attr extends JCTree.Visitor {
Name name = TreeInfo.name(arg); Name name = TreeInfo.name(arg);
if (name == names._this || name == names._super) return arg; if (name == names._this || name == names._super) return arg;
int optag = JCTree.NULLCHK; JCTree.Tag optag = NULLCHK;
JCUnary tree = make.at(arg.pos).Unary(optag, arg); JCUnary tree = make.at(arg.pos).Unary(optag, arg);
tree.operator = syms.nullcheck; tree.operator = syms.nullcheck;
tree.type = arg.type; tree.type = arg.type;
@ -1991,7 +1996,7 @@ public class Attr extends JCTree.Visitor {
Type operand = attribExpr(tree.rhs, env); Type operand = attribExpr(tree.rhs, env);
// Find operator. // Find operator.
Symbol operator = tree.operator = rs.resolveBinaryOperator( Symbol operator = tree.operator = rs.resolveBinaryOperator(
tree.pos(), tree.getTag() - JCTree.ASGOffset, env, tree.pos(), tree.getTag().noAssignOp(), env,
owntype, operand); owntype, operand);
if (operator.kind == MTH && if (operator.kind == MTH &&
@ -1999,7 +2004,7 @@ public class Attr extends JCTree.Visitor {
!operand.isErroneous()) { !operand.isErroneous()) {
chk.checkOperator(tree.pos(), chk.checkOperator(tree.pos(),
(OperatorSymbol)operator, (OperatorSymbol)operator,
tree.getTag() - JCTree.ASGOffset, tree.getTag().noAssignOp(),
owntype, owntype,
operand); operand);
chk.checkDivZero(tree.rhs.pos(), operator, operand); chk.checkDivZero(tree.rhs.pos(), operator, operand);
@ -2012,7 +2017,7 @@ public class Attr extends JCTree.Visitor {
public void visitUnary(JCUnary tree) { public void visitUnary(JCUnary tree) {
// Attribute arguments. // Attribute arguments.
Type argtype = (JCTree.PREINC <= tree.getTag() && tree.getTag() <= JCTree.POSTDEC) Type argtype = (tree.getTag().isIncOrDecUnaryOp())
? attribTree(tree.arg, env, VAR, Type.noType) ? attribTree(tree.arg, env, VAR, Type.noType)
: chk.checkNonVoid(tree.arg.pos(), attribExpr(tree.arg, env)); : chk.checkNonVoid(tree.arg.pos(), attribExpr(tree.arg, env));
@ -2023,7 +2028,7 @@ public class Attr extends JCTree.Visitor {
Type owntype = types.createErrorType(tree.type); Type owntype = types.createErrorType(tree.type);
if (operator.kind == MTH && if (operator.kind == MTH &&
!argtype.isErroneous()) { !argtype.isErroneous()) {
owntype = (JCTree.PREINC <= tree.getTag() && tree.getTag() <= JCTree.POSTDEC) owntype = (tree.getTag().isIncOrDecUnaryOp())
? tree.arg.type ? tree.arg.type
: operator.type.getReturnType(); : operator.type.getReturnType();
int opc = ((OperatorSymbol)operator).opcode; int opc = ((OperatorSymbol)operator).opcode;
@ -2621,7 +2626,7 @@ public class Attr extends JCTree.Visitor {
canOwnInitializer(env.info.scope.owner) && canOwnInitializer(env.info.scope.owner) &&
v.owner == env.info.scope.owner.enclClass() && v.owner == env.info.scope.owner.enclClass() &&
((v.flags() & STATIC) != 0) == Resolve.isStatic(env) && ((v.flags() & STATIC) != 0) == Resolve.isStatic(env) &&
(env.tree.getTag() != JCTree.ASSIGN || (!env.tree.hasTag(ASSIGN) ||
TreeInfo.skipParens(((JCAssign) env.tree).lhs) != tree)) { TreeInfo.skipParens(((JCAssign) env.tree).lhs) != tree)) {
String suffix = (env.info.enclVar == v) ? String suffix = (env.info.enclVar == v) ?
"self.ref" : "forward.ref"; "self.ref" : "forward.ref";
@ -2812,10 +2817,10 @@ public class Attr extends JCTree.Visitor {
} }
Type elemtype = types.elemtype(argtype); Type elemtype = types.elemtype(argtype);
switch (tree.getTag()) { switch (tree.getTag()) {
case JCTree.APPLY: case APPLY:
((JCMethodInvocation) tree).varargsElement = elemtype; ((JCMethodInvocation) tree).varargsElement = elemtype;
break; break;
case JCTree.NEWCLASS: case NEWCLASS:
((JCNewClass) tree).varargsElement = elemtype; ((JCNewClass) tree).varargsElement = elemtype;
break; break;
default: default:
@ -2896,9 +2901,9 @@ public class Attr extends JCTree.Visitor {
if (clazzOuter.tag == CLASS) { if (clazzOuter.tag == CLASS) {
Type site; Type site;
JCExpression clazz = TreeInfo.typeIn(tree.clazz); JCExpression clazz = TreeInfo.typeIn(tree.clazz);
if (clazz.getTag() == JCTree.IDENT) { if (clazz.hasTag(IDENT)) {
site = env.enclClass.sym.type; site = env.enclClass.sym.type;
} else if (clazz.getTag() == JCTree.SELECT) { } else if (clazz.hasTag(SELECT)) {
site = ((JCFieldAccess) clazz).selected.type; site = ((JCFieldAccess) clazz).selected.type;
} else throw new AssertionError(""+tree); } else throw new AssertionError(""+tree);
if (clazzOuter.tag == CLASS && site != clazzOuter) { if (clazzOuter.tag == CLASS && site != clazzOuter) {
@ -3068,7 +3073,7 @@ public class Attr extends JCTree.Visitor {
* Attribute an env for either a top level tree or class declaration. * Attribute an env for either a top level tree or class declaration.
*/ */
public void attrib(Env<AttrContext> env) { public void attrib(Env<AttrContext> env) {
if (env.tree.getTag() == JCTree.TOPLEVEL) if (env.tree.hasTag(TOPLEVEL))
attribTopLevel(env); attribTopLevel(env);
else else
attribClass(env.tree.pos(), env.enclClass.sym); attribClass(env.tree.pos(), env.enclClass.sym);
@ -3245,7 +3250,7 @@ public class Attr extends JCTree.Visitor {
((c.flags() & STATIC) == 0 || c.name == names.empty) && ((c.flags() & STATIC) == 0 || c.name == names.empty) &&
(TreeInfo.flags(l.head) & (STATIC | INTERFACE)) != 0) { (TreeInfo.flags(l.head) & (STATIC | INTERFACE)) != 0) {
Symbol sym = null; Symbol sym = null;
if (l.head.getTag() == JCTree.VARDEF) sym = ((JCVariableDecl) l.head).sym; if (l.head.hasTag(VARDEF)) sym = ((JCVariableDecl) l.head).sym;
if (sym == null || if (sym == null ||
sym.kind != VAR || sym.kind != VAR ||
((VarSymbol) sym).getConstValue() == null) ((VarSymbol) sym).getConstValue() == null)

View file

@ -42,10 +42,14 @@ import com.sun.tools.javac.code.Type.*;
import com.sun.tools.javac.code.Symbol.*; import com.sun.tools.javac.code.Symbol.*;
import static com.sun.tools.javac.code.Flags.*; import static com.sun.tools.javac.code.Flags.*;
import static com.sun.tools.javac.code.Flags.ANNOTATION;
import static com.sun.tools.javac.code.Flags.SYNCHRONIZED;
import static com.sun.tools.javac.code.Kinds.*; import static com.sun.tools.javac.code.Kinds.*;
import static com.sun.tools.javac.code.TypeTags.*; import static com.sun.tools.javac.code.TypeTags.*;
import static com.sun.tools.javac.code.TypeTags.WILDCARD;
import static com.sun.tools.javac.main.OptionName.*; import static com.sun.tools.javac.main.OptionName.*;
import static com.sun.tools.javac.tree.JCTree.Tag.*;
/** Type checking helper class for the attribution phase. /** Type checking helper class for the attribution phase.
* *
@ -987,7 +991,7 @@ public class Check {
* <i>not</i> final. * <i>not</i> final.
*/ */
private long implicitEnumFinalFlag(JCTree tree) { private long implicitEnumFinalFlag(JCTree tree) {
if (tree.getTag() != JCTree.CLASSDEF) return 0; if (!tree.hasTag(CLASSDEF)) return 0;
class SpecialTreeVisitor extends JCTree.Visitor { class SpecialTreeVisitor extends JCTree.Visitor {
boolean specialized; boolean specialized;
SpecialTreeVisitor() { SpecialTreeVisitor() {
@ -1099,7 +1103,7 @@ public class Check {
// not parameterized at all. // not parameterized at all.
if (tree.type.getEnclosingType().isRaw()) if (tree.type.getEnclosingType().isRaw())
log.error(tree.pos(), "improperly.formed.type.inner.raw.param"); log.error(tree.pos(), "improperly.formed.type.inner.raw.param");
if (tree.clazz.getTag() == JCTree.SELECT) if (tree.clazz.hasTag(SELECT))
visitSelectInternal((JCFieldAccess)tree.clazz); visitSelectInternal((JCFieldAccess)tree.clazz);
} }
} }
@ -2413,7 +2417,7 @@ public class Check {
// count them off as they're annotated // count them off as they're annotated
for (JCTree arg : a.args) { for (JCTree arg : a.args) {
if (arg.getTag() != JCTree.ASSIGN) continue; // recovery if (!arg.hasTag(ASSIGN)) continue; // recovery
JCAssign assign = (JCAssign) arg; JCAssign assign = (JCAssign) arg;
Symbol m = TreeInfo.symbol(assign.lhs); Symbol m = TreeInfo.symbol(assign.lhs);
if (m == null || m.type.isErroneous()) continue; if (m == null || m.type.isErroneous()) continue;
@ -2442,12 +2446,12 @@ public class Check {
a.args.tail == null) a.args.tail == null)
return; return;
if (a.args.head.getTag() != JCTree.ASSIGN) return; // error recovery if (!a.args.head.hasTag(ASSIGN)) return; // error recovery
JCAssign assign = (JCAssign) a.args.head; JCAssign assign = (JCAssign) a.args.head;
Symbol m = TreeInfo.symbol(assign.lhs); Symbol m = TreeInfo.symbol(assign.lhs);
if (m.name != names.value) return; if (m.name != names.value) return;
JCTree rhs = assign.rhs; JCTree rhs = assign.rhs;
if (rhs.getTag() != JCTree.NEWARRAY) return; if (!rhs.hasTag(NEWARRAY)) return;
JCNewArray na = (JCNewArray) rhs; JCNewArray na = (JCNewArray) rhs;
Set<Symbol> targets = new HashSet<Symbol>(); Set<Symbol> targets = new HashSet<Symbol>();
for (JCTree elem : na.elems) { for (JCTree elem : na.elems) {
@ -2506,7 +2510,7 @@ public class Check {
try { try {
tree.sym.flags_field |= LOCKED; tree.sym.flags_field |= LOCKED;
for (JCTree def : tree.defs) { for (JCTree def : tree.defs) {
if (def.getTag() != JCTree.METHODDEF) continue; if (!def.hasTag(METHODDEF)) continue;
JCMethodDecl meth = (JCMethodDecl)def; JCMethodDecl meth = (JCMethodDecl)def;
checkAnnotationResType(meth.pos(), meth.restype.type); checkAnnotationResType(meth.pos(), meth.restype.type);
} }
@ -2614,7 +2618,7 @@ public class Check {
*/ */
int checkOperator(DiagnosticPosition pos, int checkOperator(DiagnosticPosition pos,
OperatorSymbol operator, OperatorSymbol operator,
int tag, JCTree.Tag tag,
Type left, Type left,
Type right) { Type right) {
if (operator.opcode == ByteCodes.error) { if (operator.opcode == ByteCodes.error) {
@ -2650,7 +2654,8 @@ public class Check {
* Check for empty statements after if * Check for empty statements after if
*/ */
void checkEmptyIf(JCIf tree) { void checkEmptyIf(JCIf tree) {
if (tree.thenpart.getTag() == JCTree.SKIP && tree.elsepart == null && lint.isEnabled(LintCategory.EMPTY)) if (tree.thenpart.hasTag(SKIP) && tree.elsepart == null &&
lint.isEnabled(LintCategory.EMPTY))
log.warning(LintCategory.EMPTY, tree.thenpart.pos(), "empty.if"); log.warning(LintCategory.EMPTY, tree.thenpart.pos(), "empty.if");
} }
@ -2754,7 +2759,7 @@ public class Check {
} }
// where // where
private boolean isCanonical(JCTree tree) { private boolean isCanonical(JCTree tree) {
while (tree.getTag() == JCTree.SELECT) { while (tree.hasTag(SELECT)) {
JCFieldAccess s = (JCFieldAccess) tree; JCFieldAccess s = (JCFieldAccess) tree;
if (s.sym.owner != TreeInfo.symbol(s.selected)) if (s.sym.owner != TreeInfo.symbol(s.selected))
return false; return false;

View file

@ -228,7 +228,7 @@ public class Enter extends JCTree.Visitor {
* only, and members go into the class member scope. * only, and members go into the class member scope.
*/ */
Scope enterScope(Env<AttrContext> env) { Scope enterScope(Env<AttrContext> env) {
return (env.tree.getTag() == JCTree.CLASSDEF) return (env.tree.hasTag(JCTree.Tag.CLASSDEF))
? ((JCClassDecl) env.tree).sym.members_field ? ((JCClassDecl) env.tree).sym.members_field
: env.info.scope; : env.info.scope;
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -116,9 +116,9 @@ public class Env<A> implements Iterable<Env<A>> {
/** Return closest enclosing environment which points to a tree with given tag. /** Return closest enclosing environment which points to a tree with given tag.
*/ */
public Env<A> enclosing(int tag) { public Env<A> enclosing(JCTree.Tag tag) {
Env<A> env1 = this; Env<A> env1 = this;
while (env1 != null && env1.tree.getTag() != tag) env1 = env1.next; while (env1 != null && !env1.tree.hasTag(tag)) env1 = env1.next;
return env1; return env1;
} }

View file

@ -40,8 +40,10 @@ import com.sun.tools.javac.code.Symbol.*;
import com.sun.tools.javac.tree.JCTree.*; import com.sun.tools.javac.tree.JCTree.*;
import static com.sun.tools.javac.code.Flags.*; import static com.sun.tools.javac.code.Flags.*;
import static com.sun.tools.javac.code.Flags.BLOCK;
import static com.sun.tools.javac.code.Kinds.*; import static com.sun.tools.javac.code.Kinds.*;
import static com.sun.tools.javac.code.TypeTags.*; import static com.sun.tools.javac.code.TypeTags.*;
import static com.sun.tools.javac.tree.JCTree.Tag.*;
/** This pass implements dataflow analysis for Java programs. /** This pass implements dataflow analysis for Java programs.
* Liveness analysis checks that every statement is reachable. * Liveness analysis checks that every statement is reachable.
@ -321,7 +323,7 @@ public class Flow extends TreeScanner {
log.error(exit.tree.pos(), log.error(exit.tree.pos(),
"unreported.exception.default.constructor", "unreported.exception.default.constructor",
exit.thrown); exit.thrown);
} else if (exit.tree.getTag() == JCTree.VARDEF && } else if (exit.tree.hasTag(VARDEF) &&
((JCVariableDecl)exit.tree).sym.isResourceVariable()) { ((JCVariableDecl)exit.tree).sym.isResourceVariable()) {
log.error(exit.tree.pos(), log.error(exit.tree.pos(),
"unreported.exception.implicit.close", "unreported.exception.implicit.close",
@ -416,7 +418,7 @@ public class Flow extends TreeScanner {
*/ */
void letInit(JCTree tree) { void letInit(JCTree tree) {
tree = TreeInfo.skipParens(tree); tree = TreeInfo.skipParens(tree);
if (tree.getTag() == JCTree.IDENT || tree.getTag() == JCTree.SELECT) { if (tree.hasTag(IDENT) || tree.hasTag(SELECT)) {
Symbol sym = TreeInfo.symbol(tree); Symbol sym = TreeInfo.symbol(tree);
if (sym.kind == VAR) { if (sym.kind == VAR) {
letInit(tree.pos(), (VarSymbol)sym); letInit(tree.pos(), (VarSymbol)sym);
@ -452,7 +454,7 @@ public class Flow extends TreeScanner {
pendingExits = oldPendingExits; pendingExits = oldPendingExits;
for (; exits.nonEmpty(); exits = exits.tail) { for (; exits.nonEmpty(); exits = exits.tail) {
PendingExit exit = exits.head; PendingExit exit = exits.head;
if (exit.tree.getTag() == JCTree.BREAK && if (exit.tree.hasTag(BREAK) &&
((JCBreak) exit.tree).target == tree) { ((JCBreak) exit.tree).target == tree) {
inits.andSet(exit.inits); inits.andSet(exit.inits);
uninits.andSet(exit.uninits); uninits.andSet(exit.uninits);
@ -471,7 +473,7 @@ public class Flow extends TreeScanner {
pendingExits = new ListBuffer<PendingExit>(); pendingExits = new ListBuffer<PendingExit>();
for (; exits.nonEmpty(); exits = exits.tail) { for (; exits.nonEmpty(); exits = exits.tail) {
PendingExit exit = exits.head; PendingExit exit = exits.head;
if (exit.tree.getTag() == JCTree.CONTINUE && if (exit.tree.hasTag(CONTINUE) &&
((JCContinue) exit.tree).target == tree) { ((JCContinue) exit.tree).target == tree) {
inits.andSet(exit.inits); inits.andSet(exit.inits);
uninits.andSet(exit.uninits); uninits.andSet(exit.uninits);
@ -517,7 +519,7 @@ public class Flow extends TreeScanner {
*/ */
void scanDef(JCTree tree) { void scanDef(JCTree tree) {
scanStat(tree); scanStat(tree);
if (tree != null && tree.getTag() == JCTree.BLOCK && !alive) { if (tree != null && tree.hasTag(JCTree.Tag.BLOCK) && !alive) {
log.error(tree.pos(), log.error(tree.pos(),
"initializer.must.be.able.to.complete.normally"); "initializer.must.be.able.to.complete.normally");
} }
@ -528,7 +530,7 @@ public class Flow extends TreeScanner {
void scanStat(JCTree tree) { void scanStat(JCTree tree) {
if (!alive && tree != null) { if (!alive && tree != null) {
log.error(tree.pos(), "unreachable.stmt"); log.error(tree.pos(), "unreachable.stmt");
if (tree.getTag() != JCTree.SKIP) alive = true; if (!tree.hasTag(SKIP)) alive = true;
} }
scan(tree); scan(tree);
} }
@ -614,7 +616,7 @@ public class Flow extends TreeScanner {
try { try {
// define all the static fields // define all the static fields
for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) { for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) {
if (l.head.getTag() == JCTree.VARDEF) { if (l.head.hasTag(VARDEF)) {
JCVariableDecl def = (JCVariableDecl)l.head; JCVariableDecl def = (JCVariableDecl)l.head;
if ((def.mods.flags & STATIC) != 0) { if ((def.mods.flags & STATIC) != 0) {
VarSymbol sym = def.sym; VarSymbol sym = def.sym;
@ -626,7 +628,7 @@ public class Flow extends TreeScanner {
// process all the static initializers // process all the static initializers
for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) { for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) {
if (l.head.getTag() != JCTree.METHODDEF && if (!l.head.hasTag(METHODDEF) &&
(TreeInfo.flags(l.head) & STATIC) != 0) { (TreeInfo.flags(l.head) & STATIC) != 0) {
scanDef(l.head); scanDef(l.head);
errorUncaught(); errorUncaught();
@ -653,7 +655,7 @@ public class Flow extends TreeScanner {
// define all the instance fields // define all the instance fields
for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) { for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) {
if (l.head.getTag() == JCTree.VARDEF) { if (l.head.hasTag(VARDEF)) {
JCVariableDecl def = (JCVariableDecl)l.head; JCVariableDecl def = (JCVariableDecl)l.head;
if ((def.mods.flags & STATIC) == 0) { if ((def.mods.flags & STATIC) == 0) {
VarSymbol sym = def.sym; VarSymbol sym = def.sym;
@ -665,7 +667,7 @@ public class Flow extends TreeScanner {
// process all the instance initializers // process all the instance initializers
for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) { for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) {
if (l.head.getTag() != JCTree.METHODDEF && if (!l.head.hasTag(METHODDEF) &&
(TreeInfo.flags(l.head) & STATIC) == 0) { (TreeInfo.flags(l.head) & STATIC) == 0) {
scanDef(l.head); scanDef(l.head);
errorUncaught(); errorUncaught();
@ -691,7 +693,7 @@ public class Flow extends TreeScanner {
// process all the methods // process all the methods
for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) { for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) {
if (l.head.getTag() == JCTree.METHODDEF) { if (l.head.hasTag(METHODDEF)) {
scan(l.head); scan(l.head);
errorUncaught(); errorUncaught();
} }
@ -760,7 +762,7 @@ public class Flow extends TreeScanner {
PendingExit exit = exits.head; PendingExit exit = exits.head;
exits = exits.tail; exits = exits.tail;
if (exit.thrown == null) { if (exit.thrown == null) {
Assert.check(exit.tree.getTag() == JCTree.RETURN); Assert.check(exit.tree.hasTag(RETURN));
if (isInitialConstructor) { if (isInitialConstructor) {
inits = exit.inits; inits = exit.inits;
for (int i = firstadr; i < nextadr; i++) for (int i = firstadr; i < nextadr; i++)
@ -989,7 +991,7 @@ public class Flow extends TreeScanner {
Bits uninits) { Bits uninits) {
for (;stats.nonEmpty(); stats = stats.tail) { for (;stats.nonEmpty(); stats = stats.tail) {
JCTree stat = stats.head; JCTree stat = stats.head;
if (stat.getTag() == JCTree.VARDEF) { if (stat.hasTag(VARDEF)) {
int adr = ((JCVariableDecl) stat).sym.adr; int adr = ((JCVariableDecl) stat).sym.adr;
inits.excl(adr); inits.excl(adr);
uninits.incl(adr); uninits.incl(adr);
@ -1346,7 +1348,7 @@ public class Flow extends TreeScanner {
public void visitUnary(JCUnary tree) { public void visitUnary(JCUnary tree) {
switch (tree.getTag()) { switch (tree.getTag()) {
case JCTree.NOT: case NOT:
scanCond(tree.arg); scanCond(tree.arg);
Bits t = initsWhenFalse; Bits t = initsWhenFalse;
initsWhenFalse = initsWhenTrue; initsWhenFalse = initsWhenTrue;
@ -1355,8 +1357,8 @@ public class Flow extends TreeScanner {
uninitsWhenFalse = uninitsWhenTrue; uninitsWhenFalse = uninitsWhenTrue;
uninitsWhenTrue = t; uninitsWhenTrue = t;
break; break;
case JCTree.PREINC: case JCTree.POSTINC: case PREINC: case POSTINC:
case JCTree.PREDEC: case JCTree.POSTDEC: case PREDEC: case POSTDEC:
scanExpr(tree.arg); scanExpr(tree.arg);
letInit(tree.arg); letInit(tree.arg);
break; break;
@ -1367,7 +1369,7 @@ public class Flow extends TreeScanner {
public void visitBinary(JCBinary tree) { public void visitBinary(JCBinary tree) {
switch (tree.getTag()) { switch (tree.getTag()) {
case JCTree.AND: case AND:
scanCond(tree.lhs); scanCond(tree.lhs);
Bits initsWhenFalseLeft = initsWhenFalse; Bits initsWhenFalseLeft = initsWhenFalse;
Bits uninitsWhenFalseLeft = uninitsWhenFalse; Bits uninitsWhenFalseLeft = uninitsWhenFalse;
@ -1377,7 +1379,7 @@ public class Flow extends TreeScanner {
initsWhenFalse.andSet(initsWhenFalseLeft); initsWhenFalse.andSet(initsWhenFalseLeft);
uninitsWhenFalse.andSet(uninitsWhenFalseLeft); uninitsWhenFalse.andSet(uninitsWhenFalseLeft);
break; break;
case JCTree.OR: case OR:
scanCond(tree.lhs); scanCond(tree.lhs);
Bits initsWhenTrueLeft = initsWhenTrue; Bits initsWhenTrueLeft = initsWhenTrue;
Bits uninitsWhenTrueLeft = uninitsWhenTrue; Bits uninitsWhenTrueLeft = uninitsWhenTrue;
@ -1418,7 +1420,7 @@ public class Flow extends TreeScanner {
private boolean is292targetTypeCast(JCTypeCast tree) { private boolean is292targetTypeCast(JCTypeCast tree) {
boolean is292targetTypeCast = false; boolean is292targetTypeCast = false;
JCExpression expr = TreeInfo.skipParens(tree.expr); JCExpression expr = TreeInfo.skipParens(tree.expr);
if (expr.getTag() == JCTree.APPLY) { if (expr.hasTag(APPLY)) {
JCMethodInvocation apply = (JCMethodInvocation)expr; JCMethodInvocation apply = (JCMethodInvocation)expr;
Symbol sym = TreeInfo.symbol(apply.meth); Symbol sym = TreeInfo.symbol(apply.meth);
is292targetTypeCast = sym != null && is292targetTypeCast = sym != null &&

View file

@ -633,13 +633,13 @@ public class Infer {
//the polymorphic signature call environment is nested. //the polymorphic signature call environment is nested.
switch (env.next.tree.getTag()) { switch (env.next.tree.getTag()) {
case JCTree.TYPECAST: case TYPECAST:
JCTypeCast castTree = (JCTypeCast)env.next.tree; JCTypeCast castTree = (JCTypeCast)env.next.tree;
restype = (TreeInfo.skipParens(castTree.expr) == env.tree) ? restype = (TreeInfo.skipParens(castTree.expr) == env.tree) ?
castTree.clazz.type : castTree.clazz.type :
syms.objectType; syms.objectType;
break; break;
case JCTree.EXEC: case EXEC:
JCTree.JCExpressionStatement execTree = JCTree.JCExpressionStatement execTree =
(JCTree.JCExpressionStatement)env.next.tree; (JCTree.JCExpressionStatement)env.next.tree;
restype = (TreeInfo.skipParens(execTree.expr) == env.tree) ? restype = (TreeInfo.skipParens(execTree.expr) == env.tree) ?

View file

@ -42,9 +42,11 @@ import com.sun.tools.javac.code.Type.*;
import com.sun.tools.javac.jvm.Target; import com.sun.tools.javac.jvm.Target;
import static com.sun.tools.javac.code.Flags.*; import static com.sun.tools.javac.code.Flags.*;
import static com.sun.tools.javac.code.Flags.BLOCK;
import static com.sun.tools.javac.code.Kinds.*; import static com.sun.tools.javac.code.Kinds.*;
import static com.sun.tools.javac.code.TypeTags.*; import static com.sun.tools.javac.code.TypeTags.*;
import static com.sun.tools.javac.jvm.ByteCodes.*; import static com.sun.tools.javac.jvm.ByteCodes.*;
import static com.sun.tools.javac.tree.JCTree.Tag.*;
/** This pass translates away some syntactic sugar: inner classes, /** This pass translates away some syntactic sugar: inner classes,
* class literals, assertions, foreach loops, etc. * class literals, assertions, foreach loops, etc.
@ -303,7 +305,7 @@ public class Lower extends TreeTranslator {
Symbol constructor = TreeInfo.symbol(tree.meth); Symbol constructor = TreeInfo.symbol(tree.meth);
ClassSymbol c = (ClassSymbol)constructor.owner; ClassSymbol c = (ClassSymbol)constructor.owner;
if (c.hasOuterInstance() && if (c.hasOuterInstance() &&
tree.meth.getTag() != JCTree.SELECT && !tree.meth.hasTag(SELECT) &&
outerThisStack.head != null) outerThisStack.head != null)
visitSymbol(outerThisStack.head); visitSymbol(outerThisStack.head);
} }
@ -508,7 +510,7 @@ public class Lower extends TreeTranslator {
* @param optag The operators tree tag. * @param optag The operators tree tag.
* @param arg The operator's argument. * @param arg The operator's argument.
*/ */
JCUnary makeUnary(int optag, JCExpression arg) { JCUnary makeUnary(JCTree.Tag optag, JCExpression arg) {
JCUnary tree = make.Unary(optag, arg); JCUnary tree = make.Unary(optag, arg);
tree.operator = rs.resolveUnaryOperator( tree.operator = rs.resolveUnaryOperator(
make_pos, optag, attrEnv, arg.type); make_pos, optag, attrEnv, arg.type);
@ -521,7 +523,7 @@ public class Lower extends TreeTranslator {
* @param lhs The operator's left argument. * @param lhs The operator's left argument.
* @param rhs The operator's right argument. * @param rhs The operator's right argument.
*/ */
JCBinary makeBinary(int optag, JCExpression lhs, JCExpression rhs) { JCBinary makeBinary(JCTree.Tag optag, JCExpression lhs, JCExpression rhs) {
JCBinary tree = make.Binary(optag, lhs, rhs); JCBinary tree = make.Binary(optag, lhs, rhs);
tree.operator = rs.resolveBinaryOperator( tree.operator = rs.resolveBinaryOperator(
make_pos, optag, attrEnv, lhs.type, rhs.type); make_pos, optag, attrEnv, lhs.type, rhs.type);
@ -534,10 +536,10 @@ public class Lower extends TreeTranslator {
* @param lhs The operator's left argument. * @param lhs The operator's left argument.
* @param rhs The operator's right argument. * @param rhs The operator's right argument.
*/ */
JCAssignOp makeAssignop(int optag, JCTree lhs, JCTree rhs) { JCAssignOp makeAssignop(JCTree.Tag optag, JCTree lhs, JCTree rhs) {
JCAssignOp tree = make.Assignop(optag, lhs, rhs); JCAssignOp tree = make.Assignop(optag, lhs, rhs);
tree.operator = rs.resolveBinaryOperator( tree.operator = rs.resolveBinaryOperator(
make_pos, tree.getTag() - JCTree.ASGOffset, attrEnv, lhs.type, rhs.type); make_pos, tree.getTag().noAssignOp(), attrEnv, lhs.type, rhs.type);
tree.type = lhs.type; tree.type = lhs.type;
return tree; return tree;
} }
@ -720,7 +722,7 @@ public class Lower extends TreeTranslator {
// where // where
private boolean isTranslatedClassAvailable(ClassSymbol c) { private boolean isTranslatedClassAvailable(ClassSymbol c) {
for (JCTree tree: translated) { for (JCTree tree: translated) {
if (tree.getTag() == JCTree.CLASSDEF if (tree.hasTag(CLASSDEF)
&& ((JCClassDecl) tree).sym == c) { && ((JCClassDecl) tree).sym == c) {
return true; return true;
} }
@ -802,13 +804,13 @@ public class Lower extends TreeTranslator {
private static int accessCode(JCTree tree, JCTree enclOp) { private static int accessCode(JCTree tree, JCTree enclOp) {
if (enclOp == null) if (enclOp == null)
return DEREFcode; return DEREFcode;
else if (enclOp.getTag() == JCTree.ASSIGN && else if (enclOp.hasTag(ASSIGN) &&
tree == TreeInfo.skipParens(((JCAssign) enclOp).lhs)) tree == TreeInfo.skipParens(((JCAssign) enclOp).lhs))
return ASSIGNcode; return ASSIGNcode;
else if (JCTree.PREINC <= enclOp.getTag() && enclOp.getTag() <= JCTree.POSTDEC && else if (enclOp.getTag().isIncOrDecUnaryOp() &&
tree == TreeInfo.skipParens(((JCUnary) enclOp).arg)) tree == TreeInfo.skipParens(((JCUnary) enclOp).arg))
return (enclOp.getTag() - JCTree.PREINC) * 2 + PREINCcode; return mapTagToUnaryOpCode(enclOp.getTag());
else if (JCTree.BITOR_ASG <= enclOp.getTag() && enclOp.getTag() <= JCTree.MOD_ASG && else if (enclOp.getTag().isAssignop() &&
tree == TreeInfo.skipParens(((JCAssignOp) enclOp).lhs)) tree == TreeInfo.skipParens(((JCAssignOp) enclOp).lhs))
return accessCode(((OperatorSymbol) ((JCAssignOp) enclOp).operator).opcode); return accessCode(((OperatorSymbol) ((JCAssignOp) enclOp).operator).opcode);
else else
@ -832,39 +834,39 @@ public class Lower extends TreeTranslator {
/** Return tree tag for assignment operation corresponding /** Return tree tag for assignment operation corresponding
* to given binary operator. * to given binary operator.
*/ */
private static int treeTag(OperatorSymbol operator) { private static JCTree.Tag treeTag(OperatorSymbol operator) {
switch (operator.opcode) { switch (operator.opcode) {
case ByteCodes.ior: case ByteCodes.lor: case ByteCodes.ior: case ByteCodes.lor:
return JCTree.BITOR_ASG; return BITOR_ASG;
case ByteCodes.ixor: case ByteCodes.lxor: case ByteCodes.ixor: case ByteCodes.lxor:
return JCTree.BITXOR_ASG; return BITXOR_ASG;
case ByteCodes.iand: case ByteCodes.land: case ByteCodes.iand: case ByteCodes.land:
return JCTree.BITAND_ASG; return BITAND_ASG;
case ByteCodes.ishl: case ByteCodes.lshl: case ByteCodes.ishl: case ByteCodes.lshl:
case ByteCodes.ishll: case ByteCodes.lshll: case ByteCodes.ishll: case ByteCodes.lshll:
return JCTree.SL_ASG; return SL_ASG;
case ByteCodes.ishr: case ByteCodes.lshr: case ByteCodes.ishr: case ByteCodes.lshr:
case ByteCodes.ishrl: case ByteCodes.lshrl: case ByteCodes.ishrl: case ByteCodes.lshrl:
return JCTree.SR_ASG; return SR_ASG;
case ByteCodes.iushr: case ByteCodes.lushr: case ByteCodes.iushr: case ByteCodes.lushr:
case ByteCodes.iushrl: case ByteCodes.lushrl: case ByteCodes.iushrl: case ByteCodes.lushrl:
return JCTree.USR_ASG; return USR_ASG;
case ByteCodes.iadd: case ByteCodes.ladd: case ByteCodes.iadd: case ByteCodes.ladd:
case ByteCodes.fadd: case ByteCodes.dadd: case ByteCodes.fadd: case ByteCodes.dadd:
case ByteCodes.string_add: case ByteCodes.string_add:
return JCTree.PLUS_ASG; return PLUS_ASG;
case ByteCodes.isub: case ByteCodes.lsub: case ByteCodes.isub: case ByteCodes.lsub:
case ByteCodes.fsub: case ByteCodes.dsub: case ByteCodes.fsub: case ByteCodes.dsub:
return JCTree.MINUS_ASG; return MINUS_ASG;
case ByteCodes.imul: case ByteCodes.lmul: case ByteCodes.imul: case ByteCodes.lmul:
case ByteCodes.fmul: case ByteCodes.dmul: case ByteCodes.fmul: case ByteCodes.dmul:
return JCTree.MUL_ASG; return MUL_ASG;
case ByteCodes.idiv: case ByteCodes.ldiv: case ByteCodes.idiv: case ByteCodes.ldiv:
case ByteCodes.fdiv: case ByteCodes.ddiv: case ByteCodes.fdiv: case ByteCodes.ddiv:
return JCTree.DIV_ASG; return DIV_ASG;
case ByteCodes.imod: case ByteCodes.lmod: case ByteCodes.imod: case ByteCodes.lmod:
case ByteCodes.fmod: case ByteCodes.dmod: case ByteCodes.fmod: case ByteCodes.dmod:
return JCTree.MOD_ASG; return MOD_ASG;
default: default:
throw new AssertionError(); throw new AssertionError();
} }
@ -1003,7 +1005,7 @@ public class Lower extends TreeTranslator {
if (!currentClass.isSubClass(sym.owner, types)) if (!currentClass.isSubClass(sym.owner, types))
return true; return true;
if ((sym.flags() & STATIC) != 0 || if ((sym.flags() & STATIC) != 0 ||
tree.getTag() != JCTree.SELECT || !tree.hasTag(SELECT) ||
TreeInfo.name(((JCFieldAccess) tree).selected) == names._super) TreeInfo.name(((JCFieldAccess) tree).selected) == names._super)
return false; return false;
return !((JCFieldAccess) tree).selected.type.tsym.isSubClass(currentClass, types); return !((JCFieldAccess) tree).selected.type.tsym.isSubClass(currentClass, types);
@ -1018,7 +1020,7 @@ public class Lower extends TreeTranslator {
if (protAccess) { if (protAccess) {
Symbol qualifier = null; Symbol qualifier = null;
ClassSymbol c = currentClass; ClassSymbol c = currentClass;
if (tree.getTag() == JCTree.SELECT && (sym.flags() & STATIC) == 0) { if (tree.hasTag(SELECT) && (sym.flags() & STATIC) == 0) {
qualifier = ((JCFieldAccess) tree).selected.type.tsym; qualifier = ((JCFieldAccess) tree).selected.type.tsym;
while (!qualifier.isSubClass(c, types)) { while (!qualifier.isSubClass(c, types)) {
c = c.owner.enclClass(); c = c.owner.enclClass();
@ -1058,7 +1060,7 @@ public class Lower extends TreeTranslator {
Assert.check(sym != null && (sym.flags_field & FINAL) != 0); Assert.check(sym != null && (sym.flags_field & FINAL) != 0);
tree = make.at(tree.pos).Ident(sym); tree = make.at(tree.pos).Ident(sym);
} }
JCExpression base = (tree.getTag() == JCTree.SELECT) ? ((JCFieldAccess) tree).selected : null; JCExpression base = (tree.hasTag(SELECT)) ? ((JCFieldAccess) tree).selected : null;
switch (sym.kind) { switch (sym.kind) {
case TYP: case TYP:
if (sym.owner.kind != PCK) { if (sym.owner.kind != PCK) {
@ -1068,11 +1070,11 @@ public class Lower extends TreeTranslator {
while (base != null && while (base != null &&
TreeInfo.symbol(base) != null && TreeInfo.symbol(base) != null &&
TreeInfo.symbol(base).kind != PCK) { TreeInfo.symbol(base).kind != PCK) {
base = (base.getTag() == JCTree.SELECT) base = (base.hasTag(SELECT))
? ((JCFieldAccess) base).selected ? ((JCFieldAccess) base).selected
: null; : null;
} }
if (tree.getTag() == JCTree.IDENT) { if (tree.hasTag(IDENT)) {
((JCIdent) tree).name = flatname; ((JCIdent) tree).name = flatname;
} else if (base == null) { } else if (base == null) {
tree = make.at(tree.pos).Ident(sym); tree = make.at(tree.pos).Ident(sym);
@ -1220,6 +1222,42 @@ public class Lower extends TreeTranslator {
} }
} }
/** Maps unary operator integer codes to JCTree.Tag objects
* @param unaryOpCode the unary operator code
*/
private static Tag mapUnaryOpCodeToTag(int unaryOpCode){
switch (unaryOpCode){
case PREINCcode:
return PREINC;
case PREDECcode:
return PREDEC;
case POSTINCcode:
return POSTINC;
case POSTDECcode:
return POSTDEC;
default:
return NO_TAG;
}
}
/** Maps JCTree.Tag objects to unary operator integer codes
* @param tag the JCTree.Tag
*/
private static int mapTagToUnaryOpCode(Tag tag){
switch (tag){
case PREINC:
return PREINCcode;
case PREDEC:
return PREDECcode;
case POSTINC:
return POSTINCcode;
case POSTDEC:
return POSTDECcode;
default:
return -1;
}
}
/** Construct definition of an access method. /** Construct definition of an access method.
* @param pos The source code position of the definition. * @param pos The source code position of the definition.
* @param vsym The private or protected symbol. * @param vsym The private or protected symbol.
@ -1259,8 +1297,7 @@ public class Lower extends TreeTranslator {
expr = make.Assign(ref, args.head); expr = make.Assign(ref, args.head);
break; break;
case PREINCcode: case POSTINCcode: case PREDECcode: case POSTDECcode: case PREINCcode: case POSTINCcode: case PREDECcode: case POSTDECcode:
expr = makeUnary( expr = makeUnary(mapUnaryOpCodeToTag(acode1), ref);
((acode1 - PREINCcode) >> 1) + JCTree.PREINC, ref);
break; break;
default: default:
expr = make.Assignop( expr = make.Assignop(
@ -1576,7 +1613,7 @@ public class Lower extends TreeTranslator {
} }
private JCExpression makeNonNullCheck(JCExpression expression) { private JCExpression makeNonNullCheck(JCExpression expression) {
return makeBinary(JCTree.NE, expression, makeNull()); return makeBinary(NE, expression, makeNull());
} }
/** Construct a tree that represents the outer instance /** Construct a tree that represents the outer instance
@ -1808,7 +1845,7 @@ public class Lower extends TreeTranslator {
// $newcache.getClass().getComponentType().getClassLoader() : cl$" // $newcache.getClass().getComponentType().getClassLoader() : cl$"
JCExpression clvalue = JCExpression clvalue =
make.Conditional( make.Conditional(
makeBinary(JCTree.EQ, make.Ident(clsym), makeNull()), makeBinary(EQ, make.Ident(clsym), makeNull()),
make.Assign( make.Assign(
make.Ident(clsym), make.Ident(clsym),
makeCall( makeCall(
@ -1976,7 +2013,7 @@ public class Lower extends TreeTranslator {
writer.xClassName(type).toString().replace('/', '.'); writer.xClassName(type).toString().replace('/', '.');
Symbol cs = cacheSym(pos, sig); Symbol cs = cacheSym(pos, sig);
return make_at(pos).Conditional( return make_at(pos).Conditional(
makeBinary(JCTree.EQ, make.Ident(cs), makeNull()), makeBinary(EQ, make.Ident(cs), makeNull()),
make.Assign( make.Assign(
make.Ident(cs), make.Ident(cs),
make.App( make.App(
@ -2023,7 +2060,7 @@ public class Lower extends TreeTranslator {
List.<Type>nil()); List.<Type>nil());
JCClassDecl containerDef = classDef(container); JCClassDecl containerDef = classDef(container);
make_at(containerDef.pos()); make_at(containerDef.pos());
JCExpression notStatus = makeUnary(JCTree.NOT, make.App(make.Select( JCExpression notStatus = makeUnary(NOT, make.App(make.Select(
classOfType(types.erasure(outermostClass.type), classOfType(types.erasure(outermostClass.type),
containerDef.pos()), containerDef.pos()),
desiredAssertionStatusSym))); desiredAssertionStatusSym)));
@ -2032,7 +2069,7 @@ public class Lower extends TreeTranslator {
containerDef.defs = containerDef.defs.prepend(assertDisabledDef); containerDef.defs = containerDef.defs.prepend(assertDisabledDef);
} }
make_at(pos); make_at(pos);
return makeUnary(JCTree.NOT, make.Ident(assertDisabledSym)); return makeUnary(NOT, make.Ident(assertDisabledSym));
} }
@ -2062,9 +2099,9 @@ public class Lower extends TreeTranslator {
JCTree abstractRval(JCTree rval, Type type, TreeBuilder builder) { JCTree abstractRval(JCTree rval, Type type, TreeBuilder builder) {
rval = TreeInfo.skipParens(rval); rval = TreeInfo.skipParens(rval);
switch (rval.getTag()) { switch (rval.getTag()) {
case JCTree.LITERAL: case LITERAL:
return builder.build(rval); return builder.build(rval);
case JCTree.IDENT: case IDENT:
JCIdent id = (JCIdent) rval; JCIdent id = (JCIdent) rval;
if ((id.sym.flags() & FINAL) != 0 && id.sym.owner.kind == MTH) if ((id.sym.flags() & FINAL) != 0 && id.sym.owner.kind == MTH)
return builder.build(rval); return builder.build(rval);
@ -2097,9 +2134,9 @@ public class Lower extends TreeTranslator {
JCTree abstractLval(JCTree lval, final TreeBuilder builder) { JCTree abstractLval(JCTree lval, final TreeBuilder builder) {
lval = TreeInfo.skipParens(lval); lval = TreeInfo.skipParens(lval);
switch (lval.getTag()) { switch (lval.getTag()) {
case JCTree.IDENT: case IDENT:
return builder.build(lval); return builder.build(lval);
case JCTree.SELECT: { case SELECT: {
final JCFieldAccess s = (JCFieldAccess)lval; final JCFieldAccess s = (JCFieldAccess)lval;
JCTree selected = TreeInfo.skipParens(s.selected); JCTree selected = TreeInfo.skipParens(s.selected);
Symbol lid = TreeInfo.symbol(s.selected); Symbol lid = TreeInfo.symbol(s.selected);
@ -2110,7 +2147,7 @@ public class Lower extends TreeTranslator {
} }
}); });
} }
case JCTree.INDEXED: { case INDEXED: {
final JCArrayAccess i = (JCArrayAccess)lval; final JCArrayAccess i = (JCArrayAccess)lval;
return abstractRval(i.indexed, new TreeBuilder() { return abstractRval(i.indexed, new TreeBuilder() {
public JCTree build(final JCTree indexed) { public JCTree build(final JCTree indexed) {
@ -2125,7 +2162,7 @@ public class Lower extends TreeTranslator {
} }
}); });
} }
case JCTree.TYPECAST: { case TYPECAST: {
return abstractLval(((JCTypeCast)lval).expr, builder); return abstractLval(((JCTypeCast)lval).expr, builder);
} }
} }
@ -2345,7 +2382,7 @@ public class Lower extends TreeTranslator {
for (List<JCTree> defs = tree.defs; for (List<JCTree> defs = tree.defs;
defs.nonEmpty(); defs.nonEmpty();
defs=defs.tail) { defs=defs.tail) {
if (defs.head.getTag() == JCTree.VARDEF && (((JCVariableDecl) defs.head).mods.flags & ENUM) != 0) { if (defs.head.hasTag(VARDEF) && (((JCVariableDecl) defs.head).mods.flags & ENUM) != 0) {
JCVariableDecl var = (JCVariableDecl)defs.head; JCVariableDecl var = (JCVariableDecl)defs.head;
visitEnumConstantDef(var, nextOrdinal++); visitEnumConstantDef(var, nextOrdinal++);
values.append(make.QualIdent(var.sym)); values.append(make.QualIdent(var.sym));
@ -2757,9 +2794,9 @@ public class Lower extends TreeTranslator {
List.<JCExpression>nil() : List.of(translate(tree.detail)); List.<JCExpression>nil() : List.of(translate(tree.detail));
if (!tree.cond.type.isFalse()) { if (!tree.cond.type.isFalse()) {
cond = makeBinary cond = makeBinary
(JCTree.AND, (AND,
cond, cond,
makeUnary(JCTree.NOT, tree.cond)); makeUnary(NOT, tree.cond));
} }
result = result =
make.If(cond, make.If(cond,
@ -2816,7 +2853,7 @@ public class Lower extends TreeTranslator {
// first argument. // first argument.
if (c.hasOuterInstance()) { if (c.hasOuterInstance()) {
JCExpression thisArg; JCExpression thisArg;
if (tree.meth.getTag() == JCTree.SELECT) { if (tree.meth.hasTag(SELECT)) {
thisArg = attr. thisArg = attr.
makeNullCheck(translate(((JCFieldAccess) tree.meth).selected)); makeNullCheck(translate(((JCFieldAccess) tree.meth).selected));
tree.meth = make.Ident(constructor); tree.meth = make.Ident(constructor);
@ -2837,7 +2874,7 @@ public class Lower extends TreeTranslator {
// If the translated method itself is an Apply tree, we are // If the translated method itself is an Apply tree, we are
// seeing an access method invocation. In this case, append // seeing an access method invocation. In this case, append
// the method arguments to the arguments of the access method. // the method arguments to the arguments of the access method.
if (tree.meth.getTag() == JCTree.APPLY) { if (tree.meth.hasTag(APPLY)) {
JCMethodInvocation app = (JCMethodInvocation)tree.meth; JCMethodInvocation app = (JCMethodInvocation)tree.meth;
app.args = tree.args.prependList(app.args); app.args = tree.args.prependList(app.args);
result = app; result = app;
@ -2971,7 +3008,7 @@ public class Lower extends TreeTranslator {
// If translated left hand side is an Apply, we are // If translated left hand side is an Apply, we are
// seeing an access method invocation. In this case, append // seeing an access method invocation. In this case, append
// right hand side as last argument of the access method. // right hand side as last argument of the access method.
if (tree.lhs.getTag() == JCTree.APPLY) { if (tree.lhs.hasTag(APPLY)) {
JCMethodInvocation app = (JCMethodInvocation)tree.lhs; JCMethodInvocation app = (JCMethodInvocation)tree.lhs;
app.args = List.of(tree.rhs).prependList(app.args); app.args = List.of(tree.rhs).prependList(app.args);
result = app; result = app;
@ -2988,7 +3025,7 @@ public class Lower extends TreeTranslator {
// (but without recomputing x) // (but without recomputing x)
JCTree newTree = abstractLval(tree.lhs, new TreeBuilder() { JCTree newTree = abstractLval(tree.lhs, new TreeBuilder() {
public JCTree build(final JCTree lhs) { public JCTree build(final JCTree lhs) {
int newTag = tree.getTag() - JCTree.ASGOffset; JCTree.Tag newTag = tree.getTag().noAssignOp();
// Erasure (TransTypes) can change the type of // Erasure (TransTypes) can change the type of
// tree.lhs. However, we can still get the // tree.lhs. However, we can still get the
// unerased type of tree.lhs as it is stored // unerased type of tree.lhs as it is stored
@ -3018,7 +3055,7 @@ public class Lower extends TreeTranslator {
// If translated left hand side is an Apply, we are // If translated left hand side is an Apply, we are
// seeing an access method invocation. In this case, append // seeing an access method invocation. In this case, append
// right hand side as last argument of the access method. // right hand side as last argument of the access method.
if (tree.lhs.getTag() == JCTree.APPLY) { if (tree.lhs.hasTag(APPLY)) {
JCMethodInvocation app = (JCMethodInvocation)tree.lhs; JCMethodInvocation app = (JCMethodInvocation)tree.lhs;
// if operation is a += on strings, // if operation is a += on strings,
// make sure to convert argument to string // make sure to convert argument to string
@ -3038,13 +3075,13 @@ public class Lower extends TreeTranslator {
// or // or
// translate to tmp1=lval(e); tmp2=tmp1; (typeof tree)tmp1 OP 1; tmp2 // translate to tmp1=lval(e); tmp2=tmp1; (typeof tree)tmp1 OP 1; tmp2
// where OP is += or -= // where OP is += or -=
final boolean cast = TreeInfo.skipParens(tree.arg).getTag() == JCTree.TYPECAST; final boolean cast = TreeInfo.skipParens(tree.arg).hasTag(TYPECAST);
return abstractLval(tree.arg, new TreeBuilder() { return abstractLval(tree.arg, new TreeBuilder() {
public JCTree build(final JCTree tmp1) { public JCTree build(final JCTree tmp1) {
return abstractRval(tmp1, tree.arg.type, new TreeBuilder() { return abstractRval(tmp1, tree.arg.type, new TreeBuilder() {
public JCTree build(final JCTree tmp2) { public JCTree build(final JCTree tmp2) {
int opcode = (tree.getTag() == JCTree.POSTINC) JCTree.Tag opcode = (tree.hasTag(POSTINC))
? JCTree.PLUS_ASG : JCTree.MINUS_ASG; ? PLUS_ASG : MINUS_ASG;
JCTree lhs = cast JCTree lhs = cast
? make.TypeCast(tree.arg.type, (JCExpression)tmp1) ? make.TypeCast(tree.arg.type, (JCExpression)tmp1)
: tmp1; : tmp1;
@ -3059,25 +3096,24 @@ public class Lower extends TreeTranslator {
} }
public void visitUnary(JCUnary tree) { public void visitUnary(JCUnary tree) {
boolean isUpdateOperator = boolean isUpdateOperator = tree.getTag().isIncOrDecUnaryOp();
JCTree.PREINC <= tree.getTag() && tree.getTag() <= JCTree.POSTDEC;
if (isUpdateOperator && !tree.arg.type.isPrimitive()) { if (isUpdateOperator && !tree.arg.type.isPrimitive()) {
switch(tree.getTag()) { switch(tree.getTag()) {
case JCTree.PREINC: // ++ e case PREINC: // ++ e
// translate to e += 1 // translate to e += 1
case JCTree.PREDEC: // -- e case PREDEC: // -- e
// translate to e -= 1 // translate to e -= 1
{ {
int opcode = (tree.getTag() == JCTree.PREINC) JCTree.Tag opcode = (tree.hasTag(PREINC))
? JCTree.PLUS_ASG : JCTree.MINUS_ASG; ? PLUS_ASG : MINUS_ASG;
JCAssignOp newTree = makeAssignop(opcode, JCAssignOp newTree = makeAssignop(opcode,
tree.arg, tree.arg,
make.Literal(1)); make.Literal(1));
result = translate(newTree, tree.type); result = translate(newTree, tree.type);
return; return;
} }
case JCTree.POSTINC: // e ++ case POSTINC: // e ++
case JCTree.POSTDEC: // e -- case POSTDEC: // e --
{ {
result = translate(lowerBoxedPostop(tree), tree.type); result = translate(lowerBoxedPostop(tree), tree.type);
return; return;
@ -3088,14 +3124,14 @@ public class Lower extends TreeTranslator {
tree.arg = boxIfNeeded(translate(tree.arg, tree), tree.type); tree.arg = boxIfNeeded(translate(tree.arg, tree), tree.type);
if (tree.getTag() == JCTree.NOT && tree.arg.type.constValue() != null) { if (tree.hasTag(NOT) && tree.arg.type.constValue() != null) {
tree.type = cfolder.fold1(bool_not, tree.arg.type); tree.type = cfolder.fold1(bool_not, tree.arg.type);
} }
// If translated left hand side is an Apply, we are // If translated left hand side is an Apply, we are
// seeing an access method invocation. In this case, return // seeing an access method invocation. In this case, return
// that access method invocation as result. // that access method invocation as result.
if (isUpdateOperator && tree.arg.getTag() == JCTree.APPLY) { if (isUpdateOperator && tree.arg.hasTag(APPLY)) {
result = tree.arg; result = tree.arg;
} else { } else {
result = tree; result = tree;
@ -3106,7 +3142,7 @@ public class Lower extends TreeTranslator {
List<Type> formals = tree.operator.type.getParameterTypes(); List<Type> formals = tree.operator.type.getParameterTypes();
JCTree lhs = tree.lhs = translate(tree.lhs, formals.head); JCTree lhs = tree.lhs = translate(tree.lhs, formals.head);
switch (tree.getTag()) { switch (tree.getTag()) {
case JCTree.OR: case OR:
if (lhs.type.isTrue()) { if (lhs.type.isTrue()) {
result = lhs; result = lhs;
return; return;
@ -3116,7 +3152,7 @@ public class Lower extends TreeTranslator {
return; return;
} }
break; break;
case JCTree.AND: case AND:
if (lhs.type.isFalse()) { if (lhs.type.isFalse()) {
result = lhs; result = lhs;
return; return;
@ -3186,9 +3222,9 @@ public class Lower extends TreeTranslator {
indexdef.init.type = indexdef.type = syms.intType.constType(0); indexdef.init.type = indexdef.type = syms.intType.constType(0);
List<JCStatement> loopinit = List.of(arraycachedef, lencachedef, indexdef); List<JCStatement> loopinit = List.of(arraycachedef, lencachedef, indexdef);
JCBinary cond = makeBinary(JCTree.LT, make.Ident(index), make.Ident(lencache)); JCBinary cond = makeBinary(LT, make.Ident(index), make.Ident(lencache));
JCExpressionStatement step = make.Exec(makeUnary(JCTree.PREINC, make.Ident(index))); JCExpressionStatement step = make.Exec(makeUnary(PREINC, make.Ident(index)));
Type elemtype = types.elemtype(tree.expr.type); Type elemtype = types.elemtype(tree.expr.type);
JCExpression loopvarinit = make.Indexed(make.Ident(arraycache), JCExpression loopvarinit = make.Indexed(make.Ident(arraycache),
@ -3592,7 +3628,7 @@ public class Lower extends TreeTranslator {
// need to special case-access of the form C.super.x // need to special case-access of the form C.super.x
// these will always need an access method. // these will always need an access method.
boolean qualifiedSuperAccess = boolean qualifiedSuperAccess =
tree.selected.getTag() == JCTree.SELECT && tree.selected.hasTag(SELECT) &&
TreeInfo.name(tree.selected) == names._super; TreeInfo.name(tree.selected) == names._super;
tree.selected = translate(tree.selected); tree.selected = translate(tree.selected);
if (tree.name == names._class) if (tree.name == names._class)
@ -3642,7 +3678,7 @@ public class Lower extends TreeTranslator {
endPositions = env.toplevel.endPositions; endPositions = env.toplevel.endPositions;
currentClass = null; currentClass = null;
currentMethodDef = null; currentMethodDef = null;
outermostClassDef = (cdef.getTag() == JCTree.CLASSDEF) ? (JCClassDecl)cdef : null; outermostClassDef = (cdef.hasTag(CLASSDEF)) ? (JCClassDecl)cdef : null;
outermostMemberDef = null; outermostMemberDef = null;
this.translated = new ListBuffer<JCTree>(); this.translated = new ListBuffer<JCTree>();
classdefs = new HashMap<ClassSymbol,JCClassDecl>(); classdefs = new HashMap<ClassSymbol,JCClassDecl>();
@ -3838,7 +3874,7 @@ public class Lower extends TreeTranslator {
JCIdent fLocUsageId = make.Ident(otherVarSym); JCIdent fLocUsageId = make.Ident(otherVarSym);
JCExpression sel = make.Select(fLocUsageId, ordinalSymbol); JCExpression sel = make.Select(fLocUsageId, ordinalSymbol);
JCBinary bin = makeBinary(JCTree.MINUS, id1, sel); JCBinary bin = makeBinary(MINUS, id1, sel);
JCReturn ret = make.Return(bin); JCReturn ret = make.Return(bin);
blockStatements.append(ret); blockStatements.append(ret);
JCMethodDecl compareToMethod = make.MethodDef((MethodSymbol)compareToSym, JCMethodDecl compareToMethod = make.MethodDef((MethodSymbol)compareToSym,

View file

@ -40,8 +40,10 @@ import com.sun.tools.javac.code.Symbol.*;
import com.sun.tools.javac.tree.JCTree.*; import com.sun.tools.javac.tree.JCTree.*;
import static com.sun.tools.javac.code.Flags.*; import static com.sun.tools.javac.code.Flags.*;
import static com.sun.tools.javac.code.Flags.ANNOTATION;
import static com.sun.tools.javac.code.Kinds.*; import static com.sun.tools.javac.code.Kinds.*;
import static com.sun.tools.javac.code.TypeTags.*; import static com.sun.tools.javac.code.TypeTags.*;
import static com.sun.tools.javac.tree.JCTree.Tag.*;
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
/** This is the second phase of Enter, in which classes are completed /** This is the second phase of Enter, in which classes are completed
@ -644,7 +646,7 @@ public class MemberEnter extends JCTree.Visitor implements Completer {
tree.sym = v; tree.sym = v;
if (tree.init != null) { if (tree.init != null) {
v.flags_field |= HASINIT; v.flags_field |= HASINIT;
if ((v.flags_field & FINAL) != 0 && tree.init.getTag() != JCTree.NEWCLASS) { if ((v.flags_field & FINAL) != 0 && !tree.init.hasTag(NEWCLASS)) {
Env<AttrContext> initEnv = getInitEnv(tree, env); Env<AttrContext> initEnv = getInitEnv(tree, env);
initEnv.info.enclVar = v; initEnv.info.enclVar = v;
v.setLazyConstValue(initEnv(tree, initEnv), attr, tree.init); v.setLazyConstValue(initEnv(tree, initEnv), attr, tree.init);
@ -868,7 +870,7 @@ public class MemberEnter extends JCTree.Visitor implements Completer {
// If this is a toplevel-class, make sure any preceding import // If this is a toplevel-class, make sure any preceding import
// clauses have been seen. // clauses have been seen.
if (c.owner.kind == PCK) { if (c.owner.kind == PCK) {
memberEnter(env.toplevel, env.enclosing(JCTree.TOPLEVEL)); memberEnter(env.toplevel, env.enclosing(TOPLEVEL));
todo.append(env); todo.append(env);
} }

View file

@ -49,9 +49,12 @@ import java.util.Set;
import javax.lang.model.element.ElementVisitor; import javax.lang.model.element.ElementVisitor;
import static com.sun.tools.javac.code.Flags.*; import static com.sun.tools.javac.code.Flags.*;
import static com.sun.tools.javac.code.Flags.BLOCK;
import static com.sun.tools.javac.code.Kinds.*; import static com.sun.tools.javac.code.Kinds.*;
import static com.sun.tools.javac.code.Kinds.ERRONEOUS;
import static com.sun.tools.javac.code.TypeTags.*; import static com.sun.tools.javac.code.TypeTags.*;
import static com.sun.tools.javac.comp.Resolve.MethodResolutionPhase.*; import static com.sun.tools.javac.comp.Resolve.MethodResolutionPhase.*;
import static com.sun.tools.javac.tree.JCTree.Tag.*;
/** Helper class for name resolution, used mostly by the attribution phase. /** Helper class for name resolution, used mostly by the attribution phase.
* *
@ -1269,7 +1272,7 @@ public class Resolve {
staticOnly = true; staticOnly = true;
} }
if (env.tree.getTag() != JCTree.IMPORT) { if (!env.tree.hasTag(IMPORT)) {
sym = findGlobalType(env, env.toplevel.namedImportScope, name); sym = findGlobalType(env, env.toplevel.namedImportScope, name);
if (sym.exists()) return sym; if (sym.exists()) return sym;
else if (sym.kind < bestSoFar.kind) bestSoFar = sym; else if (sym.kind < bestSoFar.kind) bestSoFar = sym;
@ -1796,7 +1799,7 @@ public class Resolve {
* @param env The environment current at the operation. * @param env The environment current at the operation.
* @param argtypes The types of the operands. * @param argtypes The types of the operands.
*/ */
Symbol resolveOperator(DiagnosticPosition pos, int optag, Symbol resolveOperator(DiagnosticPosition pos, JCTree.Tag optag,
Env<AttrContext> env, List<Type> argtypes) { Env<AttrContext> env, List<Type> argtypes) {
startResolution(); startResolution();
Name name = treeinfo.operatorName(optag); Name name = treeinfo.operatorName(optag);
@ -1815,7 +1818,7 @@ public class Resolve {
* @param env The environment current at the operation. * @param env The environment current at the operation.
* @param arg The type of the operand. * @param arg The type of the operand.
*/ */
Symbol resolveUnaryOperator(DiagnosticPosition pos, int optag, Env<AttrContext> env, Type arg) { Symbol resolveUnaryOperator(DiagnosticPosition pos, JCTree.Tag optag, Env<AttrContext> env, Type arg) {
return resolveOperator(pos, optag, env, List.of(arg)); return resolveOperator(pos, optag, env, List.of(arg));
} }
@ -1827,7 +1830,7 @@ public class Resolve {
* @param right The types of the right operand. * @param right The types of the right operand.
*/ */
Symbol resolveBinaryOperator(DiagnosticPosition pos, Symbol resolveBinaryOperator(DiagnosticPosition pos,
int optag, JCTree.Tag optag,
Env<AttrContext> env, Env<AttrContext> env,
Type left, Type left,
Type right) { Type right) {

View file

@ -532,7 +532,7 @@ implements CRTFlags {
*/ */
public int endPos(JCTree tree) { public int endPos(JCTree tree) {
if (tree == null) return Position.NOPOS; if (tree == null) return Position.NOPOS;
if (tree.getTag() == JCTree.BLOCK) if (tree.hasTag(JCTree.Tag.BLOCK))
return ((JCBlock) tree).endpos; return ((JCBlock) tree).endpos;
Integer endpos = endPositions.get(tree); Integer endpos = endPositions.get(tree);
if (endpos != null) if (endpos != null)

View file

@ -47,6 +47,8 @@ import static com.sun.tools.javac.code.TypeTags.*;
import static com.sun.tools.javac.jvm.ByteCodes.*; import static com.sun.tools.javac.jvm.ByteCodes.*;
import static com.sun.tools.javac.jvm.CRTFlags.*; import static com.sun.tools.javac.jvm.CRTFlags.*;
import static com.sun.tools.javac.main.OptionName.*; import static com.sun.tools.javac.main.OptionName.*;
import static com.sun.tools.javac.tree.JCTree.Tag.*;
import static com.sun.tools.javac.tree.JCTree.Tag.BLOCK;
/** This pass maps flat Java (i.e. without inner classes) to bytecodes. /** This pass maps flat Java (i.e. without inner classes) to bytecodes.
* *
@ -433,7 +435,7 @@ public class Gen extends JCTree.Visitor {
*/ */
boolean hasFinally(JCTree target, Env<GenContext> env) { boolean hasFinally(JCTree target, Env<GenContext> env) {
while (env.tree != target) { while (env.tree != target) {
if (env.tree.getTag() == JCTree.TRY && env.info.finalize.hasFinalizer()) if (env.tree.hasTag(TRY) && env.info.finalize.hasFinalizer())
return true; return true;
env = env.next; env = env.next;
} }
@ -460,17 +462,17 @@ public class Gen extends JCTree.Visitor {
for (List<JCTree> l = defs; l.nonEmpty(); l = l.tail) { for (List<JCTree> l = defs; l.nonEmpty(); l = l.tail) {
JCTree def = l.head; JCTree def = l.head;
switch (def.getTag()) { switch (def.getTag()) {
case JCTree.BLOCK: case BLOCK:
JCBlock block = (JCBlock)def; JCBlock block = (JCBlock)def;
if ((block.flags & STATIC) != 0) if ((block.flags & STATIC) != 0)
clinitCode.append(block); clinitCode.append(block);
else else
initCode.append(block); initCode.append(block);
break; break;
case JCTree.METHODDEF: case METHODDEF:
methodDefs.append(def); methodDefs.append(def);
break; break;
case JCTree.VARDEF: case VARDEF:
JCVariableDecl vdef = (JCVariableDecl) def; JCVariableDecl vdef = (JCVariableDecl) def;
VarSymbol sym = vdef.sym; VarSymbol sym = vdef.sym;
checkDimension(vdef.pos(), sym.type); checkDimension(vdef.pos(), sym.type);
@ -707,7 +709,7 @@ public class Gen extends JCTree.Visitor {
} }
int startpc = code.curPc(); int startpc = code.curPc();
genStat(tree, env); genStat(tree, env);
if (tree.getTag() == JCTree.BLOCK) crtFlags |= CRT_BLOCK; if (tree.hasTag(BLOCK)) crtFlags |= CRT_BLOCK;
code.crt.put(tree, crtFlags, startpc, code.curPc()); code.crt.put(tree, crtFlags, startpc, code.curPc());
} }
@ -717,7 +719,7 @@ public class Gen extends JCTree.Visitor {
if (code.isAlive()) { if (code.isAlive()) {
code.statBegin(tree.pos); code.statBegin(tree.pos);
genDef(tree, env); genDef(tree, env);
} else if (env.info.isSwitch && tree.getTag() == JCTree.VARDEF) { } else if (env.info.isSwitch && tree.hasTag(VARDEF)) {
// variables whose declarations are in a switch // variables whose declarations are in a switch
// can be used even if the decl is unreachable. // can be used even if the decl is unreachable.
code.newLocal(((JCVariableDecl) tree).sym); code.newLocal(((JCVariableDecl) tree).sym);
@ -784,7 +786,7 @@ public class Gen extends JCTree.Visitor {
*/ */
public CondItem genCond(JCTree _tree, boolean markBranches) { public CondItem genCond(JCTree _tree, boolean markBranches) {
JCTree inner_tree = TreeInfo.skipParens(_tree); JCTree inner_tree = TreeInfo.skipParens(_tree);
if (inner_tree.getTag() == JCTree.CONDEXPR) { if (inner_tree.hasTag(CONDEXPR)) {
JCConditional tree = (JCConditional)inner_tree; JCConditional tree = (JCConditional)inner_tree;
CondItem cond = genCond(tree.cond, CRT_FLOW_CONTROLLER); CondItem cond = genCond(tree.cond, CRT_FLOW_CONTROLLER);
if (cond.isTrue()) { if (cond.isTrue()) {
@ -1033,7 +1035,7 @@ public class Gen extends JCTree.Visitor {
Env<GenContext> localEnv = env.dup(tree, new GenContext()); Env<GenContext> localEnv = env.dup(tree, new GenContext());
genStats(tree.stats, localEnv); genStats(tree.stats, localEnv);
// End the scope of all block-local variables in variable info. // End the scope of all block-local variables in variable info.
if (env.tree.getTag() != JCTree.METHODDEF) { if (!env.tree.hasTag(METHODDEF)) {
code.statBegin(tree.endpos); code.statBegin(tree.endpos);
code.endScopes(limit); code.endScopes(limit);
code.pendingStatPos = Position.NOPOS; code.pendingStatPos = Position.NOPOS;
@ -1628,11 +1630,11 @@ public class Gen extends JCTree.Visitor {
// Optimize x++ to ++x and x-- to --x. // Optimize x++ to ++x and x-- to --x.
JCExpression e = tree.expr; JCExpression e = tree.expr;
switch (e.getTag()) { switch (e.getTag()) {
case JCTree.POSTINC: case POSTINC:
((JCUnary) e).setTag(JCTree.PREINC); ((JCUnary) e).setTag(PREINC);
break; break;
case JCTree.POSTDEC: case POSTDEC:
((JCUnary) e).setTag(JCTree.PREDEC); ((JCUnary) e).setTag(PREDEC);
break; break;
} }
genExpr(tree.expr, tree.expr.type).drop(); genExpr(tree.expr, tree.expr.type).drop();
@ -1819,13 +1821,13 @@ public class Gen extends JCTree.Visitor {
// If we have an increment of -32768 to +32767 of a local // If we have an increment of -32768 to +32767 of a local
// int variable we can use an incr instruction instead of // int variable we can use an incr instruction instead of
// proceeding further. // proceeding further.
if ((tree.getTag() == JCTree.PLUS_ASG || tree.getTag() == JCTree.MINUS_ASG) && if ((tree.hasTag(PLUS_ASG) || tree.hasTag(MINUS_ASG)) &&
l instanceof LocalItem && l instanceof LocalItem &&
tree.lhs.type.tag <= INT && tree.lhs.type.tag <= INT &&
tree.rhs.type.tag <= INT && tree.rhs.type.tag <= INT &&
tree.rhs.type.constValue() != null) { tree.rhs.type.constValue() != null) {
int ival = ((Number) tree.rhs.type.constValue()).intValue(); int ival = ((Number) tree.rhs.type.constValue()).intValue();
if (tree.getTag() == JCTree.MINUS_ASG) ival = -ival; if (tree.hasTag(MINUS_ASG)) ival = -ival;
((LocalItem)l).incr(ival); ((LocalItem)l).incr(ival);
result = l; result = l;
return; return;
@ -1841,29 +1843,29 @@ public class Gen extends JCTree.Visitor {
public void visitUnary(JCUnary tree) { public void visitUnary(JCUnary tree) {
OperatorSymbol operator = (OperatorSymbol)tree.operator; OperatorSymbol operator = (OperatorSymbol)tree.operator;
if (tree.getTag() == JCTree.NOT) { if (tree.hasTag(NOT)) {
CondItem od = genCond(tree.arg, false); CondItem od = genCond(tree.arg, false);
result = od.negate(); result = od.negate();
} else { } else {
Item od = genExpr(tree.arg, operator.type.getParameterTypes().head); Item od = genExpr(tree.arg, operator.type.getParameterTypes().head);
switch (tree.getTag()) { switch (tree.getTag()) {
case JCTree.POS: case POS:
result = od.load(); result = od.load();
break; break;
case JCTree.NEG: case NEG:
result = od.load(); result = od.load();
code.emitop0(operator.opcode); code.emitop0(operator.opcode);
break; break;
case JCTree.COMPL: case COMPL:
result = od.load(); result = od.load();
emitMinusOne(od.typecode); emitMinusOne(od.typecode);
code.emitop0(operator.opcode); code.emitop0(operator.opcode);
break; break;
case JCTree.PREINC: case JCTree.PREDEC: case PREINC: case PREDEC:
od.duplicate(); od.duplicate();
if (od instanceof LocalItem && if (od instanceof LocalItem &&
(operator.opcode == iadd || operator.opcode == isub)) { (operator.opcode == iadd || operator.opcode == isub)) {
((LocalItem)od).incr(tree.getTag() == JCTree.PREINC ? 1 : -1); ((LocalItem)od).incr(tree.hasTag(PREINC) ? 1 : -1);
result = od; result = od;
} else { } else {
od.load(); od.load();
@ -1877,12 +1879,12 @@ public class Gen extends JCTree.Visitor {
result = items.makeAssignItem(od); result = items.makeAssignItem(od);
} }
break; break;
case JCTree.POSTINC: case JCTree.POSTDEC: case POSTINC: case POSTDEC:
od.duplicate(); od.duplicate();
if (od instanceof LocalItem && if (od instanceof LocalItem &&
(operator.opcode == iadd || operator.opcode == isub)) { (operator.opcode == iadd || operator.opcode == isub)) {
Item res = od.load(); Item res = od.load();
((LocalItem)od).incr(tree.getTag() == JCTree.POSTINC ? 1 : -1); ((LocalItem)od).incr(tree.hasTag(POSTINC) ? 1 : -1);
result = res; result = res;
} else { } else {
Item res = od.load(); Item res = od.load();
@ -1898,7 +1900,7 @@ public class Gen extends JCTree.Visitor {
result = res; result = res;
} }
break; break;
case JCTree.NULLCHK: case NULLCHK:
result = od.load(); result = od.load();
code.emitop0(dup); code.emitop0(dup);
genNullCheck(tree.pos()); genNullCheck(tree.pos());
@ -1926,7 +1928,7 @@ public class Gen extends JCTree.Visitor {
// Convert buffer to string. // Convert buffer to string.
bufferToString(tree.pos()); bufferToString(tree.pos());
result = items.makeStackItem(syms.stringType); result = items.makeStackItem(syms.stringType);
} else if (tree.getTag() == JCTree.AND) { } else if (tree.hasTag(AND)) {
CondItem lcond = genCond(tree.lhs, CRT_FLOW_CONTROLLER); CondItem lcond = genCond(tree.lhs, CRT_FLOW_CONTROLLER);
if (!lcond.isFalse()) { if (!lcond.isFalse()) {
Chain falseJumps = lcond.jumpFalse(); Chain falseJumps = lcond.jumpFalse();
@ -1940,7 +1942,7 @@ public class Gen extends JCTree.Visitor {
} else { } else {
result = lcond; result = lcond;
} }
} else if (tree.getTag() == JCTree.OR) { } else if (tree.hasTag(OR)) {
CondItem lcond = genCond(tree.lhs, CRT_FLOW_CONTROLLER); CondItem lcond = genCond(tree.lhs, CRT_FLOW_CONTROLLER);
if (!lcond.isTrue()) { if (!lcond.isTrue()) {
Chain trueJumps = lcond.jumpTrue(); Chain trueJumps = lcond.jumpTrue();
@ -1997,7 +1999,7 @@ public class Gen extends JCTree.Visitor {
*/ */
void appendStrings(JCTree tree) { void appendStrings(JCTree tree) {
tree = TreeInfo.skipParens(tree); tree = TreeInfo.skipParens(tree);
if (tree.getTag() == JCTree.PLUS && tree.type.constValue() == null) { if (tree.hasTag(PLUS) && tree.type.constValue() == null) {
JCBinary op = (JCBinary) tree; JCBinary op = (JCBinary) tree;
if (op.operator.kind == MTH && if (op.operator.kind == MTH &&
((OperatorSymbol) op.operator).opcode == string_add) { ((OperatorSymbol) op.operator).opcode == string_add) {
@ -2240,7 +2242,7 @@ public class Gen extends JCTree.Visitor {
if (nerrs != 0) { if (nerrs != 0) {
// if errors, discard code // if errors, discard code
for (List<JCTree> l = cdef.defs; l.nonEmpty(); l = l.tail) { for (List<JCTree> l = cdef.defs; l.nonEmpty(); l = l.tail) {
if (l.head.getTag() == JCTree.METHODDEF) if (l.head.hasTag(METHODDEF))
((JCMethodDecl) l.head).sym.code = null; ((JCMethodDecl) l.head).sym.code = null;
} }
} }

View file

@ -1506,20 +1506,20 @@ public class JavaCompiler implements ClassReader.SourceCompleter {
for (List<JCTree> it = tree.defs; it.tail != null; it = it.tail) { for (List<JCTree> it = tree.defs; it.tail != null; it = it.tail) {
JCTree t = it.head; JCTree t = it.head;
switch (t.getTag()) { switch (t.getTag()) {
case JCTree.CLASSDEF: case CLASSDEF:
if (isInterface || if (isInterface ||
(((JCClassDecl) t).mods.flags & (Flags.PROTECTED|Flags.PUBLIC)) != 0 || (((JCClassDecl) t).mods.flags & (Flags.PROTECTED|Flags.PUBLIC)) != 0 ||
(((JCClassDecl) t).mods.flags & (Flags.PRIVATE)) == 0 && ((JCClassDecl) t).sym.packge().getQualifiedName() == names.java_lang) (((JCClassDecl) t).mods.flags & (Flags.PRIVATE)) == 0 && ((JCClassDecl) t).sym.packge().getQualifiedName() == names.java_lang)
newdefs.append(t); newdefs.append(t);
break; break;
case JCTree.METHODDEF: case METHODDEF:
if (isInterface || if (isInterface ||
(((JCMethodDecl) t).mods.flags & (Flags.PROTECTED|Flags.PUBLIC)) != 0 || (((JCMethodDecl) t).mods.flags & (Flags.PROTECTED|Flags.PUBLIC)) != 0 ||
((JCMethodDecl) t).sym.name == names.init || ((JCMethodDecl) t).sym.name == names.init ||
(((JCMethodDecl) t).mods.flags & (Flags.PRIVATE)) == 0 && ((JCMethodDecl) t).sym.packge().getQualifiedName() == names.java_lang) (((JCMethodDecl) t).mods.flags & (Flags.PRIVATE)) == 0 && ((JCMethodDecl) t).sym.packge().getQualifiedName() == names.java_lang)
newdefs.append(t); newdefs.append(t);
break; break;
case JCTree.VARDEF: case VARDEF:
if (isInterface || (((JCVariableDecl) t).mods.flags & (Flags.PROTECTED|Flags.PUBLIC)) != 0 || if (isInterface || (((JCVariableDecl) t).mods.flags & (Flags.PROTECTED|Flags.PUBLIC)) != 0 ||
(((JCVariableDecl) t).mods.flags & (Flags.PRIVATE)) == 0 && ((JCVariableDecl) t).sym.packge().getQualifiedName() == names.java_lang) (((JCVariableDecl) t).mods.flags & (Flags.PRIVATE)) == 0 && ((JCVariableDecl) t).sym.packge().getQualifiedName() == names.java_lang)
newdefs.append(t); newdefs.append(t);

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -48,6 +48,7 @@ import com.sun.tools.javac.tree.TreeScanner;
import com.sun.tools.javac.util.*; import com.sun.tools.javac.util.*;
import com.sun.tools.javac.util.Name; import com.sun.tools.javac.util.Name;
import static com.sun.tools.javac.tree.JCTree.Tag.*;
import static javax.lang.model.util.ElementFilter.methodsIn; import static javax.lang.model.util.ElementFilter.methodsIn;
/** /**
@ -288,7 +289,7 @@ public class JavacElements implements Elements {
} }
} }
public void visitArray(Attribute.Array array) { public void visitArray(Attribute.Array array) {
if (tree.getTag() == JCTree.NEWARRAY && if (tree.hasTag(NEWARRAY) &&
types.elemtype(array.type).tsym == findme.type.tsym) { types.elemtype(array.type).tsym == findme.type.tsym) {
List<JCExpression> elems = ((JCNewArray) tree).elems; List<JCExpression> elems = ((JCNewArray) tree).elems;
for (Attribute value : array.values) { for (Attribute value : array.values) {
@ -327,7 +328,7 @@ public class JavacElements implements Elements {
scan(t.args); scan(t.args);
} }
public void visitAssign(JCAssign t) { public void visitAssign(JCAssign t) {
if (t.lhs.getTag() == JCTree.IDENT) { if (t.lhs.hasTag(IDENT)) {
JCIdent ident = (JCIdent) t.lhs; JCIdent ident = (JCIdent) t.lhs;
if (ident.sym == sym) if (ident.sym == sym)
result = t.rhs; result = t.rhs;

View file

@ -37,8 +37,16 @@ import com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag;
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
import com.sun.tools.javac.util.List; import com.sun.tools.javac.util.List;
import static com.sun.tools.javac.util.ListBuffer.lb;
import static com.sun.tools.javac.parser.Tokens.TokenKind.*; import static com.sun.tools.javac.parser.Tokens.TokenKind.*;
import static com.sun.tools.javac.parser.Tokens.TokenKind.ASSERT;
import static com.sun.tools.javac.parser.Tokens.TokenKind.CASE;
import static com.sun.tools.javac.parser.Tokens.TokenKind.CATCH;
import static com.sun.tools.javac.parser.Tokens.TokenKind.EQ;
import static com.sun.tools.javac.parser.Tokens.TokenKind.GT;
import static com.sun.tools.javac.parser.Tokens.TokenKind.IMPORT;
import static com.sun.tools.javac.parser.Tokens.TokenKind.LT;
import static com.sun.tools.javac.util.ListBuffer.lb;
import static com.sun.tools.javac.tree.JCTree.Tag.*;
/** The parser maps a token sequence into an abstract syntax /** The parser maps a token sequence into an abstract syntax
* tree. It operates by recursive descent, with code derived * tree. It operates by recursive descent, with code derived
@ -758,7 +766,7 @@ public class JavacParser implements Parser {
Assert.check(top == 0); Assert.check(top == 0);
t = odStack[0]; t = odStack[0];
if (t.getTag() == JCTree.PLUS) { if (t.hasTag(JCTree.Tag.PLUS)) {
StringBuffer buf = foldStrings(t); StringBuffer buf = foldStrings(t);
if (buf != null) { if (buf != null) {
t = toP(F.at(startPos).Literal(TypeTags.CLASS, buf.toString())); t = toP(F.at(startPos).Literal(TypeTags.CLASS, buf.toString()));
@ -791,7 +799,7 @@ public class JavacParser implements Parser {
return null; return null;
List<String> buf = List.nil(); List<String> buf = List.nil();
while (true) { while (true) {
if (tree.getTag() == JCTree.LITERAL) { if (tree.hasTag(LITERAL)) {
JCLiteral lit = (JCLiteral) tree; JCLiteral lit = (JCLiteral) tree;
if (lit.typetag == TypeTags.CLASS) { if (lit.typetag == TypeTags.CLASS) {
StringBuffer sbuf = StringBuffer sbuf =
@ -802,9 +810,9 @@ public class JavacParser implements Parser {
} }
return sbuf; return sbuf;
} }
} else if (tree.getTag() == JCTree.PLUS) { } else if (tree.hasTag(JCTree.Tag.PLUS)) {
JCBinary op = (JCBinary)tree; JCBinary op = (JCBinary)tree;
if (op.rhs.getTag() == JCTree.LITERAL) { if (op.rhs.hasTag(LITERAL)) {
JCLiteral lit = (JCLiteral) op.rhs; JCLiteral lit = (JCLiteral) op.rhs;
if (lit.typetag == TypeTags.CLASS) { if (lit.typetag == TypeTags.CLASS) {
buf = buf.prepend((String) lit.value); buf = buf.prepend((String) lit.value);
@ -900,7 +908,7 @@ public class JavacParser implements Parser {
t = term3(); t = term3();
if ((mode & TYPE) != 0 && token.kind == LT) { if ((mode & TYPE) != 0 && token.kind == LT) {
// Could be a cast to a parameterized type // Could be a cast to a parameterized type
int op = JCTree.LT; JCTree.Tag op = JCTree.Tag.LT;
int pos1 = token.pos; int pos1 = token.pos;
nextToken(); nextToken();
mode &= (EXPR | TYPE); mode &= (EXPR | TYPE);
@ -1154,7 +1162,7 @@ public class JavacParser implements Parser {
while ((token.kind == PLUSPLUS || token.kind == SUBSUB) && (mode & EXPR) != 0) { while ((token.kind == PLUSPLUS || token.kind == SUBSUB) && (mode & EXPR) != 0) {
mode = EXPR; mode = EXPR;
t = to(F.at(token.pos).Unary( t = to(F.at(token.pos).Unary(
token.kind == PLUSPLUS ? JCTree.POSTINC : JCTree.POSTDEC, t)); token.kind == PLUSPLUS ? POSTINC : POSTDEC, t));
nextToken(); nextToken();
} }
return toP(t); return toP(t);
@ -1627,7 +1635,7 @@ public class JavacParser implements Parser {
default: default:
Token prevToken = token; Token prevToken = token;
JCExpression t = term(EXPR | TYPE); JCExpression t = term(EXPR | TYPE);
if (token.kind == COLON && t.getTag() == JCTree.IDENT) { if (token.kind == COLON && t.hasTag(IDENT)) {
nextToken(); nextToken();
JCStatement stat = parseStatement(); JCStatement stat = parseStatement();
stats.append(F.at(pos).Labelled(prevToken.name(), stat)); stats.append(F.at(pos).Labelled(prevToken.name(), stat));
@ -1702,7 +1710,7 @@ public class JavacParser implements Parser {
accept(LPAREN); accept(LPAREN);
List<JCStatement> inits = token.kind == SEMI ? List.<JCStatement>nil() : forInit(); List<JCStatement> inits = token.kind == SEMI ? List.<JCStatement>nil() : forInit();
if (inits.length() == 1 && if (inits.length() == 1 &&
inits.head.getTag() == JCTree.VARDEF && inits.head.hasTag(VARDEF) &&
((JCVariableDecl) inits.head).init == null && ((JCVariableDecl) inits.head).init == null &&
token.kind == COLON) { token.kind == COLON) {
checkForeach(); checkForeach();
@ -1835,7 +1843,7 @@ public class JavacParser implements Parser {
default: default:
Token prevToken = token; Token prevToken = token;
JCExpression expr = parseExpression(); JCExpression expr = parseExpression();
if (token.kind == COLON && expr.getTag() == JCTree.IDENT) { if (token.kind == COLON && expr.hasTag(IDENT)) {
nextToken(); nextToken();
JCStatement stat = parseStatement(); JCStatement stat = parseStatement();
return F.at(pos).Labelled(prevToken.name(), stat); return F.at(pos).Labelled(prevToken.name(), stat);
@ -2088,7 +2096,7 @@ public class JavacParser implements Parser {
if (token.kind == IDENTIFIER) { if (token.kind == IDENTIFIER) {
mode = EXPR; mode = EXPR;
JCExpression t1 = term1(); JCExpression t1 = term1();
if (t1.getTag() == JCTree.IDENT && token.kind == EQ) { if (t1.hasTag(IDENT) && token.kind == EQ) {
int pos = token.pos; int pos = token.pos;
accept(EQ); accept(EQ);
JCExpression v = annotationValue(); JCExpression v = annotationValue();
@ -2618,7 +2626,7 @@ public class JavacParser implements Parser {
} else { } else {
type = parseType(); type = parseType();
} }
if (token.kind == LPAREN && !isInterface && type.getTag() == JCTree.IDENT) { if (token.kind == LPAREN && !isInterface && type.hasTag(IDENT)) {
if (isInterface || tk.name() != className) if (isInterface || tk.name() != className)
error(pos, "invalid.meth.decl.ret.type.req"); error(pos, "invalid.meth.decl.ret.type.req");
return List.of(methodDeclaratorRest( return List.of(methodDeclaratorRest(
@ -2815,15 +2823,15 @@ public class JavacParser implements Parser {
*/ */
protected JCExpression checkExprStat(JCExpression t) { protected JCExpression checkExprStat(JCExpression t) {
switch(t.getTag()) { switch(t.getTag()) {
case JCTree.PREINC: case JCTree.PREDEC: case PREINC: case PREDEC:
case JCTree.POSTINC: case JCTree.POSTDEC: case POSTINC: case POSTDEC:
case JCTree.ASSIGN: case ASSIGN:
case JCTree.BITOR_ASG: case JCTree.BITXOR_ASG: case JCTree.BITAND_ASG: case BITOR_ASG: case BITXOR_ASG: case BITAND_ASG:
case JCTree.SL_ASG: case JCTree.SR_ASG: case JCTree.USR_ASG: case SL_ASG: case SR_ASG: case USR_ASG:
case JCTree.PLUS_ASG: case JCTree.MINUS_ASG: case PLUS_ASG: case MINUS_ASG:
case JCTree.MUL_ASG: case JCTree.DIV_ASG: case JCTree.MOD_ASG: case MUL_ASG: case DIV_ASG: case MOD_ASG:
case JCTree.APPLY: case JCTree.NEWCLASS: case APPLY: case NEWCLASS:
case JCTree.ERRONEOUS: case ERRONEOUS:
return t; return t;
default: default:
JCExpression ret = F.at(t.pos).Erroneous(List.<JCTree>of(t)); JCExpression ret = F.at(t.pos).Erroneous(List.<JCTree>of(t));
@ -2836,8 +2844,8 @@ public class JavacParser implements Parser {
* -1 if token is not a binary operator. @see TreeInfo.opPrec * -1 if token is not a binary operator. @see TreeInfo.opPrec
*/ */
static int prec(TokenKind token) { static int prec(TokenKind token) {
int oc = optag(token); JCTree.Tag oc = optag(token);
return (oc >= 0) ? TreeInfo.opPrec(oc) : -1; return (oc != NO_TAG) ? TreeInfo.opPrec(oc) : -1;
} }
/** /**
@ -2853,96 +2861,96 @@ public class JavacParser implements Parser {
} }
/** Return operation tag of binary operator represented by token, /** Return operation tag of binary operator represented by token,
* -1 if token is not a binary operator. * No_TAG if token is not a binary operator.
*/ */
static int optag(TokenKind token) { static JCTree.Tag optag(TokenKind token) {
switch (token) { switch (token) {
case BARBAR: case BARBAR:
return JCTree.OR; return OR;
case AMPAMP: case AMPAMP:
return JCTree.AND; return AND;
case BAR: case BAR:
return JCTree.BITOR; return BITOR;
case BAREQ: case BAREQ:
return JCTree.BITOR_ASG; return BITOR_ASG;
case CARET: case CARET:
return JCTree.BITXOR; return BITXOR;
case CARETEQ: case CARETEQ:
return JCTree.BITXOR_ASG; return BITXOR_ASG;
case AMP: case AMP:
return JCTree.BITAND; return BITAND;
case AMPEQ: case AMPEQ:
return JCTree.BITAND_ASG; return BITAND_ASG;
case EQEQ: case EQEQ:
return JCTree.EQ; return JCTree.Tag.EQ;
case BANGEQ: case BANGEQ:
return JCTree.NE; return NE;
case LT: case LT:
return JCTree.LT; return JCTree.Tag.LT;
case GT: case GT:
return JCTree.GT; return JCTree.Tag.GT;
case LTEQ: case LTEQ:
return JCTree.LE; return LE;
case GTEQ: case GTEQ:
return JCTree.GE; return GE;
case LTLT: case LTLT:
return JCTree.SL; return SL;
case LTLTEQ: case LTLTEQ:
return JCTree.SL_ASG; return SL_ASG;
case GTGT: case GTGT:
return JCTree.SR; return SR;
case GTGTEQ: case GTGTEQ:
return JCTree.SR_ASG; return SR_ASG;
case GTGTGT: case GTGTGT:
return JCTree.USR; return USR;
case GTGTGTEQ: case GTGTGTEQ:
return JCTree.USR_ASG; return USR_ASG;
case PLUS: case PLUS:
return JCTree.PLUS; return JCTree.Tag.PLUS;
case PLUSEQ: case PLUSEQ:
return JCTree.PLUS_ASG; return PLUS_ASG;
case SUB: case SUB:
return JCTree.MINUS; return MINUS;
case SUBEQ: case SUBEQ:
return JCTree.MINUS_ASG; return MINUS_ASG;
case STAR: case STAR:
return JCTree.MUL; return MUL;
case STAREQ: case STAREQ:
return JCTree.MUL_ASG; return MUL_ASG;
case SLASH: case SLASH:
return JCTree.DIV; return DIV;
case SLASHEQ: case SLASHEQ:
return JCTree.DIV_ASG; return DIV_ASG;
case PERCENT: case PERCENT:
return JCTree.MOD; return MOD;
case PERCENTEQ: case PERCENTEQ:
return JCTree.MOD_ASG; return MOD_ASG;
case INSTANCEOF: case INSTANCEOF:
return JCTree.TYPETEST; return TYPETEST;
default: default:
return -1; return NO_TAG;
} }
} }
/** Return operation tag of unary operator represented by token, /** Return operation tag of unary operator represented by token,
* -1 if token is not a binary operator. * No_TAG if token is not a binary operator.
*/ */
static int unoptag(TokenKind token) { static JCTree.Tag unoptag(TokenKind token) {
switch (token) { switch (token) {
case PLUS: case PLUS:
return JCTree.POS; return POS;
case SUB: case SUB:
return JCTree.NEG; return NEG;
case BANG: case BANG:
return JCTree.NOT; return NOT;
case TILDE: case TILDE:
return JCTree.COMPL; return COMPL;
case PLUSPLUS: case PLUSPLUS:
return JCTree.PREINC; return PREINC;
case SUBSUB: case SUBSUB:
return JCTree.PREDEC; return PREDEC;
default: default:
return -1; return NO_TAG;
} }
} }

View file

@ -1222,7 +1222,7 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
List<ClassSymbol> classes = List.nil(); List<ClassSymbol> classes = List.nil();
for (JCCompilationUnit unit : units) { for (JCCompilationUnit unit : units) {
for (JCTree node : unit.defs) { for (JCTree node : unit.defs) {
if (node.getTag() == JCTree.CLASSDEF) { if (node.hasTag(JCTree.Tag.CLASSDEF)) {
ClassSymbol sym = ((JCClassDecl) node).sym; ClassSymbol sym = ((JCClassDecl) node).sym;
Assert.checkNonNull(sym); Assert.checkNonNull(sym);
classes = classes.prepend(sym); classes = classes.prepend(sym);

View file

@ -42,6 +42,7 @@ import com.sun.tools.javac.code.Symbol.*;
import com.sun.source.tree.*; import com.sun.source.tree.*;
import static com.sun.tools.javac.code.BoundKind.*; import static com.sun.tools.javac.code.BoundKind.*;
import static com.sun.tools.javac.tree.JCTree.Tag.*;
/** /**
* Root class for abstract syntax tree nodes. It provides definitions * Root class for abstract syntax tree nodes. It provides definitions
@ -79,253 +80,289 @@ import static com.sun.tools.javac.code.BoundKind.*;
public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition { public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
/* Tree tag values, identifying kinds of trees */ /* Tree tag values, identifying kinds of trees */
public enum Tag{
/** For methods that return an invalid tag if a given condition is not met
*/
NO_TAG,
/** Toplevel nodes, of type TopLevel, representing entire source files. /** Toplevel nodes, of type TopLevel, representing entire source files.
*/ */
public static final int TOPLEVEL = 1; TOPLEVEL,
/** Import clauses, of type Import. /** Import clauses, of type Import.
*/ */
public static final int IMPORT = TOPLEVEL + 1; IMPORT,
/** Class definitions, of type ClassDef. /** Class definitions, of type ClassDef.
*/ */
public static final int CLASSDEF = IMPORT + 1; CLASSDEF,
/** Method definitions, of type MethodDef. /** Method definitions, of type MethodDef.
*/ */
public static final int METHODDEF = CLASSDEF + 1; METHODDEF,
/** Variable definitions, of type VarDef. /** Variable definitions, of type VarDef.
*/ */
public static final int VARDEF = METHODDEF + 1; VARDEF,
/** The no-op statement ";", of type Skip /** The no-op statement ";", of type Skip
*/ */
public static final int SKIP = VARDEF + 1; SKIP,
/** Blocks, of type Block. /** Blocks, of type Block.
*/ */
public static final int BLOCK = SKIP + 1; BLOCK,
/** Do-while loops, of type DoLoop. /** Do-while loops, of type DoLoop.
*/ */
public static final int DOLOOP = BLOCK + 1; DOLOOP,
/** While-loops, of type WhileLoop. /** While-loops, of type WhileLoop.
*/ */
public static final int WHILELOOP = DOLOOP + 1; WHILELOOP,
/** For-loops, of type ForLoop. /** For-loops, of type ForLoop.
*/ */
public static final int FORLOOP = WHILELOOP + 1; FORLOOP,
/** Foreach-loops, of type ForeachLoop. /** Foreach-loops, of type ForeachLoop.
*/ */
public static final int FOREACHLOOP = FORLOOP + 1; FOREACHLOOP,
/** Labelled statements, of type Labelled. /** Labelled statements, of type Labelled.
*/ */
public static final int LABELLED = FOREACHLOOP + 1; LABELLED,
/** Switch statements, of type Switch. /** Switch statements, of type Switch.
*/ */
public static final int SWITCH = LABELLED + 1; SWITCH,
/** Case parts in switch statements, of type Case. /** Case parts in switch statements, of type Case.
*/ */
public static final int CASE = SWITCH + 1; CASE,
/** Synchronized statements, of type Synchonized. /** Synchronized statements, of type Synchonized.
*/ */
public static final int SYNCHRONIZED = CASE + 1; SYNCHRONIZED,
/** Try statements, of type Try. /** Try statements, of type Try.
*/ */
public static final int TRY = SYNCHRONIZED + 1; TRY,
/** Catch clauses in try statements, of type Catch. /** Catch clauses in try statements, of type Catch.
*/ */
public static final int CATCH = TRY + 1; CATCH,
/** Conditional expressions, of type Conditional. /** Conditional expressions, of type Conditional.
*/ */
public static final int CONDEXPR = CATCH + 1; CONDEXPR,
/** Conditional statements, of type If. /** Conditional statements, of type If.
*/ */
public static final int IF = CONDEXPR + 1; IF,
/** Expression statements, of type Exec. /** Expression statements, of type Exec.
*/ */
public static final int EXEC = IF + 1; EXEC,
/** Break statements, of type Break. /** Break statements, of type Break.
*/ */
public static final int BREAK = EXEC + 1; BREAK,
/** Continue statements, of type Continue. /** Continue statements, of type Continue.
*/ */
public static final int CONTINUE = BREAK + 1; CONTINUE,
/** Return statements, of type Return. /** Return statements, of type Return.
*/ */
public static final int RETURN = CONTINUE + 1; RETURN,
/** Throw statements, of type Throw. /** Throw statements, of type Throw.
*/ */
public static final int THROW = RETURN + 1; THROW,
/** Assert statements, of type Assert. /** Assert statements, of type Assert.
*/ */
public static final int ASSERT = THROW + 1; ASSERT,
/** Method invocation expressions, of type Apply. /** Method invocation expressions, of type Apply.
*/ */
public static final int APPLY = ASSERT + 1; APPLY,
/** Class instance creation expressions, of type NewClass. /** Class instance creation expressions, of type NewClass.
*/ */
public static final int NEWCLASS = APPLY + 1; NEWCLASS,
/** Array creation expressions, of type NewArray. /** Array creation expressions, of type NewArray.
*/ */
public static final int NEWARRAY = NEWCLASS + 1; NEWARRAY,
/** Parenthesized subexpressions, of type Parens. /** Parenthesized subexpressions, of type Parens.
*/ */
public static final int PARENS = NEWARRAY + 1; PARENS,
/** Assignment expressions, of type Assign. /** Assignment expressions, of type Assign.
*/ */
public static final int ASSIGN = PARENS + 1; ASSIGN,
/** Type cast expressions, of type TypeCast. /** Type cast expressions, of type TypeCast.
*/ */
public static final int TYPECAST = ASSIGN + 1; TYPECAST,
/** Type test expressions, of type TypeTest. /** Type test expressions, of type TypeTest.
*/ */
public static final int TYPETEST = TYPECAST + 1; TYPETEST,
/** Indexed array expressions, of type Indexed. /** Indexed array expressions, of type Indexed.
*/ */
public static final int INDEXED = TYPETEST + 1; INDEXED,
/** Selections, of type Select. /** Selections, of type Select.
*/ */
public static final int SELECT = INDEXED + 1; SELECT,
/** Simple identifiers, of type Ident. /** Simple identifiers, of type Ident.
*/ */
public static final int IDENT = SELECT + 1; IDENT,
/** Literals, of type Literal. /** Literals, of type Literal.
*/ */
public static final int LITERAL = IDENT + 1; LITERAL,
/** Basic type identifiers, of type TypeIdent. /** Basic type identifiers, of type TypeIdent.
*/ */
public static final int TYPEIDENT = LITERAL + 1; TYPEIDENT,
/** Array types, of type TypeArray. /** Array types, of type TypeArray.
*/ */
public static final int TYPEARRAY = TYPEIDENT + 1; TYPEARRAY,
/** Parameterized types, of type TypeApply. /** Parameterized types, of type TypeApply.
*/ */
public static final int TYPEAPPLY = TYPEARRAY + 1; TYPEAPPLY,
/** Union types, of type TypeUnion /** Union types, of type TypeUnion
*/ */
public static final int TYPEUNION = TYPEAPPLY + 1; TYPEUNION,
/** Formal type parameters, of type TypeParameter. /** Formal type parameters, of type TypeParameter.
*/ */
public static final int TYPEPARAMETER = TYPEUNION + 1; TYPEPARAMETER,
/** Type argument. /** Type argument.
*/ */
public static final int WILDCARD = TYPEPARAMETER + 1; WILDCARD,
/** Bound kind: extends, super, exact, or unbound /** Bound kind: extends, super, exact, or unbound
*/ */
public static final int TYPEBOUNDKIND = WILDCARD + 1; TYPEBOUNDKIND,
/** metadata: Annotation. /** metadata: Annotation.
*/ */
public static final int ANNOTATION = TYPEBOUNDKIND + 1; ANNOTATION,
/** metadata: Modifiers /** metadata: Modifiers
*/ */
public static final int MODIFIERS = ANNOTATION + 1; MODIFIERS,
public static final int ANNOTATED_TYPE = MODIFIERS + 1; ANNOTATED_TYPE,
/** Error trees, of type Erroneous. /** Error trees, of type Erroneous.
*/ */
public static final int ERRONEOUS = ANNOTATED_TYPE + 1; ERRONEOUS,
/** Unary operators, of type Unary. /** Unary operators, of type Unary.
*/ */
public static final int POS = ERRONEOUS + 1; // + POS, // +
public static final int NEG = POS + 1; // - NEG, // -
public static final int NOT = NEG + 1; // ! NOT, // !
public static final int COMPL = NOT + 1; // ~ COMPL, // ~
public static final int PREINC = COMPL + 1; // ++ _ PREINC, // ++ _
public static final int PREDEC = PREINC + 1; // -- _ PREDEC, // -- _
public static final int POSTINC = PREDEC + 1; // _ ++ POSTINC, // _ ++
public static final int POSTDEC = POSTINC + 1; // _ -- POSTDEC, // _ --
/** unary operator for null reference checks, only used internally. /** unary operator for null reference checks, only used internally.
*/ */
public static final int NULLCHK = POSTDEC + 1; NULLCHK,
/** Binary operators, of type Binary. /** Binary operators, of type Binary.
*/ */
public static final int OR = NULLCHK + 1; // || OR, // ||
public static final int AND = OR + 1; // && AND, // &&
public static final int BITOR = AND + 1; // | BITOR, // |
public static final int BITXOR = BITOR + 1; // ^ BITXOR, // ^
public static final int BITAND = BITXOR + 1; // & BITAND, // &
public static final int EQ = BITAND + 1; // == EQ, // ==
public static final int NE = EQ + 1; // != NE, // !=
public static final int LT = NE + 1; // < LT, // <
public static final int GT = LT + 1; // > GT, // >
public static final int LE = GT + 1; // <= LE, // <=
public static final int GE = LE + 1; // >= GE, // >=
public static final int SL = GE + 1; // << SL, // <<
public static final int SR = SL + 1; // >> SR, // >>
public static final int USR = SR + 1; // >>> USR, // >>>
public static final int PLUS = USR + 1; // + PLUS, // +
public static final int MINUS = PLUS + 1; // - MINUS, // -
public static final int MUL = MINUS + 1; // * MUL, // *
public static final int DIV = MUL + 1; // / DIV, // /
public static final int MOD = DIV + 1; // % MOD, // %
/** Assignment operators, of type Assignop. /** Assignment operators, of type Assignop.
*/ */
public static final int BITOR_ASG = MOD + 1; // |= BITOR_ASG(BITOR), // |=
public static final int BITXOR_ASG = BITOR_ASG + 1; // ^= BITXOR_ASG(BITXOR), // ^=
public static final int BITAND_ASG = BITXOR_ASG + 1; // &= BITAND_ASG(BITAND), // &=
public static final int SL_ASG = SL + BITOR_ASG - BITOR; // <<= SL_ASG(SL), // <<=
public static final int SR_ASG = SL_ASG + 1; // >>= SR_ASG(SR), // >>=
public static final int USR_ASG = SR_ASG + 1; // >>>= USR_ASG(USR), // >>>=
public static final int PLUS_ASG = USR_ASG + 1; // += PLUS_ASG(PLUS), // +=
public static final int MINUS_ASG = PLUS_ASG + 1; // -= MINUS_ASG(MINUS), // -=
public static final int MUL_ASG = MINUS_ASG + 1; // *= MUL_ASG(MUL), // *=
public static final int DIV_ASG = MUL_ASG + 1; // /= DIV_ASG(DIV), // /=
public static final int MOD_ASG = DIV_ASG + 1; // %= MOD_ASG(MOD), // %=
/** A synthetic let expression, of type LetExpr. /** A synthetic let expression, of type LetExpr.
*/ */
public static final int LETEXPR = MOD_ASG + 1; // ala scheme LETEXPR; // ala scheme
private Tag noAssignTag;
/** The offset between assignment operators and normal operators. private static int numberOfOperators = MOD.ordinal() - POS.ordinal() + 1;
*/
public static final int ASGOffset = BITOR_ASG - BITOR; private Tag(Tag noAssignTag) {
this.noAssignTag = noAssignTag;
}
private Tag() { }
public static int getNumberOfOperators() {
return numberOfOperators;
}
public Tag noAssignOp() {
if (noAssignTag != null)
return noAssignTag;
throw new AssertionError("noAssignOp() method is not available for non assignment tags");
}
public boolean isPostUnaryOp() {
return (this == POSTINC || this == POSTDEC);
}
public boolean isIncOrDecUnaryOp() {
return (this == PREINC || this == PREDEC || this == POSTINC || this == POSTDEC);
}
public boolean isAssignop() {
return noAssignTag != null;
}
public int operatorIndex() {
return (this.ordinal() - POS.ordinal());
}
}
/* The (encoded) position in the source file. @see util.Position. /* The (encoded) position in the source file. @see util.Position.
*/ */
@ -337,7 +374,13 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
/* The tag of this node -- one of the constants declared above. /* The tag of this node -- one of the constants declared above.
*/ */
public abstract int getTag(); public abstract Tag getTag();
/* Returns true if the tag of this node is equals to tag.
*/
public boolean hasTag(Tag tag) {
return tag == getTag();
}
/** Convert a tree to a pretty-printed string. */ /** Convert a tree to a pretty-printed string. */
@Override @Override
@ -464,10 +507,9 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
public List<JCImport> getImports() { public List<JCImport> getImports() {
ListBuffer<JCImport> imports = new ListBuffer<JCImport>(); ListBuffer<JCImport> imports = new ListBuffer<JCImport>();
for (JCTree tree : defs) { for (JCTree tree : defs) {
int tag = tree.getTag(); if (tree.hasTag(IMPORT))
if (tag == IMPORT)
imports.append((JCImport)tree); imports.append((JCImport)tree);
else if (tag != SKIP) else if (!tree.hasTag(SKIP))
break; break;
} }
return imports.toList(); return imports.toList();
@ -482,7 +524,7 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
public List<JCTree> getTypeDecls() { public List<JCTree> getTypeDecls() {
List<JCTree> typeDefs; List<JCTree> typeDefs;
for (typeDefs = defs; !typeDefs.isEmpty(); typeDefs = typeDefs.tail) for (typeDefs = defs; !typeDefs.isEmpty(); typeDefs = typeDefs.tail)
if (typeDefs.head.getTag() != IMPORT) if (!typeDefs.head.hasTag(IMPORT))
break; break;
return typeDefs; return typeDefs;
} }
@ -492,7 +534,7 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
} }
@Override @Override
public int getTag() { public Tag getTag() {
return TOPLEVEL; return TOPLEVEL;
} }
} }
@ -521,7 +563,7 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
} }
@Override @Override
public int getTag() { public Tag getTag() {
return IMPORT; return IMPORT;
} }
} }
@ -618,7 +660,7 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
} }
@Override @Override
public int getTag() { public Tag getTag() {
return CLASSDEF; return CLASSDEF;
} }
} }
@ -690,7 +732,7 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
} }
@Override @Override
public int getTag() { public Tag getTag() {
return METHODDEF; return METHODDEF;
} }
} }
@ -736,7 +778,7 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
} }
@Override @Override
public int getTag() { public Tag getTag() {
return VARDEF; return VARDEF;
} }
} }
@ -757,7 +799,7 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
} }
@Override @Override
public int getTag() { public Tag getTag() {
return SKIP; return SKIP;
} }
} }
@ -790,7 +832,7 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
} }
@Override @Override
public int getTag() { public Tag getTag() {
return BLOCK; return BLOCK;
} }
} }
@ -817,7 +859,7 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
} }
@Override @Override
public int getTag() { public Tag getTag() {
return DOLOOP; return DOLOOP;
} }
} }
@ -844,7 +886,7 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
} }
@Override @Override
public int getTag() { public Tag getTag() {
return WHILELOOP; return WHILELOOP;
} }
} }
@ -885,7 +927,7 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
} }
@Override @Override
public int getTag() { public Tag getTag() {
return FORLOOP; return FORLOOP;
} }
} }
@ -914,7 +956,7 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
return v.visitEnhancedForLoop(this, d); return v.visitEnhancedForLoop(this, d);
} }
@Override @Override
public int getTag() { public Tag getTag() {
return FOREACHLOOP; return FOREACHLOOP;
} }
} }
@ -939,7 +981,7 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
return v.visitLabeledStatement(this, d); return v.visitLabeledStatement(this, d);
} }
@Override @Override
public int getTag() { public Tag getTag() {
return LABELLED; return LABELLED;
} }
} }
@ -965,7 +1007,7 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
return v.visitSwitch(this, d); return v.visitSwitch(this, d);
} }
@Override @Override
public int getTag() { public Tag getTag() {
return SWITCH; return SWITCH;
} }
} }
@ -991,7 +1033,7 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
return v.visitCase(this, d); return v.visitCase(this, d);
} }
@Override @Override
public int getTag() { public Tag getTag() {
return CASE; return CASE;
} }
} }
@ -1017,7 +1059,7 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
return v.visitSynchronized(this, d); return v.visitSynchronized(this, d);
} }
@Override @Override
public int getTag() { public Tag getTag() {
return SYNCHRONIZED; return SYNCHRONIZED;
} }
} }
@ -1057,7 +1099,7 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
return resources; return resources;
} }
@Override @Override
public int getTag() { public Tag getTag() {
return TRY; return TRY;
} }
} }
@ -1083,7 +1125,7 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
return v.visitCatch(this, d); return v.visitCatch(this, d);
} }
@Override @Override
public int getTag() { public Tag getTag() {
return CATCH; return CATCH;
} }
} }
@ -1115,7 +1157,7 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
return v.visitConditionalExpression(this, d); return v.visitConditionalExpression(this, d);
} }
@Override @Override
public int getTag() { public Tag getTag() {
return CONDEXPR; return CONDEXPR;
} }
} }
@ -1147,7 +1189,7 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
return v.visitIf(this, d); return v.visitIf(this, d);
} }
@Override @Override
public int getTag() { public Tag getTag() {
return IF; return IF;
} }
} }
@ -1172,7 +1214,7 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
return v.visitExpressionStatement(this, d); return v.visitExpressionStatement(this, d);
} }
@Override @Override
public int getTag() { public Tag getTag() {
return EXEC; return EXEC;
} }
@ -1212,7 +1254,7 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
return v.visitBreak(this, d); return v.visitBreak(this, d);
} }
@Override @Override
public int getTag() { public Tag getTag() {
return BREAK; return BREAK;
} }
} }
@ -1237,7 +1279,7 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
return v.visitContinue(this, d); return v.visitContinue(this, d);
} }
@Override @Override
public int getTag() { public Tag getTag() {
return CONTINUE; return CONTINUE;
} }
} }
@ -1260,7 +1302,7 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
return v.visitReturn(this, d); return v.visitReturn(this, d);
} }
@Override @Override
public int getTag() { public Tag getTag() {
return RETURN; return RETURN;
} }
} }
@ -1283,7 +1325,7 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
return v.visitThrow(this, d); return v.visitThrow(this, d);
} }
@Override @Override
public int getTag() { public Tag getTag() {
return THROW; return THROW;
} }
} }
@ -1309,7 +1351,7 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
return v.visitAssert(this, d); return v.visitAssert(this, d);
} }
@Override @Override
public int getTag() { public Tag getTag() {
return ASSERT; return ASSERT;
} }
} }
@ -1352,7 +1394,7 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
return this; return this;
} }
@Override @Override
public int getTag() { public Tag getTag() {
return(APPLY); return(APPLY);
} }
} }
@ -1402,7 +1444,7 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
return v.visitNewClass(this, d); return v.visitNewClass(this, d);
} }
@Override @Override
public int getTag() { public Tag getTag() {
return NEWCLASS; return NEWCLASS;
} }
} }
@ -1438,7 +1480,7 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
return v.visitNewArray(this, d); return v.visitNewArray(this, d);
} }
@Override @Override
public int getTag() { public Tag getTag() {
return NEWARRAY; return NEWARRAY;
} }
} }
@ -1461,7 +1503,7 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
return v.visitParenthesized(this, d); return v.visitParenthesized(this, d);
} }
@Override @Override
public int getTag() { public Tag getTag() {
return PARENS; return PARENS;
} }
} }
@ -1487,7 +1529,7 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
return v.visitAssignment(this, d); return v.visitAssignment(this, d);
} }
@Override @Override
public int getTag() { public Tag getTag() {
return ASSIGN; return ASSIGN;
} }
} }
@ -1496,11 +1538,11 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
* An assignment with "+=", "|=" ... * An assignment with "+=", "|=" ...
*/ */
public static class JCAssignOp extends JCExpression implements CompoundAssignmentTree { public static class JCAssignOp extends JCExpression implements CompoundAssignmentTree {
private int opcode; private Tag opcode;
public JCExpression lhs; public JCExpression lhs;
public JCExpression rhs; public JCExpression rhs;
public Symbol operator; public Symbol operator;
protected JCAssignOp(int opcode, JCTree lhs, JCTree rhs, Symbol operator) { protected JCAssignOp(Tag opcode, JCTree lhs, JCTree rhs, Symbol operator) {
this.opcode = opcode; this.opcode = opcode;
this.lhs = (JCExpression)lhs; this.lhs = (JCExpression)lhs;
this.rhs = (JCExpression)rhs; this.rhs = (JCExpression)rhs;
@ -1520,7 +1562,7 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
return v.visitCompoundAssignment(this, d); return v.visitCompoundAssignment(this, d);
} }
@Override @Override
public int getTag() { public Tag getTag() {
return opcode; return opcode;
} }
} }
@ -1529,10 +1571,10 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
* A unary operation. * A unary operation.
*/ */
public static class JCUnary extends JCExpression implements UnaryTree { public static class JCUnary extends JCExpression implements UnaryTree {
private int opcode; private Tag opcode;
public JCExpression arg; public JCExpression arg;
public Symbol operator; public Symbol operator;
protected JCUnary(int opcode, JCExpression arg) { protected JCUnary(Tag opcode, JCExpression arg) {
this.opcode = opcode; this.opcode = opcode;
this.arg = arg; this.arg = arg;
} }
@ -1549,11 +1591,11 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
return v.visitUnary(this, d); return v.visitUnary(this, d);
} }
@Override @Override
public int getTag() { public Tag getTag() {
return opcode; return opcode;
} }
public void setTag(int tag) { public void setTag(Tag tag) {
opcode = tag; opcode = tag;
} }
} }
@ -1562,11 +1604,11 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
* A binary operation. * A binary operation.
*/ */
public static class JCBinary extends JCExpression implements BinaryTree { public static class JCBinary extends JCExpression implements BinaryTree {
private int opcode; private Tag opcode;
public JCExpression lhs; public JCExpression lhs;
public JCExpression rhs; public JCExpression rhs;
public Symbol operator; public Symbol operator;
protected JCBinary(int opcode, protected JCBinary(Tag opcode,
JCExpression lhs, JCExpression lhs,
JCExpression rhs, JCExpression rhs,
Symbol operator) { Symbol operator) {
@ -1589,7 +1631,7 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
return v.visitBinary(this, d); return v.visitBinary(this, d);
} }
@Override @Override
public int getTag() { public Tag getTag() {
return opcode; return opcode;
} }
} }
@ -1615,7 +1657,7 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
return v.visitTypeCast(this, d); return v.visitTypeCast(this, d);
} }
@Override @Override
public int getTag() { public Tag getTag() {
return TYPECAST; return TYPECAST;
} }
} }
@ -1641,7 +1683,7 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
return v.visitInstanceOf(this, d); return v.visitInstanceOf(this, d);
} }
@Override @Override
public int getTag() { public Tag getTag() {
return TYPETEST; return TYPETEST;
} }
} }
@ -1667,7 +1709,7 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
return v.visitArrayAccess(this, d); return v.visitArrayAccess(this, d);
} }
@Override @Override
public int getTag() { public Tag getTag() {
return INDEXED; return INDEXED;
} }
} }
@ -1698,7 +1740,7 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
} }
public Name getIdentifier() { return name; } public Name getIdentifier() { return name; }
@Override @Override
public int getTag() { public Tag getTag() {
return SELECT; return SELECT;
} }
} }
@ -1724,7 +1766,8 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
public <R,D> R accept(TreeVisitor<R,D> v, D d) { public <R,D> R accept(TreeVisitor<R,D> v, D d) {
return v.visitIdentifier(this, d); return v.visitIdentifier(this, d);
} }
public int getTag() { @Override
public Tag getTag() {
return IDENT; return IDENT;
} }
} }
@ -1790,7 +1833,7 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
return this; return this;
} }
@Override @Override
public int getTag() { public Tag getTag() {
return LITERAL; return LITERAL;
} }
} }
@ -1838,7 +1881,7 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
return v.visitPrimitiveType(this, d); return v.visitPrimitiveType(this, d);
} }
@Override @Override
public int getTag() { public Tag getTag() {
return TYPEIDENT; return TYPEIDENT;
} }
} }
@ -1861,7 +1904,7 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
return v.visitArrayType(this, d); return v.visitArrayType(this, d);
} }
@Override @Override
public int getTag() { public Tag getTag() {
return TYPEARRAY; return TYPEARRAY;
} }
} }
@ -1889,7 +1932,7 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
return v.visitParameterizedType(this, d); return v.visitParameterizedType(this, d);
} }
@Override @Override
public int getTag() { public Tag getTag() {
return TYPEAPPLY; return TYPEAPPLY;
} }
} }
@ -1917,7 +1960,7 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
return v.visitUnionType(this, d); return v.visitUnionType(this, d);
} }
@Override @Override
public int getTag() { public Tag getTag() {
return TYPEUNION; return TYPEUNION;
} }
} }
@ -1947,7 +1990,7 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
return v.visitTypeParameter(this, d); return v.visitTypeParameter(this, d);
} }
@Override @Override
public int getTag() { public Tag getTag() {
return TYPEPARAMETER; return TYPEPARAMETER;
} }
} }
@ -1981,7 +2024,7 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
return v.visitWildcard(this, d); return v.visitWildcard(this, d);
} }
@Override @Override
public int getTag() { public Tag getTag() {
return WILDCARD; return WILDCARD;
} }
} }
@ -2002,7 +2045,7 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
throw new AssertionError("TypeBoundKind is not part of a public API"); throw new AssertionError("TypeBoundKind is not part of a public API");
} }
@Override @Override
public int getTag() { public Tag getTag() {
return TYPEBOUNDKIND; return TYPEBOUNDKIND;
} }
} }
@ -2027,7 +2070,7 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
return v.visitAnnotation(this, d); return v.visitAnnotation(this, d);
} }
@Override @Override
public int getTag() { public Tag getTag() {
return ANNOTATION; return ANNOTATION;
} }
} }
@ -2054,7 +2097,7 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
return v.visitModifiers(this, d); return v.visitModifiers(this, d);
} }
@Override @Override
public int getTag() { public Tag getTag() {
return MODIFIERS; return MODIFIERS;
} }
} }
@ -2079,7 +2122,7 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
return v.visitErroneous(this, d); return v.visitErroneous(this, d);
} }
@Override @Override
public int getTag() { public Tag getTag() {
return ERRONEOUS; return ERRONEOUS;
} }
} }
@ -2103,7 +2146,7 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
throw new AssertionError("LetExpr is not part of a public API"); throw new AssertionError("LetExpr is not part of a public API");
} }
@Override @Override
public int getTag() { public Tag getTag() {
return LETEXPR; return LETEXPR;
} }
} }
@ -2175,9 +2218,9 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
List<JCExpression> elems); List<JCExpression> elems);
JCParens Parens(JCExpression expr); JCParens Parens(JCExpression expr);
JCAssign Assign(JCExpression lhs, JCExpression rhs); JCAssign Assign(JCExpression lhs, JCExpression rhs);
JCAssignOp Assignop(int opcode, JCTree lhs, JCTree rhs); JCAssignOp Assignop(Tag opcode, JCTree lhs, JCTree rhs);
JCUnary Unary(int opcode, JCExpression arg); JCUnary Unary(Tag opcode, JCExpression arg);
JCBinary Binary(int opcode, JCExpression lhs, JCExpression rhs); JCBinary Binary(Tag opcode, JCExpression lhs, JCExpression rhs);
JCTypeCast TypeCast(JCTree expr, JCExpression type); JCTypeCast TypeCast(JCTree expr, JCExpression type);
JCInstanceOf TypeTest(JCExpression expr, JCTree clazz); JCInstanceOf TypeTest(JCExpression expr, JCTree clazz);
JCArrayAccess Indexed(JCExpression indexed, JCExpression index); JCArrayAccess Indexed(JCExpression indexed, JCExpression index);

View file

@ -36,6 +36,8 @@ import com.sun.tools.javac.code.Symbol.*;
import com.sun.tools.javac.tree.JCTree.*; import com.sun.tools.javac.tree.JCTree.*;
import static com.sun.tools.javac.code.Flags.*; import static com.sun.tools.javac.code.Flags.*;
import static com.sun.tools.javac.code.Flags.ANNOTATION;
import static com.sun.tools.javac.tree.JCTree.Tag.*;
/** Prints out a tree as an indented Java source program. /** Prints out a tree as an indented Java source program.
* *
@ -310,7 +312,7 @@ public class Pretty extends JCTree.Visitor {
/** Is the given tree an enumerator definition? */ /** Is the given tree an enumerator definition? */
boolean isEnumerator(JCTree t) { boolean isEnumerator(JCTree t) {
return t.getTag() == JCTree.VARDEF && (((JCVariableDecl) t).mods.flags & ENUM) != 0; return t.hasTag(VARDEF) && (((JCVariableDecl) t).mods.flags & ENUM) != 0;
} }
/** Print unit consisting of package clause and import statements in toplevel, /** Print unit consisting of package clause and import statements in toplevel,
@ -331,9 +333,9 @@ public class Pretty extends JCTree.Visitor {
} }
boolean firstImport = true; boolean firstImport = true;
for (List<JCTree> l = tree.defs; for (List<JCTree> l = tree.defs;
l.nonEmpty() && (cdef == null || l.head.getTag() == JCTree.IMPORT); l.nonEmpty() && (cdef == null || l.head.hasTag(IMPORT));
l = l.tail) { l = l.tail) {
if (l.head.getTag() == JCTree.IMPORT) { if (l.head.hasTag(IMPORT)) {
JCImport imp = (JCImport)l.head; JCImport imp = (JCImport)l.head;
Name name = TreeInfo.name(imp.qualid); Name name = TreeInfo.name(imp.qualid);
if (name == name.table.names.asterisk || if (name == name.table.names.asterisk ||
@ -484,7 +486,7 @@ public class Pretty extends JCTree.Visitor {
print("/*public static final*/ "); print("/*public static final*/ ");
print(tree.name); print(tree.name);
if (tree.init != null) { if (tree.init != null) {
if (sourceOutput && tree.init.getTag() == JCTree.NEWCLASS) { if (sourceOutput && tree.init.hasTag(NEWCLASS)) {
print(" /*enum*/ "); print(" /*enum*/ ");
JCNewClass init = (JCNewClass) tree.init; JCNewClass init = (JCNewClass) tree.init;
if (init.args != null && init.args.nonEmpty()) { if (init.args != null && init.args.nonEmpty()) {
@ -545,7 +547,7 @@ public class Pretty extends JCTree.Visitor {
printStat(tree.body); printStat(tree.body);
align(); align();
print(" while "); print(" while ");
if (tree.cond.getTag() == JCTree.PARENS) { if (tree.cond.hasTag(PARENS)) {
printExpr(tree.cond); printExpr(tree.cond);
} else { } else {
print("("); print("(");
@ -561,7 +563,7 @@ public class Pretty extends JCTree.Visitor {
public void visitWhileLoop(JCWhileLoop tree) { public void visitWhileLoop(JCWhileLoop tree) {
try { try {
print("while "); print("while ");
if (tree.cond.getTag() == JCTree.PARENS) { if (tree.cond.hasTag(PARENS)) {
printExpr(tree.cond); printExpr(tree.cond);
} else { } else {
print("("); print("(");
@ -579,7 +581,7 @@ public class Pretty extends JCTree.Visitor {
try { try {
print("for ("); print("for (");
if (tree.init.nonEmpty()) { if (tree.init.nonEmpty()) {
if (tree.init.head.getTag() == JCTree.VARDEF) { if (tree.init.head.hasTag(VARDEF)) {
printExpr(tree.init.head); printExpr(tree.init.head);
for (List<JCStatement> l = tree.init.tail; l.nonEmpty(); l = l.tail) { for (List<JCStatement> l = tree.init.tail; l.nonEmpty(); l = l.tail) {
JCVariableDecl vdef = (JCVariableDecl)l.head; JCVariableDecl vdef = (JCVariableDecl)l.head;
@ -626,7 +628,7 @@ public class Pretty extends JCTree.Visitor {
public void visitSwitch(JCSwitch tree) { public void visitSwitch(JCSwitch tree) {
try { try {
print("switch "); print("switch ");
if (tree.selector.getTag() == JCTree.PARENS) { if (tree.selector.hasTag(PARENS)) {
printExpr(tree.selector); printExpr(tree.selector);
} else { } else {
print("("); print("(");
@ -665,7 +667,7 @@ public class Pretty extends JCTree.Visitor {
public void visitSynchronized(JCSynchronized tree) { public void visitSynchronized(JCSynchronized tree) {
try { try {
print("synchronized "); print("synchronized ");
if (tree.lock.getTag() == JCTree.PARENS) { if (tree.lock.hasTag(PARENS)) {
printExpr(tree.lock); printExpr(tree.lock);
} else { } else {
print("("); print("(");
@ -736,7 +738,7 @@ public class Pretty extends JCTree.Visitor {
public void visitIf(JCIf tree) { public void visitIf(JCIf tree) {
try { try {
print("if "); print("if ");
if (tree.cond.getTag() == JCTree.PARENS) { if (tree.cond.hasTag(PARENS)) {
printExpr(tree.cond); printExpr(tree.cond);
} else { } else {
print("("); print("(");
@ -823,7 +825,7 @@ public class Pretty extends JCTree.Visitor {
public void visitApply(JCMethodInvocation tree) { public void visitApply(JCMethodInvocation tree) {
try { try {
if (!tree.typeargs.isEmpty()) { if (!tree.typeargs.isEmpty()) {
if (tree.meth.getTag() == JCTree.SELECT) { if (tree.meth.hasTag(SELECT)) {
JCFieldAccess left = (JCFieldAccess)tree.meth; JCFieldAccess left = (JCFieldAccess)tree.meth;
printExpr(left.selected); printExpr(left.selected);
print(".<"); print(".<");
@ -882,7 +884,7 @@ public class Pretty extends JCTree.Visitor {
if (tree.elemtype != null) { if (tree.elemtype != null) {
print("new "); print("new ");
JCTree elem = tree.elemtype; JCTree elem = tree.elemtype;
if (elem.getTag() == JCTree.TYPEARRAY) if (elem.hasTag(TYPEARRAY))
printBaseElementType((JCArrayTypeTree) elem); printBaseElementType((JCArrayTypeTree) elem);
else else
printExpr(elem); printExpr(elem);
@ -927,36 +929,36 @@ public class Pretty extends JCTree.Visitor {
} }
} }
public String operatorName(int tag) { public String operatorName(JCTree.Tag tag) {
switch(tag) { switch(tag) {
case JCTree.POS: return "+"; case POS: return "+";
case JCTree.NEG: return "-"; case NEG: return "-";
case JCTree.NOT: return "!"; case NOT: return "!";
case JCTree.COMPL: return "~"; case COMPL: return "~";
case JCTree.PREINC: return "++"; case PREINC: return "++";
case JCTree.PREDEC: return "--"; case PREDEC: return "--";
case JCTree.POSTINC: return "++"; case POSTINC: return "++";
case JCTree.POSTDEC: return "--"; case POSTDEC: return "--";
case JCTree.NULLCHK: return "<*nullchk*>"; case NULLCHK: return "<*nullchk*>";
case JCTree.OR: return "||"; case OR: return "||";
case JCTree.AND: return "&&"; case AND: return "&&";
case JCTree.EQ: return "=="; case EQ: return "==";
case JCTree.NE: return "!="; case NE: return "!=";
case JCTree.LT: return "<"; case LT: return "<";
case JCTree.GT: return ">"; case GT: return ">";
case JCTree.LE: return "<="; case LE: return "<=";
case JCTree.GE: return ">="; case GE: return ">=";
case JCTree.BITOR: return "|"; case BITOR: return "|";
case JCTree.BITXOR: return "^"; case BITXOR: return "^";
case JCTree.BITAND: return "&"; case BITAND: return "&";
case JCTree.SL: return "<<"; case SL: return "<<";
case JCTree.SR: return ">>"; case SR: return ">>";
case JCTree.USR: return ">>>"; case USR: return ">>>";
case JCTree.PLUS: return "+"; case PLUS: return "+";
case JCTree.MINUS: return "-"; case MINUS: return "-";
case JCTree.MUL: return "*"; case MUL: return "*";
case JCTree.DIV: return "/"; case DIV: return "/";
case JCTree.MOD: return "%"; case MOD: return "%";
default: throw new Error(); default: throw new Error();
} }
} }
@ -965,7 +967,7 @@ public class Pretty extends JCTree.Visitor {
try { try {
open(prec, TreeInfo.assignopPrec); open(prec, TreeInfo.assignopPrec);
printExpr(tree.lhs, TreeInfo.assignopPrec + 1); printExpr(tree.lhs, TreeInfo.assignopPrec + 1);
print(" " + operatorName(tree.getTag() - JCTree.ASGOffset) + "= "); print(" " + operatorName(tree.getTag().noAssignOp()) + "= ");
printExpr(tree.rhs, TreeInfo.assignopPrec); printExpr(tree.rhs, TreeInfo.assignopPrec);
close(prec, TreeInfo.assignopPrec); close(prec, TreeInfo.assignopPrec);
} catch (IOException e) { } catch (IOException e) {
@ -978,7 +980,7 @@ public class Pretty extends JCTree.Visitor {
int ownprec = TreeInfo.opPrec(tree.getTag()); int ownprec = TreeInfo.opPrec(tree.getTag());
String opname = operatorName(tree.getTag()); String opname = operatorName(tree.getTag());
open(prec, ownprec); open(prec, ownprec);
if (tree.getTag() <= JCTree.PREDEC) { if (!tree.getTag().isPostUnaryOp()) {
print(opname); print(opname);
printExpr(tree.arg, ownprec); printExpr(tree.arg, ownprec);
} else { } else {
@ -1153,7 +1155,7 @@ public class Pretty extends JCTree.Visitor {
while (true) { while (true) {
elem = tree.elemtype; elem = tree.elemtype;
print("[]"); print("[]");
if (elem.getTag() != JCTree.TYPEARRAY) break; if (!elem.hasTag(TYPEARRAY)) break;
tree = (JCArrayTypeTree) elem; tree = (JCArrayTypeTree) elem;
} }
} }

View file

@ -406,7 +406,7 @@ public class TreeCopier<P> implements TreeVisitor<JCTree,P> {
public JCTree visitOther(Tree node, P p) { public JCTree visitOther(Tree node, P p) {
JCTree tree = (JCTree) node; JCTree tree = (JCTree) node;
switch (tree.getTag()) { switch (tree.getTag()) {
case JCTree.LETEXPR: { case LETEXPR: {
LetExpr t = (LetExpr) node; LetExpr t = (LetExpr) node;
List<JCVariableDecl> defs = copy(t.defs, p); List<JCVariableDecl> defs = copy(t.defs, p);
JCTree expr = copy(t.expr, p); JCTree expr = copy(t.expr, p);

View file

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

View file

@ -363,19 +363,19 @@ public class TreeMaker implements JCTree.Factory {
return tree; return tree;
} }
public JCAssignOp Assignop(int opcode, JCTree lhs, JCTree rhs) { public JCAssignOp Assignop(JCTree.Tag opcode, JCTree lhs, JCTree rhs) {
JCAssignOp tree = new JCAssignOp(opcode, lhs, rhs, null); JCAssignOp tree = new JCAssignOp(opcode, lhs, rhs, null);
tree.pos = pos; tree.pos = pos;
return tree; return tree;
} }
public JCUnary Unary(int opcode, JCExpression arg) { public JCUnary Unary(JCTree.Tag opcode, JCExpression arg) {
JCUnary tree = new JCUnary(opcode, arg); JCUnary tree = new JCUnary(opcode, arg);
tree.pos = pos; tree.pos = pos;
return tree; return tree;
} }
public JCBinary Binary(int opcode, JCExpression lhs, JCExpression rhs) { public JCBinary Binary(JCTree.Tag opcode, JCExpression lhs, JCExpression rhs) {
JCBinary tree = new JCBinary(opcode, lhs, rhs, null); JCBinary tree = new JCBinary(opcode, lhs, rhs, null);
tree.pos = pos; tree.pos = pos;
return tree; return tree;

View file

@ -65,6 +65,7 @@ import com.sun.tools.javac.util.Names;
import com.sun.tools.javac.util.Position; import com.sun.tools.javac.util.Position;
import static com.sun.tools.javac.code.Kinds.*; import static com.sun.tools.javac.code.Kinds.*;
import static com.sun.tools.javac.tree.JCTree.Tag.*;
/** /**
* Represents a java class and provides access to information * Represents a java class and provides access to information
@ -1083,7 +1084,7 @@ public class ClassDocImpl extends ProgramElementDocImpl implements ClassDoc {
Name asterisk = tsym.name.table.names.asterisk; Name asterisk = tsym.name.table.names.asterisk;
for (JCTree t : compenv.toplevel.defs) { for (JCTree t : compenv.toplevel.defs) {
if (t.getTag() == JCTree.IMPORT) { if (t.hasTag(IMPORT)) {
JCTree imp = ((JCImport) t).qualid; JCTree imp = ((JCImport) t).qualid;
if ((TreeInfo.name(imp) != asterisk) && if ((TreeInfo.name(imp) != asterisk) &&
(imp.type.tsym.kind & Kinds.TYP) != 0) { (imp.type.tsym.kind & Kinds.TYP) != 0) {
@ -1124,7 +1125,7 @@ public class ClassDocImpl extends ProgramElementDocImpl implements ClassDoc {
if (compenv == null) return new PackageDocImpl[0]; if (compenv == null) return new PackageDocImpl[0];
for (JCTree t : compenv.toplevel.defs) { for (JCTree t : compenv.toplevel.defs) {
if (t.getTag() == JCTree.IMPORT) { if (t.hasTag(IMPORT)) {
JCTree imp = ((JCImport) t).qualid; JCTree imp = ((JCImport) t).qualid;
if (TreeInfo.name(imp) == names.asterisk) { if (TreeInfo.name(imp) == names.asterisk) {
JCFieldAccess sel = (JCFieldAccess)imp; JCFieldAccess sel = (JCFieldAccess)imp;

View file

@ -419,7 +419,7 @@ public class JavadocTool extends com.sun.tools.javac.main.JavaCompiler {
ListBuffer<JCClassDecl> result = new ListBuffer<JCClassDecl>(); ListBuffer<JCClassDecl> result = new ListBuffer<JCClassDecl>();
for (JCCompilationUnit t : trees) { for (JCCompilationUnit t : trees) {
for (JCTree def : t.defs) { for (JCTree def : t.defs) {
if (def.getTag() == JCTree.CLASSDEF) if (def.hasTag(JCTree.Tag.CLASSDEF))
result.append((JCClassDecl)def); result.append((JCClassDecl)def);
} }
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -85,6 +85,8 @@ import java.util.HashSet;
import java.util.Set; import java.util.Set;
import javax.lang.model.element.Element; import javax.lang.model.element.Element;
import static com.sun.tools.javac.tree.JCTree.Tag.*;
/** /**
* Utility and test program to check validity of tree positions for tree nodes. * Utility and test program to check validity of tree positions for tree nodes.
* The program can be run standalone, or as a jtreg test. In standalone mode, * The program can be run standalone, or as a jtreg test. In standalone mode,
@ -289,7 +291,7 @@ public class CheckAttributedTree {
for (CompilationUnitTree t : trees) { for (CompilationUnitTree t : trees) {
JCCompilationUnit cu = (JCCompilationUnit)t; JCCompilationUnit cu = (JCCompilationUnit)t;
for (JCTree def : cu.defs) { for (JCTree def : cu.defs) {
if (def.getTag() == JCTree.CLASSDEF && if (def.hasTag(CLASSDEF) &&
analyzedElems.contains(((JCTree.JCClassDecl)def).sym)) { analyzedElems.contains(((JCTree.JCClassDecl)def).sym)) {
//System.out.println("Adding pair..."); //System.out.println("Adding pair...");
res.add(new Pair<>(cu, def)); res.add(new Pair<>(cu, def));
@ -373,9 +375,9 @@ public class CheckAttributedTree {
private boolean mandatoryType(JCTree that) { private boolean mandatoryType(JCTree that) {
return that instanceof JCTree.JCExpression || return that instanceof JCTree.JCExpression ||
that.getTag() == JCTree.VARDEF || that.hasTag(VARDEF) ||
that.getTag() == JCTree.METHODDEF || that.hasTag(METHODDEF) ||
that.getTag() == JCTree.CLASSDEF; that.hasTag(CLASSDEF);
} }
private final List<String> excludedFields = Arrays.asList("varargsElement"); private final List<String> excludedFields = Arrays.asList("varargsElement");
@ -429,7 +431,7 @@ public class CheckAttributedTree {
private class Info { private class Info {
Info() { Info() {
tree = null; tree = null;
tag = JCTree.ERRONEOUS; tag = ERRONEOUS;
start = 0; start = 0;
pos = 0; pos = 0;
end = Integer.MAX_VALUE; end = Integer.MAX_VALUE;
@ -449,7 +451,7 @@ public class CheckAttributedTree {
} }
final JCTree tree; final JCTree tree;
final int tag; final JCTree.Tag tag;
final int start; final int start;
final int pos; final int pos;
final int end; final int end;
@ -457,27 +459,10 @@ public class CheckAttributedTree {
/** /**
* Names for tree tags. * Names for tree tags.
* javac does not provide an API to convert tag values to strings, so this class uses
* reflection to determine names of public static final int values in JCTree.
*/ */
private static class TreeUtil { private static class TreeUtil {
String nameFromTag(int tag) { String nameFromTag(JCTree.Tag tag) {
if (names == null) { String name = tag.name();
names = new HashMap<Integer, String>();
Class c = JCTree.class;
for (Field f : c.getDeclaredFields()) {
if (f.getType().equals(int.class)) {
int mods = f.getModifiers();
if (Modifier.isPublic(mods) && Modifier.isStatic(mods) && Modifier.isFinal(mods)) {
try {
names.put(f.getInt(null), f.getName());
} catch (IllegalAccessException e) {
}
}
}
}
}
String name = names.get(tag);
return (name == null) ? "??" : name; return (name == null) ? "??" : name;
} }
@ -496,8 +481,6 @@ public class CheckAttributedTree {
} }
return buf; return buf;
} }
private Map<Integer, String> names;
} }
/** /**

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -274,7 +274,7 @@ public abstract class AbstractTreeScannerTest {
return fields; return fields;
} }
// where // where
Map<Integer, Set<Field>> map = new HashMap<Integer,Set<Field>>(); Map<JCTree.Tag, Set<Field>> map = new HashMap<JCTree.Tag,Set<Field>>();
/** Get the line number for the primary position for a tree. /** Get the line number for the primary position for a tree.
* The code is intended to be simple, although not necessarily efficient. * The code is intended to be simple, although not necessarily efficient.

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -80,6 +80,7 @@ import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
import com.sun.tools.javac.tree.TreeInfo; import com.sun.tools.javac.tree.TreeInfo;
import com.sun.tools.javac.tree.TreeScanner; import com.sun.tools.javac.tree.TreeScanner;
import static com.sun.tools.javac.tree.JCTree.Tag.*;
import static com.sun.tools.javac.util.Position.NOPOS; import static com.sun.tools.javac.util.Position.NOPOS;
/** /**
@ -291,6 +292,14 @@ public class TreePosTest {
errors++; errors++;
} }
/**
* Names for tree tags.
*/
private static String getTagName(JCTree.Tag tag) {
String name = tag.name();
return (name == null) ? "??" : name;
}
/** Number of files that have been analyzed. */ /** Number of files that have been analyzed. */
int fileCount; int fileCount;
/** Number of errors reported. */ /** Number of errors reported. */
@ -312,8 +321,6 @@ public class TreePosTest {
Set<File> excludeFiles = new HashSet<File>(); Set<File> excludeFiles = new HashSet<File>();
/** Set of tag names to be excluded from analysis. */ /** Set of tag names to be excluded from analysis. */
Set<String> excludeTags = new HashSet<String>(); Set<String> excludeTags = new HashSet<String>();
/** Table of printable names for tree tag values. */
TagNames tagNames = new TagNames();
/** /**
* Main class for testing assertions concerning tree positions for tree nodes. * Main class for testing assertions concerning tree positions for tree nodes.
@ -337,7 +344,7 @@ public class TreePosTest {
// there is no corresponding source text. // there is no corresponding source text.
// Redundant semicolons in a class definition can cause empty // Redundant semicolons in a class definition can cause empty
// initializer blocks with no positions. // initializer blocks with no positions.
if ((self.tag == JCTree.MODIFIERS || self.tag == JCTree.BLOCK) if ((self.tag == MODIFIERS || self.tag == BLOCK)
&& self.pos == NOPOS) { && self.pos == NOPOS) {
// If pos is NOPOS, so should be the start and end positions // If pos is NOPOS, so should be the start and end positions
check("start == NOPOS", encl, self, self.start == NOPOS); check("start == NOPOS", encl, self, self.start == NOPOS);
@ -359,15 +366,15 @@ public class TreePosTest {
// e.g. int[][] a = new int[2][]; // e.g. int[][] a = new int[2][];
check("encl.start <= start", encl, self, encl.start <= self.start); check("encl.start <= start", encl, self, encl.start <= self.start);
check("start <= pos", encl, self, self.start <= self.pos); check("start <= pos", encl, self, self.start <= self.pos);
if (!(self.tag == JCTree.TYPEARRAY if (!(self.tag == TYPEARRAY
&& (encl.tag == JCTree.VARDEF || && (encl.tag == VARDEF ||
encl.tag == JCTree.METHODDEF || encl.tag == METHODDEF ||
encl.tag == JCTree.TYPEARRAY))) { encl.tag == TYPEARRAY))) {
check("encl.pos <= start || end <= encl.pos", check("encl.pos <= start || end <= encl.pos",
encl, self, encl.pos <= self.start || self.end <= encl.pos); encl, self, encl.pos <= self.start || self.end <= encl.pos);
} }
check("pos <= end", encl, self, self.pos <= self.end); check("pos <= end", encl, self, self.pos <= self.end);
if (!(self.tag == JCTree.TYPEARRAY && encl.tag == JCTree.TYPEARRAY)) { if (!(self.tag == TYPEARRAY && encl.tag == TYPEARRAY)) {
check("end <= encl.end", encl, self, self.end <= encl.end); check("end <= encl.end", encl, self, self.end <= encl.end);
} }
} }
@ -388,7 +395,7 @@ public class TreePosTest {
if ((tree.mods.flags & Flags.ENUM) != 0) { if ((tree.mods.flags & Flags.ENUM) != 0) {
scan(tree.mods); scan(tree.mods);
if (tree.init != null) { if (tree.init != null) {
if (tree.init.getTag() == JCTree.NEWCLASS) { if (tree.init.hasTag(NEWCLASS)) {
JCNewClass init = (JCNewClass) tree.init; JCNewClass init = (JCNewClass) tree.init;
if (init.args != null && init.args.nonEmpty()) { if (init.args != null && init.args.nonEmpty()) {
scan(init.args); scan(init.args);
@ -404,11 +411,11 @@ public class TreePosTest {
boolean check(Info encl, Info self) { boolean check(Info encl, Info self) {
if (excludeTags.size() > 0) { if (excludeTags.size() > 0) {
if (encl != null && excludeTags.contains(tagNames.get(encl.tag)) if (encl != null && excludeTags.contains(getTagName(encl.tag))
|| excludeTags.contains(tagNames.get(self.tag))) || excludeTags.contains(getTagName(self.tag)))
return false; return false;
} }
return tags.size() == 0 || tags.contains(tagNames.get(self.tag)); return tags.size() == 0 || tags.contains(getTagName(self.tag));
} }
void check(String label, Info encl, Info self, boolean ok) { void check(String label, Info encl, Info self, boolean ok) {
@ -439,7 +446,7 @@ public class TreePosTest {
private class Info { private class Info {
Info() { Info() {
tree = null; tree = null;
tag = JCTree.ERRONEOUS; tag = ERRONEOUS;
start = 0; start = 0;
pos = 0; pos = 0;
end = Integer.MAX_VALUE; end = Integer.MAX_VALUE;
@ -455,45 +462,16 @@ public class TreePosTest {
@Override @Override
public String toString() { public String toString() {
return tagNames.get(tree.getTag()) + "[start:" + start + ",pos:" + pos + ",end:" + end + "]"; return getTagName(tree.getTag()) + "[start:" + start + ",pos:" + pos + ",end:" + end + "]";
} }
final JCTree tree; final JCTree tree;
final int tag; final JCTree.Tag tag;
final int start; final int start;
final int pos; final int pos;
final int end; final int end;
} }
/**
* Names for tree tags.
* javac does not provide an API to convert tag values to strings, so this class uses
* reflection to determine names of public static final int values in JCTree.
*/
private static class TagNames {
String get(int tag) {
if (map == null) {
map = new HashMap<Integer, String>();
Class c = JCTree.class;
for (Field f : c.getDeclaredFields()) {
if (f.getType().equals(int.class)) {
int mods = f.getModifiers();
if (Modifier.isPublic(mods) && Modifier.isStatic(mods) && Modifier.isFinal(mods)) {
try {
map.put(f.getInt(null), f.getName());
} catch (IllegalAccessException e) {
}
}
}
}
}
String name = map.get(tag);
return (name == null) ? "??" : name;
}
private Map<Integer, String> map;
}
/** /**
* Thrown when errors are found parsing a java file. * Thrown when errors are found parsing a java file.
*/ */
@ -719,7 +697,7 @@ public class TreePosTest {
void setInfo(Info info) { void setInfo(Info info) {
this.info = info; this.info = info;
tagName.setText(tagNames.get(info.tag)); tagName.setText(getTagName(info.tag));
start.setText(String.valueOf(info.start)); start.setText(String.valueOf(info.start));
pos.setText(String.valueOf(info.pos)); pos.setText(String.valueOf(info.pos));
end.setText(String.valueOf(info.end)); end.setText(String.valueOf(info.end));