KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > debugger > jpda > expr > SimpleNode


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

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

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

79
80   public void dump(String JavaDoc prefix) {
81     System.out.println(toString(prefix));
82     if (children != null) {
83       for (int i = 0; i < children.length; ++i) {
84     SimpleNode n = (SimpleNode)children[i];
85     if (n != null) {
86       n.dump(prefix + " ");
87     }
88       }
89     }
90   }
91
92     /*
93     The following section contains code that was added to this class after it was generated by javacc preprocessor.
94     */

95     private Map<String JavaDoc, Object JavaDoc> attributes;
96     // or <String, List<Object>>
97

98     public Object JavaDoc [] getAttributes(String JavaDoc name) {
99         if (attributes == null) return null;
100         List attrs = getAttributeList(name);
101         return attrs.toArray();
102     }
103
104     public void addAttribute(String JavaDoc name, Object JavaDoc value) {
105         getAttributeList(name).add(value);
106     }
107
108     public void setAttribute(String JavaDoc name, Object JavaDoc value) {
109         getAttributeMap().put(name, value);
110     }
111
112     public Object JavaDoc getAttribute(String JavaDoc name) {
113         return (attributes == null) ? null : attributes.get(name);
114     }
115
116     private Map<String JavaDoc, Object JavaDoc> getAttributeMap() {
117         if (attributes == null) {
118             attributes = new HashMap<String JavaDoc, Object JavaDoc>();
119         }
120         return attributes;
121     }
122
123     private List<Object JavaDoc> getAttributeList(String JavaDoc name) {
124         getAttributeMap();
125         List<Object JavaDoc> list = (List<Object JavaDoc>) attributes.get(name);
126         if (list == null) {
127             list = new ArrayList<Object JavaDoc>();
128             attributes.put(name, list);
129         }
130         return list;
131     }
132
133     public int jjtGetID() {
134         return id;
135     }
136 }
137
138
Popular Tags