KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SimpleNode


1
2 /*
3  * Copyright © 2002 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
4  * California 95054, U.S.A. All rights reserved. Sun Microsystems, Inc. has
5  * intellectual property rights relating to technology embodied in the product
6  * that is described in this document. In particular, and without limitation,
7  * these intellectual property rights may include one or more of the U.S.
8  * patents listed at http://www.sun.com/patents and one or more additional
9  * patents or pending patent applications in the U.S. and in other countries.
10  * U.S. Government Rights - Commercial software. Government users are subject
11  * to the Sun Microsystems, Inc. standard license agreement and applicable
12  * provisions of the FAR and its supplements. Use is subject to license terms.
13  * Sun, Sun Microsystems, the Sun logo and Java are trademarks or registered
14  * trademarks of Sun Microsystems, Inc. in the U.S. and other countries. This
15  * product is covered and controlled by U.S. Export Control laws and may be
16  * subject to the export or import laws in other countries. Nuclear, missile,
17  * chemical biological weapons or nuclear maritime end uses or end users,
18  * whether direct or indirect, are strictly prohibited. Export or reexport
19  * to countries subject to U.S. embargo or to entities identified on U.S.
20  * export exclusion lists, including, but not limited to, the denied persons
21  * and specially designated nationals lists is strictly prohibited.
22  */

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

72
73   public String JavaDoc toString() { return ToyParserTreeConstants.jjtNodeName[id]; }
74   public String JavaDoc toString(String JavaDoc prefix) { return prefix + toString(); }
75
76   /* Override this method if you want to customize how the node dumps
77      out its children. */

78
79   public void dump(String JavaDoc prefix) {
80     System.out.println(toString(prefix));
81     if (children != null) {
82       for (int i = 0; i < children.length; ++i) {
83     SimpleNode n = (SimpleNode)children[i];
84     if (n != null) {
85       n.dump(prefix + " ");
86     }
87       }
88     }
89   }
90
91 // Manually inserted code begins here
92

93   protected Token begin, end;
94   public void setFirstToken(Token t) { begin = t; }
95   public void setLastToken(Token t) { end = t; }
96
97   public void process (PrintWriter JavaDoc ostr) {
98     System.out.println("Error - this should not be called");
99     throw new Error JavaDoc();
100   }
101
102   // The following method prints token t, as well as all preceding
103
// special tokens (essentially, white space and comments).
104

105   protected void print(Token t, PrintWriter JavaDoc ostr) {
106     Token tt = t.specialToken;
107     if (tt != null) {
108       while (tt.specialToken != null) tt = tt.specialToken;
109       while (tt != null) {
110         ostr.print(addUnicodeEscapes(tt.image));
111         tt = tt.next;
112       }
113     }
114     ostr.print(addUnicodeEscapes(t.image));
115   }
116
117   private String JavaDoc addUnicodeEscapes(String JavaDoc str) {
118     String JavaDoc retval = "";
119     char ch;
120     for (int i = 0; i < str.length(); i++) {
121       ch = str.charAt(i);
122       if ((ch < 0x20 || ch > 0x7e) && ch != '\t' && ch != '\n' && ch != '\r' && ch != '\f') {
123     String JavaDoc s = "0000" + Integer.toString(ch, 16);
124     retval += "\\u" + s.substring(s.length() - 4, s.length());
125       } else {
126         retval += ch;
127       }
128     }
129     return retval;
130   }
131 }
132
133
Popular Tags