KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openlaszlo > sc > parser > SimpleNode


1 /* ****************************************************************************
2  * SimpleNode.java
3 * ****************************************************************************/

4
5 /* J_LZ_COPYRIGHT_BEGIN *******************************************************
6 * Copyright 2001-2004 Laszlo Systems, Inc. All Rights Reserved. *
7 * Use is subject to license terms. *
8 * J_LZ_COPYRIGHT_END *********************************************************/

9
10 package org.openlaszlo.sc.parser;
11 import java.io.Serializable JavaDoc;
12
13 public abstract class SimpleNode implements Node, Serializable JavaDoc {
14     protected final static Node[] noChildren = {};
15     protected Node parent;
16     protected Node[] children = noChildren;
17     protected final int id;
18     protected Parser parser;
19     public String JavaDoc filename; // added
20
public int beginLine, beginColumn; // added
21
public String JavaDoc comment;
22   
23     public SimpleNode(int i) {
24         id = i;
25     }
26
27     public SimpleNode(Parser p, int i) {
28         this(i);
29         parser = p;
30     }
31
32     public void jjtOpen() {
33     }
34
35     public void jjtClose() {
36     }
37   
38     public void jjtSetParent(Node n) { parent = n; }
39     public Node jjtGetParent() { return parent; }
40
41     public void jjtAddChild(Node n, int i) {
42         if (i >= children.length) {
43             Node c[] = new Node[i + 1];
44             System.arraycopy(children, 0, c, 0, children.length);
45             children = c;
46         }
47         children[i] = n;
48     }
49
50     public Node jjtGetChild(int i) {
51         return children[i];
52     }
53
54     public int jjtGetNumChildren() {
55         return (children == null) ? 0 : children.length;
56     }
57
58     /* You can override these two methods in subclasses of SimpleNode to
59        customize the way the node appears when the tree is dumped. If
60        your output uses more than one line you should override
61        toString(String), otherwise overriding toString() is probably all
62        you need to do. */

63
64     public String JavaDoc toString(String JavaDoc prefix) { return prefix + toString(); }
65
66     /* Override this method if you want to customize how the node dumps
67        out its children. */

68
69     public void dump(String JavaDoc prefix) {
70         System.out.println(toString(prefix));
71         if (children != null) {
72             for (int i = 0; i < children.length; ++i) {
73                 SimpleNode n = (SimpleNode)children[i];
74                 if (n != null) {
75                     n.dump(prefix + " ");
76                 }
77             }
78         }
79     }
80   
81     public void dump() {
82         dump("");
83     }
84
85     // Added
86

87     public SimpleNode() {
88         this(0);
89     }
90
91     public String JavaDoc toString() {
92         String JavaDoc name = this.getClass().getName();
93         if (name.lastIndexOf('.') >= 0) {
94             name = name.substring(name.lastIndexOf('.') + 1);
95         }
96         return name;
97     }
98
99     public Node[] getChildren() {
100         return children;
101     }
102
103     public void setChildren(Node[] children) {
104         this.children = children;
105     }
106     
107     public Node __getitem__(int n) {
108         return jjtGetChild(n);
109     }
110     
111     public int __len__() {
112         return jjtGetNumChildren();
113     }
114
115     public boolean __nonzero__() {
116         return true;
117     }
118
119     //public void setLineNumber(int line) {
120
// this.beginLine = line;
121
//}
122

123     public int getLineNumber() {
124         return beginLine;
125     }
126     
127     public int getColumnNumber() {
128         return beginColumn;
129     }
130
131     public String JavaDoc getFilename() {
132         return filename;
133     }
134
135     public void setBeginLocation(String JavaDoc filename, int line, int column) {
136         this.filename = filename;
137         this.beginLine = line;
138         this.beginColumn = column;
139     }
140
141     public void setComment(String JavaDoc comment) {
142         this.comment = comment;
143     }
144
145     public String JavaDoc getComment() {
146         return this.comment;
147     }
148 }
149
Popular Tags