001: /* Generated By:JJTree: Do not edit this line. SimpleNode.java Version 4.1 */
002: /* JavaCCOptions:MULTI=false,NODE_USES_PARSER=false,VISITOR=false,TRACK_TOKENS=true,NODE_PREFIX=AST,NODE_EXTENDS=,NODE_FACTORY= */
003: package org.netbeans.modules.css.parser;
004:
005: public class SimpleNode implements Node {
006:
007: protected Node parent;
008: protected Node[] children;
009: protected int id;
010: protected Object value;
011: protected CSSParser parser;
012: protected Token firstToken;
013: protected Token lastToken;
014: private String image;
015:
016: public SimpleNode(int i) {
017: id = i;
018: }
019:
020: public SimpleNode(CSSParser p, int i) {
021: this (i);
022: parser = p;
023: }
024:
025: public int kind() {
026: return id;
027: }
028:
029: public int startOffset() {
030: return jjtGetFirstToken().offset;
031: }
032:
033: public int endOffset() {
034: //why this happens???
035: if (jjtGetLastToken().image == null) {
036: System.err.println("ERROR: lastToken image is null! : "
037: + jjtGetLastToken());
038: return jjtGetLastToken().offset;
039: } else {
040: return jjtGetLastToken().offset
041: + jjtGetLastToken().image.length();
042: }
043: }
044:
045: public String image() {
046: synchronized (this ) {
047: if (image == null) {
048: StringBuffer sb = new StringBuffer();
049: if (jjtGetFirstToken() == jjtGetLastToken()) {
050: image = jjtGetFirstToken().image;
051: } else {
052: Token t = jjtGetFirstToken();
053: Token last = jjtGetLastToken();
054: while (t != null && t.offset <= last.offset) { //also include the last token
055: sb.append(t.image);
056: t = t.next;
057: }
058: image = sb.toString();
059: }
060: }
061:
062: return image;
063: }
064: }
065:
066: public void jjtOpen() {
067: }
068:
069: public void jjtClose() {
070: }
071:
072: public void jjtSetParent(Node n) {
073: parent = n;
074: }
075:
076: public Node jjtGetParent() {
077: return parent;
078: }
079:
080: public void jjtAddChild(Node n, int i) {
081: if (children == null) {
082: children = new Node[i + 1];
083: } else if (i >= children.length) {
084: Node c[] = new Node[i + 1];
085: System.arraycopy(children, 0, c, 0, children.length);
086: children = c;
087: }
088: children[i] = n;
089: }
090:
091: public Node jjtGetChild(int i) {
092: return children[i];
093: }
094:
095: public int jjtGetNumChildren() {
096: return (children == null) ? 0 : children.length;
097: }
098:
099: public void jjtSetValue(Object value) {
100: this .value = value;
101: }
102:
103: public Object jjtGetValue() {
104: return value;
105: }
106:
107: public Token jjtGetFirstToken() {
108: return firstToken;
109: }
110:
111: public void jjtSetFirstToken(Token token) {
112: this .firstToken = token;
113: }
114:
115: public Token jjtGetLastToken() {
116: return lastToken;
117: }
118:
119: public void jjtSetLastToken(Token token) {
120: this .lastToken = token;
121: }
122:
123: /* You can override these two methods in subclasses of SimpleNode to
124: customize the way the node appears when the tree is dumped. If
125: your output uses more than one line you should override
126: toString(String), otherwise overriding toString() is probably all
127: you need to do. */
128: public String toString() {
129: return CSSParserTreeConstants.jjtNodeName[id] + " ["
130: + startOffset() + " - " + endOffset() + "]";
131: }
132:
133: public String toString(String prefix) {
134: return prefix + toString();
135: }
136:
137: /* Override this method if you want to customize how the node dumps
138: out its children. */
139: public void dump(String prefix) {
140: System.out.println(toString(prefix));
141: if (children != null) {
142: for (int i = 0; i < children.length; ++i) {
143: SimpleNode n = (SimpleNode) children[i];
144: if (n != null) {
145: n.dump(prefix + " ");
146: }
147: }
148: }
149: }
150:
151: public void visitChildren(NodeVisitor visitor) {
152: if (children != null) {
153: for (int i = 0; i < children.length; ++i) {
154: SimpleNode n = (SimpleNode) children[i];
155: if (n != null) {
156: visitor.visit(n);
157: n.visitChildren(visitor);
158: }
159: }
160: }
161: }
162: }
163:
164: /* JavaCC - OriginalChecksum=0f675acc04cfd880a8baf2208510fa8c (do not edit this line) */
|