KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > persistence > antlr > ASTPair


1 package persistence.antlr;
2
3 /* ANTLR Translator Generator
4  * Project led by Terence Parr at http://www.jGuru.com
5  * Software rights: http://www.antlr.org/license.html
6  *
7  */

8
9 import persistence.antlr.collections.AST;
10
11 /** ASTPair: utility class used for manipulating a pair of ASTs
12  * representing the current AST root and current AST sibling.
13  * This exists to compensate for the lack of pointers or 'var'
14  * arguments in Java.
15  */

16 public class ASTPair {
17     public AST root; // current root of tree
18
public AST child; // current child to which siblings are added
19

20     /** Make sure that child is the last sibling */
21     public final void advanceChildToEnd() {
22         if (child != null) {
23             while (child.getNextSibling() != null) {
24                 child = child.getNextSibling();
25             }
26         }
27     }
28
29     /** Copy an ASTPair. Don't call it clone() because we want type-safety */
30     public ASTPair copy() {
31         ASTPair tmp = new ASTPair();
32         tmp.root = root;
33         tmp.child = child;
34         return tmp;
35     }
36
37     public String JavaDoc toString() {
38         String JavaDoc r = root == null ? "null" : root.getText();
39         String JavaDoc c = child == null ? "null" : child.getText();
40         return "[" + r + "," + c + "]";
41     }
42 }
43
Popular Tags