KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejen > util > arl > SimpleNode


1 /* Generated By:JJTree: Do not edit this line. SimpleNode.java */
2 //
3
// Ejen (code generation system)
4
// Copyright (C) 2001, 2002 François Wolff (ejen@noos.fr).
5
//
6
// This file is part of Ejen.
7
//
8
// Ejen is free software; you can redistribute it and/or modify
9
// it under the terms of the GNU General Public License as published by
10
// the Free Software Foundation; either version 2 of the License, or
11
// (at your option) any later version.
12
//
13
// Ejen is distributed in the hope that it will be useful,
14
// but WITHOUT ANY WARRANTY; without even the implied warranty of
15
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
// GNU General Public License for more details.
17
//
18
// You should have received a copy of the GNU General Public License
19
// along with Ejen; if not, write to the Free Software
20
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
//
22
package org.ejen.util.arl;
23
24 public class SimpleNode implements Node {
25     protected Node parent;
26     protected Node[] children;
27     protected int id;
28     protected ArlParser parser;
29     // New ---------------------------
30
protected Token first, last;
31     // --------------------------- New
32
public SimpleNode(int i) {
33         id = i;
34     }
35
36     public SimpleNode(ArlParser p, int i) {
37         this(i);
38         parser = p;
39     }
40
41     public void jjtOpen() {
42         // New ---------------------------
43
first = parser.getToken(1);
44         // --------------------------- New
45
}
46
47     public void jjtClose() {
48         // New ---------------------------
49
last = parser.getToken(0);
50         // --------------------------- New
51
}
52
53     // New ---------------------------
54
public Token getFirstToken() {
55         return first;
56     }
57
58     public Token getLastToken() {
59         return last;
60     }
61
62     // --------------------------- New
63

64     public void jjtSetParent(Node n) {
65         parent = n;
66     }
67
68     public Node jjtGetParent() {
69         return parent;
70     }
71
72     public void jjtAddChild(Node n, int i) {
73         if (children == null) {
74             children = new Node[i + 1];
75         } else if (i >= children.length) {
76             Node c[] = new Node[i + 1];
77
78             System.arraycopy(children, 0, c, 0, children.length);
79             children = c;
80         }
81         children[i] = n;
82     }
83
84     public Node jjtGetChild(int i) {
85         return children[i];
86     }
87
88     public int jjtGetNumChildren() {
89         return (children == null) ? 0 : children.length;
90     }
91
92     /* You can override these two methods in subclasses of SimpleNode to
93      customize the way the node appears when the tree is dumped. If
94      your output uses more than one line you should override
95      toString(String), otherwise overriding toString() is probably all
96      you need to do. */

97     public String JavaDoc toString() {
98         return ArlParserTreeConstants.jjtNodeName[id];
99     }
100
101     public String JavaDoc toString(String JavaDoc prefix) {
102         return prefix + toString();
103     }
104
105     /* Override this method if you want to customize how the node dumps
106      out its children. */

107     public void dump(String JavaDoc prefix) {
108         System.out.println(toString(prefix));
109         if (children != null) {
110             for (int i = 0; i < children.length; ++i) {
111                 SimpleNode n = (SimpleNode) children[i];
112
113                 if (n != null) {
114                     n.dump(prefix + " ");
115                 }
116             }
117         }
118     }
119 }
120
Popular Tags