FileDocCategorySizeDatePackage
DumpASTVisitor.javaAPI DocGlassfish v2 API1677Wed Aug 30 15:34:06 BST 2006persistence.antlr

DumpASTVisitor

public class DumpASTVisitor extends Object implements ASTVisitor
Simple class to dump the contents of an AST to the output

Fields Summary
protected int
level
Constructors Summary
Methods Summary
private voidtabs()



       
        for (int i = 0; i < level; i++) {
            System.out.print("   ");
        }
    
public voidvisit(persistence.antlr.collections.AST node)

        // Flatten this level of the tree if it has no children
        boolean flatten = /*true*/ false;
        AST node2;
        for (node2 = node; node2 != null; node2 = node2.getNextSibling()) {
            if (node2.getFirstChild() != null) {
                flatten = false;
                break;
            }
        }

        for (node2 = node; node2 != null; node2 = node2.getNextSibling()) {
            if (!flatten || node2 == node) {
                tabs();
            }
            if (node2.getText() == null) {
                System.out.print("nil");
            }
            else {
                System.out.print(node2.getText());
            }

            System.out.print(" [" + node2.getType() + "] ");

            if (flatten) {
                System.out.print(" ");
            }
            else {
                System.out.println("");
            }

            if (node2.getFirstChild() != null) {
                level++;
                visit(node2.getFirstChild());
                level--;
            }
        }

        if (flatten) {
            System.out.println("");
        }