001: /* Generated By:JJTree: Do not edit this line. SimpleNode.java */
002:
003: package de.gulden.util.javasource.jjt;
004:
005: public class SimpleNode implements Node {
006: protected Node parent;
007: protected Node[] children;
008: protected int id;
009: protected Parser parser;
010:
011: public SimpleNode(int i) {
012: id = i;
013: }
014:
015: public SimpleNode(Parser p, int i) {
016: this (i);
017: parser = p;
018: }
019:
020: public void jjtOpen() {
021: }
022:
023: public void jjtClose() {
024: }
025:
026: public void jjtSetParent(Node n) {
027: parent = n;
028: }
029:
030: public Node jjtGetParent() {
031: return parent;
032: }
033:
034: public void jjtAddChild(Node n, int i) {
035: if (children == null) {
036: children = new Node[i + 1];
037: } else if (i >= children.length) {
038: Node c[] = new Node[i + 1];
039: System.arraycopy(children, 0, c, 0, children.length);
040: children = c;
041: }
042: children[i] = n;
043: }
044:
045: public Node jjtGetChild(int i) {
046: return children[i];
047: }
048:
049: public int jjtGetNumChildren() {
050: return (children == null) ? 0 : children.length;
051: }
052:
053: /* You can override these two methods in subclasses of SimpleNode to
054: customize the way the node appears when the tree is dumped. If
055: your output uses more than one line you should override
056: toString(String), otherwise overriding toString() is probably all
057: you need to do. */
058:
059: public String toString() {
060: return ParserTreeConstants.jjtNodeName[id];
061: }
062:
063: public String toString(String prefix) {
064: return prefix + toString();
065: }
066:
067: /* Override this method if you want to customize how the node dumps
068: out its children. */
069:
070: public void dump(String prefix) {
071: System.out.println(toString(prefix));
072: if (children != null) {
073: for (int i = 0; i < children.length; ++i) {
074: SimpleNode n = (SimpleNode) children[i];
075: if (n != null) {
076: n.dump(prefix + " ");
077: }
078: }
079: }
080: }
081:
082: /*** added by Jens *********************************************************/
083:
084: private final static Node[] EMPTY = new Node[0];
085:
086: protected String value;
087: protected Token[] tokenRange = new Token[2];
088: protected TextImage textImage;
089: protected String source;
090:
091: public int getId() {
092: return id;
093: }
094:
095: /**
096: * Get first child with id.
097: */
098: public Node getChild(int id) {
099: if (children != null) {
100: for (int i = 0; i < children.length; i++) {
101: if (children[i].getId() == id) {
102: return children[i];
103: }
104: }
105: }
106: return null;
107: }
108:
109: public boolean hasChild(int id) {
110: return (getChild(id) != null);
111: }
112:
113: public Node[] getChildren(int id) {
114: if (children != null) {
115: java.util.Vector v = new java.util.Vector(5);
116: for (int i = 0; i < children.length; i++) {
117: if (children[i].getId() == id) {
118: v.addElement(children[i]);
119: }
120: }
121: Node[] n = new Node[v.size()];
122: v.copyInto(n);
123: return n;
124: } else {
125: return EMPTY;
126: }
127: }
128:
129: public Node[] getAllChildren() {
130: if (children != null) {
131: return children;
132: } else {
133: return EMPTY;
134: }
135: }
136:
137: public String getValue() {
138: return value;
139: }
140:
141: public void setValue(String v) {
142: //System.out.print(v+" ");
143: value = v;
144: }
145:
146: public String getName() {
147: Node node = getChild(ParserTreeConstants.JJT_NAME);
148: if (node != null) {
149: return node.retrieveName();
150: } else {
151: return null;
152: }
153: }
154:
155: public String retrieveName() {
156: String name;
157: int num = jjtGetNumChildren();
158: if (num == 1) // optimization: single child node _IDENTIFIER
159: {
160: Node n = jjtGetChild(0);
161: name = n.getValue();
162: } else // general case: name identifiers joined by dots
163: {
164: StringBuffer sb = new StringBuffer();
165: for (int i = 0; i < num; i += 2) {
166: //Node child=node.jjtGetChild(i).getValue();
167: String n = jjtGetChild(i).getValue();
168: sb.append(n);
169: if (i + 1 < num) {
170: // next one must be _DOT
171: sb.append(".");
172: }
173: }
174: name = sb.toString();
175: }
176: return name;
177: }
178:
179: public void setStartToken(Token t) {
180: tokenRange[0] = t;
181: }
182:
183: public void setEndToken(Token t) {
184: tokenRange[1] = t;
185: }
186:
187: public Token getStartToken() {
188: return tokenRange[0];
189: }
190:
191: public Token getEndToken() {
192: return tokenRange[1];
193: }
194:
195: public void setTextImage(TextImage ti) {
196: textImage = ti;
197: }
198:
199: public TextImage getTextImage() {
200: return textImage;
201: }
202:
203: public String getSource() {
204: return source;
205: }
206:
207: public void setSource(String source) {
208: this .source = source;
209: }
210:
211: public int[] getSourcePosition() {
212: int[] pos = { getStartToken().beginLine,
213: getStartToken().beginColumn };
214: return pos;
215: }
216: }
|