View Javadoc

1   /* Generated By:JJTree: Do not edit this line. SimpleNode.java */
2   
3   package org.glassbox.dotparser;
4   
5   public class SimpleNode implements Node {
6     protected Node parent;
7     protected Node[] children;
8     protected int id;
9     protected DOTParser parser;
10  
11    public SimpleNode(int i) {
12      id = i;
13    }
14  
15    public SimpleNode(DOTParser p, int i) {
16      this(i);
17      parser = p;
18    }
19  
20    public void jjtOpen() {
21    }
22  
23    public void jjtClose() {
24    }
25    
26    public void jjtSetParent(Node n) { parent = n; }
27    public Node jjtGetParent() { return parent; }
28  
29    public void jjtAddChild(Node n, int i) {
30      if (children == null) {
31        children = new Node[i + 1];
32      } else if (i >= children.length) {
33        Node c[] = new Node[i + 1];
34        System.arraycopy(children, 0, c, 0, children.length);
35        children = c;
36      }
37      children[i] = n;
38    }
39  
40    public Node jjtGetChild(int i) {
41      return children[i];
42    }
43  
44    public int jjtGetNumChildren() {
45      return (children == null) ? 0 : children.length;
46    }
47  
48    /*** Accept the visitor. **/
49    public Object jjtAccept(DOTParserVisitor visitor, Object data) {
50      return visitor.visit(this, data);
51    }
52  
53    /*** Accept the visitor. **/
54    public Object childrenAccept(DOTParserVisitor visitor, Object data) {
55      if (children != null) {
56        for (int i = 0; i < children.length; ++i) {
57          children[i].jjtAccept(visitor, data);
58        }
59      }
60      return data;
61    }
62  
63    /* You can override these two methods in subclasses of SimpleNode to
64       customize the way the node appears when the tree is dumped.  If
65       your output uses more than one line you should override
66       toString(String), otherwise overriding toString() is probably all
67       you need to do. */
68  
69    public String toString() { return DOTParserTreeConstants.jjtNodeName[id]; }
70    public String toString(String prefix) { return prefix + toString(); }
71  
72    /* Override this method if you want to customize how the node dumps
73       out its children. */
74  
75    public void dump(String prefix) {
76      System.out.println(toString(prefix));
77      if (children != null) {
78        for (int i = 0; i < children.length; ++i) {
79  	SimpleNode n = (SimpleNode)children[i];
80  	if (n != null) {
81  	  n.dump(prefix + " ");
82  	}
83        }
84      }
85    }
86  }
87