KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > speedo > query > parser > SimpleNode


1 /* Generated By:JJTree: Do not edit this line. SimpleNode.java */
2
3 package org.objectweb.speedo.query.parser;
4
5 import org.objectweb.speedo.query.parser.SpeedoQLTreeConstants;
6 import org.objectweb.speedo.query.parser.SpeedoQL;
7 import org.objectweb.speedo.query.parser.Node;
8 import org.objectweb.speedo.query.parser.SpeedoQLVisitor;
9 import org.objectweb.speedo.query.parser.SpeedoQLConstants;
10
11 import java.util.ArrayList JavaDoc;
12 import java.util.Iterator JavaDoc;
13
14 public class SimpleNode implements Node {
15     protected Node parent;
16     protected Node[] children;
17     protected int id;
18     protected SpeedoQL parser;
19
20     // added by S. Chassande-Barrioz
21
public ArrayList JavaDoc ops = new ArrayList JavaDoc(); //operators
22
public Object JavaDoc value = null;
23     // end added
24

25
26     public SimpleNode(int i) {
27         id = i;
28     }
29
30     public SimpleNode(SpeedoQL p, int i) {
31         this(i);
32         parser = p;
33     }
34
35     public void jjtOpen() {
36     }
37
38     public void jjtClose() {
39     }
40
41     public void jjtSetParent(Node n) {
42         parent = n;
43     }
44
45     public Node jjtGetParent() {
46         return parent;
47     }
48
49     public void jjtAddChild(Node n, int i) {
50         if (children == null) {
51             children = new Node[i + 1];
52         } else if (i >= children.length) {
53             Node c[] = new Node[i + 1];
54             System.arraycopy(children, 0, c, 0, children.length);
55             children = c;
56         }
57         children[i] = n;
58     }
59
60     public Node jjtGetChild(int i) {
61         return children[i];
62     }
63
64     public int jjtGetNumChildren() {
65         return (children == null) ? 0 : children.length;
66     }
67
68     /* You can override these two methods in subclasses of SimpleNode to
69 customize the way the node appears when the tree is dumped. If
70 your output uses more than one line you should override
71 toString(String), otherwise overriding toString() is probably all
72 you need to do. */

73
74     public String JavaDoc toString() {
75         String JavaDoc ret = "";
76
77         if (ops.size() != 0) {
78             ret += "(";
79             for (Iterator JavaDoc i = ops.iterator(); i.hasNext();) {
80                 String JavaDoc token = SpeedoQLConstants.tokenImage[((Integer JavaDoc) i.next()).intValue()];
81                 ret += token.substring(1, token.length() - 1) + ",";
82                 //ret+=token+",";
83
}
84             ret = ret.substring(0, ret.length() - 1);
85         }
86         if (value != null) ret += "value=[" + value + "]";
87         if (ops.size() != 0) ret += ")";
88         return SpeedoQLTreeConstants.jjtNodeName[id] + " " + ret;
89     }
90
91     public String JavaDoc toString(String JavaDoc prefix) {
92         return prefix + toString();
93     }
94
95     /* Override this method if you want to customize how the node dumps
96 out its children. */

97
98     public void dump(String JavaDoc prefix) {
99         System.out.println(toString(prefix));
100         if (children != null) {
101             for (int i = 0; i < children.length; ++i) {
102                 SimpleNode n = (SimpleNode) children[i];
103                 if (n != null) {
104                     n.dump(prefix + " ");
105                 }
106             }
107         }
108     }
109
110     /** Accept the visitor. **/
111     public Object JavaDoc jjtAccept(SpeedoQLVisitor visitor, Object JavaDoc data) {
112         return visitor.visit(this, data);
113     }
114
115     /** Accept the visitor. **/
116     public Object JavaDoc childrenAccept(SpeedoQLVisitor visitor, Object JavaDoc data) {
117         if (children != null) {
118             for (int i = 0; i < children.length; ++i) {
119                 children[i].jjtAccept(visitor, data);
120             }
121         }
122         return data;
123     }
124 }
125
126
Popular Tags