001: /* Generated By:JJTree: Do not edit this line. SimpleNode.java */
002:
003: package jaxx.css;
004:
005: public class SimpleNode implements Node {
006: protected Node parent;
007: protected Node[] children;
008: protected int id;
009: protected CSSParser parser;
010: public Token firstToken;
011: public Token lastToken;
012:
013: public SimpleNode(int i) {
014: id = i;
015: }
016:
017: public SimpleNode(CSSParser p, int i) {
018: this (i);
019: parser = p;
020: }
021:
022: public int getId() {
023: return id;
024: }
025:
026: public void jjtOpen() {
027: }
028:
029: public void jjtClose() {
030: }
031:
032: public void jjtSetParent(Node n) {
033: parent = n;
034: }
035:
036: public Node jjtGetParent() {
037: return parent;
038: }
039:
040: public SimpleNode getParent() {
041: return (SimpleNode) parent;
042: }
043:
044: public void jjtAddChild(Node n, int i) {
045: if (children == null) {
046: children = new Node[i + 1];
047: } else if (i >= children.length) {
048: Node c[] = new Node[i + 1];
049: System.arraycopy(children, 0, c, 0, children.length);
050: children = c;
051: }
052: children[i] = n;
053: }
054:
055: public Node jjtGetChild(int i) {
056: return children[i];
057: }
058:
059: public SimpleNode getChild(int i) {
060: return (SimpleNode) children[i];
061: }
062:
063: public int jjtGetNumChildren() {
064: return (children == null) ? 0 : children.length;
065: }
066:
067: /* You can override these two methods in subclasses of SimpleNode to
068: customize the way the node appears when the tree is dumped. If
069: your output uses more than one line you should override
070: toString(String), otherwise overriding toString() is probably all
071: you need to do. */
072:
073: public String toString() {
074: return getClass().getName() + "[" + getText() + "]";
075: }
076:
077: public String toString(String prefix) {
078: return prefix + toString();
079: }
080:
081: /* Override this method if you want to customize how the node dumps
082: out its children. */
083:
084: public void dump(String prefix) {
085: System.out.println(toString(prefix));
086: if (children != null) {
087: for (int i = 0; i < children.length; ++i) {
088: SimpleNode n = (SimpleNode) children[i];
089: if (n != null) {
090: n.dump(prefix + " ");
091: }
092: }
093: }
094: }
095:
096: private void appendSpecialTokens(StringBuffer s, Token st) {
097: if (st != null) {
098: appendSpecialTokens(s, st.specialToken);
099: s.append(st.image);
100: }
101: }
102:
103: /**
104: Get the text of the tokens comprising this node.
105: */
106: public String getText() {
107: StringBuffer text = new StringBuffer();
108: Token t = firstToken;
109: while (t != null) {
110: appendSpecialTokens(text, t.specialToken);
111: text.append(t.image);
112: if (t == lastToken)
113: break;
114: t = t.next;
115: }
116:
117: return text.toString();
118: }
119: }
|