In SimpleNode, there is a protected field (id) that I wish to use to
compare against the
constants generated on the XXXTreeConstants interface
Right now I have to do: ...
public class MyVisitor implements XXXVisitor {
public Object visit(ASTDeclarativeSection node, Object data)
throws Exception {
ArrayList<Node> types = new ArrayList<Node>();
ArrayList<Node> programUnits = new ArrayList<Node>();
for (int i=0; i < node.jjtGetNumChildren(); i++ ) {
Node n = node.jjtGetChild(i);
if (n instanceof ASTProgramUnit) {
programUnits.add(n);
}
else if (n instanceof ASTTypeDefinition) {
types.add(n);
}
}
// visit types before programUnits
for (int i=0; i < types.size(); i++ ) {
Node n = types.get(i);
n.jjtAccept(this, data);
}
for (int i=0; i < programUnits.size(); i++ ) {
Node n = programUnits.get(i);
Object o = n.jjtAccept(this, data);
}
return data;
}
It would be a lot nicer if one could do something like:
if (n.getId() == XXXTreeConstants.JJTPROGRAMUNIT) {
programUnits.add(n);
}
else if (n.getId() == XXXTreeConstants.JJTTYPEDEFINITION)
{
types.add(n);
}
instead of the instanceof check