| 1 |
#if SUPPORT_CLASS_VISIBILITY_PUBLIC |
| 2 |
public |
| 3 |
#fi |
| 4 |
#if NODE_EXTENDS |
| 5 |
class SimpleNode extends ${NODE_EXTENDS} implements Node { |
| 6 |
#else |
| 7 |
class SimpleNode implements Node { |
| 8 |
#fi |
| 9 |
|
| 10 |
protected Node parent; |
| 11 |
protected Node[] children; |
| 12 |
protected int id; |
| 13 |
protected Object value; |
| 14 |
protected ${PARSER_NAME} parser; |
| 15 |
#if TRACK_TOKENS |
| 16 |
protected Token firstToken; |
| 17 |
protected Token lastToken; |
| 18 |
#fi |
| 19 |
|
| 20 |
public SimpleNode(int i) { |
| 21 |
id = i; |
| 22 |
} |
| 23 |
|
| 24 |
public SimpleNode(${PARSER_NAME} p, int i) { |
| 25 |
this(i); |
| 26 |
parser = p; |
| 27 |
} |
| 28 |
|
| 29 |
#if NODE_FACTORY |
| 30 |
public static Node jjtCreate(int id) { |
| 31 |
return new SimpleNode(id); |
| 32 |
} |
| 33 |
|
| 34 |
public static Node jjtCreate(${PARSER_NAME} p, int id) { |
| 35 |
return new SimpleNode(p, id); |
| 36 |
} |
| 37 |
|
| 38 |
#fi |
| 39 |
public void jjtOpen() { |
| 40 |
} |
| 41 |
|
| 42 |
public void jjtClose() { |
| 43 |
} |
| 44 |
|
| 45 |
public void jjtSetParent(Node n) { parent = n; } |
| 46 |
public Node jjtGetParent() { return parent; } |
| 47 |
|
| 48 |
public void jjtAddChild(Node n, int i) { |
| 49 |
if (children == null) { |
| 50 |
children = new Node[i + 1]; |
| 51 |
} else if (i >= children.length) { |
| 52 |
Node c[] = new Node[i + 1]; |
| 53 |
System.arraycopy(children, 0, c, 0, children.length); |
| 54 |
children = c; |
| 55 |
} |
| 56 |
children[i] = n; |
| 57 |
} |
| 58 |
|
| 59 |
public Node jjtGetChild(int i) { |
| 60 |
return children[i]; |
| 61 |
} |
| 62 |
|
| 63 |
public int jjtGetNumChildren() { |
| 64 |
return (children == null) ? 0 : children.length; |
| 65 |
} |
| 66 |
|
| 67 |
public void jjtSetValue(Object value) { this.value = value; } |
| 68 |
public Object jjtGetValue() { return value; } |
| 69 |
|
| 70 |
#if TRACK_TOKENS |
| 71 |
public Token jjtGetFirstToken() { return firstToken; } |
| 72 |
public void jjtSetFirstToken(Token token) { this.firstToken = token; } |
| 73 |
public Token jjtGetLastToken() { return lastToken; } |
| 74 |
public void jjtSetLastToken(Token token) { this.lastToken = token; } |
| 75 |
|
| 76 |
#fi |
| 77 |
#if VISITOR |
| 78 |
/** Accept the visitor. **/ |
| 79 |
public ${VISITOR_RETURN_TYPE} jjtAccept(${PARSER_NAME}Visitor visitor, ${VISITOR_DATA_TYPE:-Object} data) |
| 80 |
#if VISITOR_EXCEPTION |
| 81 |
throws ${VISITOR_EXCEPTION} |
| 82 |
#fi |
| 83 |
{ |
| 84 |
#if VISITOR_RETURN_TYPE_VOID |
| 85 |
visitor.visit(this, data); |
| 86 |
#else |
| 87 |
return visitor.visit(this, data); |
| 88 |
#fi |
| 89 |
} |
| 90 |
|
| 91 |
/** Accept the visitor. **/ |
| 92 |
public Object childrenAccept(${PARSER_NAME}Visitor visitor, ${VISITOR_DATA_TYPE:-Object} data) |
| 93 |
#if VISITOR_EXCEPTION |
| 94 |
throws ${VISITOR_EXCEPTION} |
| 95 |
#fi |
| 96 |
{ |
| 97 |
if (children != null) { |
| 98 |
for (int i = 0; i < children.length; ++i) { |
| 99 |
children[i].jjtAccept(visitor, data); |
| 100 |
} |
| 101 |
} |
| 102 |
return data; |
| 103 |
} |
| 104 |
|
| 105 |
#fi |
| 106 |
/* You can override these two methods in subclasses of SimpleNode to |
| 107 |
customize the way the node appears when the tree is dumped. If |
| 108 |
your output uses more than one line you should override |
| 109 |
toString(String), otherwise overriding toString() is probably all |
| 110 |
you need to do. */ |
| 111 |
|
| 112 |
public String toString() { return ${PARSER_NAME}TreeConstants.jjtNodeName[id]; } |
| 113 |
public String toString(String prefix) { return prefix + toString(); } |
| 114 |
|
| 115 |
/* Override this method if you want to customize how the node dumps |
| 116 |
out its children. */ |
| 117 |
|
| 118 |
public void dump(String prefix) { |
| 119 |
System.out.println(toString(prefix)); |
| 120 |
if (children != null) { |
| 121 |
for (int i = 0; i < children.length; ++i) { |
| 122 |
SimpleNode n = (SimpleNode)children[i]; |
| 123 |
if (n != null) { |
| 124 |
n.dump(prefix + " "); |
| 125 |
} |
| 126 |
} |
| 127 |
} |
| 128 |
} |
| 129 |
} |
| 130 |
|