001: /* Generated By:JJTree: Do not edit this line. SimpleNode.java */
002:
003: package jaxx.parser;
004:
005: import jaxx.reflect.*;
006:
007: public class SimpleNode implements Node {
008: protected Node parent;
009: protected Node[] children;
010: protected int id;
011: protected JavaParser parser;
012: public Token firstToken;
013: public Token lastToken;
014: private ClassDescriptor javaType;
015:
016: public SimpleNode(int i) {
017: id = i;
018: }
019:
020: public SimpleNode(JavaParser p, int i) {
021: this (i);
022: parser = p;
023: }
024:
025: public int getId() {
026: return id;
027: }
028:
029: public void jjtOpen() {
030: }
031:
032: public void jjtClose() {
033: }
034:
035: public void jjtSetParent(Node n) {
036: parent = n;
037: }
038:
039: public Node jjtGetParent() {
040: return parent;
041: }
042:
043: public SimpleNode getParent() {
044: return (SimpleNode) parent;
045: }
046:
047: public ClassDescriptor getJavaType() {
048: return javaType;
049: }
050:
051: public void setJavaType(ClassDescriptor javaType) {
052: this .javaType = javaType;
053: }
054:
055: public void jjtAddChild(Node n, int i) {
056: if (children == null) {
057: children = new Node[i + 1];
058: } else if (i >= children.length) {
059: Node c[] = new Node[i + 1];
060: System.arraycopy(children, 0, c, 0, children.length);
061: children = c;
062: }
063: children[i] = n;
064: }
065:
066: public Node jjtGetChild(int i) {
067: return children[i];
068: }
069:
070: public SimpleNode getChild(int i) {
071: return (SimpleNode) children[i];
072: }
073:
074: public int jjtGetNumChildren() {
075: return (children == null) ? 0 : children.length;
076: }
077:
078: /* You can override these two methods in subclasses of SimpleNode to
079: customize the way the node appears when the tree is dumped. If
080: your output uses more than one line you should override
081: toString(String), otherwise overriding toString() is probably all
082: you need to do. */
083:
084: public String toString() {
085: return getClass().getName() + "[" + getText() + "]";
086: }
087:
088: public String toString(String prefix) {
089: return prefix + toString();
090: }
091:
092: /* Override this method if you want to customize how the node dumps
093: out its children. */
094:
095: public void dump(String prefix) {
096: System.out.println(toString(prefix));
097: if (children != null) {
098: for (int i = 0; i < children.length; ++i) {
099: SimpleNode n = (SimpleNode) children[i];
100: if (n != null) {
101: n.dump(prefix + " ");
102: }
103: }
104: }
105: }
106:
107: private void appendSpecialTokens(StringBuffer s, Token st) {
108: if (st != null) {
109: appendSpecialTokens(s, st.specialToken);
110: s.append(st.image);
111: }
112: }
113:
114: /**
115: Get the text of the tokens comprising this node.
116: */
117: public String getText() {
118: StringBuffer text = new StringBuffer();
119: Token t = firstToken;
120: while (t != null) {
121: appendSpecialTokens(text, t.specialToken);
122: text.append(t.image);
123: if (t == lastToken)
124: break;
125: t = t.next;
126: }
127:
128: return text.toString();
129: }
130: }
|