edu.rice.cs.dynamicjava.symbol.type
Class TreeWalker

java.lang.Object
  extended by edu.rice.cs.dynamicjava.symbol.type.TreeWalker
Direct Known Subclasses:
ToStringWalker

public abstract class TreeWalker
extends java.lang.Object

A lightweight visitor for traversing (in depth-first order) arbitrary ASTGen-produced trees. Unlike the Visitor classes generated for a specific AST, implementations of TreeWalker are defined for all ASTs. They are more limited, having far fewer hooks available for manipulating the traversal process and handling different types of nodes. This minimal interface is enough, however, for simple visitors which aren't concerned with the semantic content of a tree and simply need to traverse its structure.

When passed to a node's walk() method, a TreeWalker can expect to receive a specific sequence of method calls: visitNode(java.lang.Object, java.lang.String, int), then #visitField and a recursive invocation for each of the node's fields. "Recursive invocations" include additional visitNode() calls and invocations of the the other "visit" methods for handling Strings, lists, primitives, and objects of unrecognized type. (Note that the method to call is determined statically based on the field's declared type, not at runtime.) Clients can prevent recursion into a non-atomic element's children by returning false in the appropriate visit method.


Constructor Summary
TreeWalker()
           
 
Method Summary
 void endIterated(java.lang.Object iterable, int size)
          Signal the end of a sequence of iterated elements.
 void endIteratedElement(int index, java.lang.Object element)
          Signal the end of recursion on an iterated element.
 void endNode(java.lang.Object node, java.lang.String type, int fields)
          Signal the end of a sequence of node fields.
 void endNodeField(java.lang.String name, java.lang.Object value)
          Signal the end of recursion on an AST node's field.
 void endNonEmptyOption(java.lang.Object option)
          Signal the end of recursion on a non-empty option.
 void endTuple(java.lang.Object tuple, int arity)
          Signal the end of a sequence of tuple elements.
 void endTupleElement(int index, java.lang.Object element)
          Signal the end of a tuple element.
 void visitBoolean(boolean b)
          Visit a boolean primitive.
 void visitByte(byte b)
          Visit a byte primitive.
 void visitChar(char c)
          Visit a char primitive.
 void visitDouble(double d)
          Visit a double primitive.
 void visitEmptyOption(java.lang.Object option)
          Visit an empty option-typed value.
 void visitFloat(float f)
          Visit a float primitive.
 void visitInt(int i)
          Visit a int primitive.
 boolean visitIterated(java.lang.Object iterable)
          Visit an Iterable or array.
 boolean visitIteratedElement(int index, java.lang.Object element)
          Visit an iterated element.
 void visitLong(long l)
          Visit a long primitive.
 boolean visitNode(java.lang.Object node, java.lang.String type, int fields)
          Visit an AST node.
 boolean visitNodeField(java.lang.String name, java.lang.Object value)
          Visit an AST node's field.
 boolean visitNonEmptyOption(java.lang.Object option)
          Visit a non-empty option-typed value.
 void visitNull()
          Visit a null reference.
 void visitShort(short s)
          Visit a short primitive.
 void visitString(java.lang.String s)
          Visit a string value.
 boolean visitTuple(java.lang.Object tuple, int arity)
          Visit a tuple-typed value.
 boolean visitTupleElement(int index, java.lang.Object element)
          Visit a tuple element.
 void visitUnknownObject(java.lang.Object o)
          Visit an object that is not known statically to have an AST Node or other supported type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TreeWalker

public TreeWalker()
Method Detail

visitNode

public boolean visitNode(java.lang.Object node,
                         java.lang.String type,
                         int fields)
Visit an AST node. Return true to recur on each of the node's fields.


visitNodeField

public boolean visitNodeField(java.lang.String name,
                              java.lang.Object value)
Visit an AST node's field. Return true to recur on the field's value.


endNodeField

public void endNodeField(java.lang.String name,
                         java.lang.Object value)
Signal the end of recursion on an AST node's field.


endNode

public void endNode(java.lang.Object node,
                    java.lang.String type,
                    int fields)
Signal the end of a sequence of node fields.


visitIterated

public boolean visitIterated(java.lang.Object iterable)
Visit an Iterable or array. Return true to recur on each element.


visitIteratedElement

public boolean visitIteratedElement(int index,
                                    java.lang.Object element)
Visit an iterated element. Return true to recur on the element value.


endIteratedElement

public void endIteratedElement(int index,
                               java.lang.Object element)
Signal the end of recursion on an iterated element.


endIterated

public void endIterated(java.lang.Object iterable,
                        int size)
Signal the end of a sequence of iterated elements.


visitNonEmptyOption

public boolean visitNonEmptyOption(java.lang.Object option)
Visit a non-empty option-typed value. Return true to recur on the nested value.


endNonEmptyOption

public void endNonEmptyOption(java.lang.Object option)
Signal the end of recursion on a non-empty option.


visitEmptyOption

public void visitEmptyOption(java.lang.Object option)
Visit an empty option-typed value.


visitTuple

public boolean visitTuple(java.lang.Object tuple,
                          int arity)
Visit a tuple-typed value. Return true to recur on the nested elements.


visitTupleElement

public boolean visitTupleElement(int index,
                                 java.lang.Object element)
Visit a tuple element. Return true to recur on the element value.


endTupleElement

public void endTupleElement(int index,
                            java.lang.Object element)
Signal the end of a tuple element.


endTuple

public void endTuple(java.lang.Object tuple,
                     int arity)
Signal the end of a sequence of tuple elements.


visitString

public void visitString(java.lang.String s)
Visit a string value.


visitUnknownObject

public void visitUnknownObject(java.lang.Object o)
Visit an object that is not known statically to have an AST Node or other supported type.


visitNull

public void visitNull()
Visit a null reference. This is called rather than visitNode, visitList, visitUnknownObject, etc., where a field or element's value is null.


visitBoolean

public void visitBoolean(boolean b)
Visit a boolean primitive.


visitChar

public void visitChar(char c)
Visit a char primitive.


visitByte

public void visitByte(byte b)
Visit a byte primitive.


visitShort

public void visitShort(short s)
Visit a short primitive.


visitInt

public void visitInt(int i)
Visit a int primitive.


visitLong

public void visitLong(long l)
Visit a long primitive.


visitFloat

public void visitFloat(float f)
Visit a float primitive.


visitDouble

public void visitDouble(double d)
Visit a double primitive.