KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > umd > cs > findbugs > tools > patcomp > SimpleNode


1 /* Generated By:JJTree: Do not edit this line. SimpleNode.java */
2
3 package edu.umd.cs.findbugs.tools.patcomp;
4
5 public class SimpleNode implements Node {
6   protected Node parent;
7   protected Node[] children;
8   protected int id;
9   protected PatternCompiler parser;
10
11   /* DHH: added these fields to keep track of tokens */
12   private Token firstToken, lastToken;
13
14   public SimpleNode(int i) {
15     id = i;
16   }
17
18   public SimpleNode(PatternCompiler p, int i) {
19     this(i);
20     parser = p;
21   }
22
23   /** Get the id of this node. */
24   public int getId() {
25     return id;
26   }
27
28   /** Set first token. */
29   public void setFirstToken(Token t) {
30     if (t == null) throw new IllegalStateException JavaDoc();
31     this.firstToken = t;
32   }
33
34   /** Get the first token. */
35   public Token getFirstToken() {
36     return firstToken;
37   }
38
39   /** Set last token. */
40   public void setLastToken(Token t) {
41     if (t == null) throw new IllegalStateException JavaDoc();
42     this.lastToken = t;
43   }
44
45   /** Get the last token. */
46   public Token getLastToken() {
47     return lastToken;
48   }
49
50   /** Get number of tokens. */
51   public int getNumTokens() {
52     int count = 0;
53     Token cur = firstToken;
54     while (cur != lastToken) {
55       ++count;
56       cur = cur.next;
57     }
58     return count;
59   }
60
61   /**
62    * Get <i>n</i>th token.
63    * Returns null if there are fewer than <i>n+1</i> tokens.
64    */

65   public Token getToken(int n) {
66     Token t = firstToken;
67     int count = 0;
68     while (t != null) {
69       if (count == n)
70         break;
71       ++count;
72       t = t.next;
73     }
74     return t;
75   }
76
77   public void jjtOpen() {
78   }
79
80   public void jjtClose() {
81   }
82   
83   public void jjtSetParent(Node n) { parent = n; }
84   public Node jjtGetParent() { return parent; }
85
86   public void jjtAddChild(Node n, int i) {
87     if (children == null) {
88       children = new Node[i + 1];
89     } else if (i >= children.length) {
90       Node c[] = new Node[i + 1];
91       System.arraycopy(children, 0, c, 0, children.length);
92       children = c;
93     }
94     children[i] = n;
95   }
96
97   public Node jjtGetChild(int i) {
98     return children[i];
99   }
100
101   public int jjtGetNumChildren() {
102     return (children == null) ? 0 : children.length;
103   }
104
105   /* You can override these two methods in subclasses of SimpleNode to
106      customize the way the node appears when the tree is dumped. If
107      your output uses more than one line you should override
108      toString(String), otherwise overriding toString() is probably all
109      you need to do. */

110
111   public String JavaDoc toString() { return PatternCompilerTreeConstants.jjtNodeName[id]; }
112   public String JavaDoc toString(String JavaDoc prefix) { return prefix + toString(); }
113
114   /* Override this method if you want to customize how the node dumps
115      out its children. */

116
117   public void dump(String JavaDoc prefix) {
118     System.out.println(toString(prefix));
119     if (children != null) {
120         for (Node aChildren : children) {
121             SimpleNode n = (SimpleNode) aChildren;
122             if (n != null) {
123                 n.dump(prefix + " ");
124             }
125         }
126     }
127   }
128 }
129
130
Popular Tags