1
2
3
4
5 package xjavadoc;
6
7 public class SimpleNode implements Node
8 {
9
10 public static int instanceCount = 0;
11 protected Node parent;
12 protected Node[] children;
13 protected int id;
14 protected JavaParser parser;
15 protected Token first, last;
16
17 public SimpleNode( int i )
18 {
19 id = i;
20 instanceCount++;
21 }
22
23 public SimpleNode( final JavaParser p, int i )
24 {
25 this( i );
26 parser = p;
27 }
28
29 /***
30 * Returns our position under our parent.
31 *
32 * @return our position under our parent.
33 */
34 public int getPosition()
35 {
36 int i;
37
38 for( i = 0; i < jjtGetParent().jjtGetNumChildren(); i++ )
39 {
40 if( jjtGetParent().jjtGetChild( i ) == this )
41 {
42 break;
43 }
44 }
45 return i;
46 }
47
48 public Token getFirstToken()
49 {
50 return first;
51 }
52
53 public Token getLastToken()
54 {
55 return last;
56 }
57
58 public String getType()
59 {
60 return NodeParserTreeConstants.jjtNodeName[id];
61 }
62
63 public void jjtOpen()
64 {
65 first = parser.getToken( 1 );
66 }
67
68 public void jjtClose()
69 {
70 last = parser.getToken( 0 );
71 }
72
73 public void jjtSetParent( Node n )
74 {
75 parent = n;
76 }
77
78 public Node jjtGetParent()
79 {
80 return parent;
81 }
82
83 public void jjtAddChild( Node n, int i )
84 {
85 if( children == null )
86 {
87 children = new Node[i + 1];
88 }
89 else if( i >= children.length )
90 {
91 Node c[] = new Node[i + 1];
92
93 System.arraycopy( children, 0, c, 0, children.length );
94 children = c;
95 }
96 children[i] = n;
97 }
98
99 public Node jjtGetChild( int i )
100 {
101 return children[i];
102 }
103
104 public int jjtGetNumChildren()
105 {
106 return ( children == null ) ? 0 : children.length;
107 }
108
109 public String toString()
110 {
111 return getType();
112 }
113
114 public String toString( String prefix )
115 {
116 return prefix + toString();
117 }
118
119 public String dump()
120 {
121 StringBuffer sb = new StringBuffer();
122
123 dump( sb, " " );
124 return sb.toString();
125 }
126
127 private void dump( StringBuffer sb, String prefix )
128 {
129 sb.append( toString( prefix ) ).append( System.getProperty( "line.separator" ) );
130
131 if( children != null )
132 {
133 for( int i = 0; i < children.length; ++i )
134 {
135 SimpleNode n = ( SimpleNode ) children[i];
136
137 if( n != null )
138 {
139 n.dump( sb, prefix + prefix );
140 }
141 }
142 }
143 }
144 }
145