xtc.tree
Class Visitor

java.lang.Object
  extended by xtc.tree.Visitor
Direct Known Subclasses:
Annotator, Annotator.Detector, Annotator.Rewriter, CodeGenerator, Copier, CostEstimator, DirectLeftRecurser, ElementVoider, EquivalenceTester, Generifier, GrammarVisitor, LeftRecurser, ListMaker, MetaDataCreator, MetaDataSetter, ParseTreePrinter, ParseTreeStripper, PrettyPrinter, ReachabilityChecker, Relocator, Resolver, SourcePrinter, TextTester, Tokenizer.Tester, Transducer, Transformer, Transformer.Deducer, Transformer.Desugarer, Transformer.Typer, TreeExtractor, TreeTyper, TypePrinter, ValueChecker, VariantSorter, VariantSorter.Registrar, VariantSorter.Typer

public abstract class Visitor
extends java.lang.Object

The superclass of all node visitors.

Nodes may contain children that are lists of nodes. To simplify the processing of such lists with visitors, this class defines three helper methods that apply a visitor to a list of nodes:

Additonally, Node provides helper methods to dynamically test and cast lists of nodes through Node.isList(Object) and Node.toList(Object) respectively.

Version:
$Revision: 1.31 $
Author:
Robert Grimm

Constructor Summary
Visitor()
          Create a new visitor.
 
Method Summary
 java.lang.Object dispatch(Node n)
          Dispatch this visitor on the specified node.
 boolean equals(java.lang.Object o)
          Determine whether this visitor equals the specified object.
 int hashCode()
          Get a hashcode for this visitor.
 void iterate(Pair<? extends Node> list)
          Iterate this visitor over the specified list.
<T> Pair<T>
map(Pair<? extends Node> list)
          Map this visitor over the specified list.
<T extends Node>
Pair<T>
mapInPlace(Pair<T> list)
          Map this visitor over the specified list while also updating the list.
 java.lang.Object unableToVisit(Node node)
          Signal that this visitor has no visit() method for the specified node.
 java.lang.Object visit(Annotation a)
          Visit the specified annotation.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Visitor

public Visitor()
Create a new visitor.

Method Detail

hashCode

public final int hashCode()
Get a hashcode for this visitor.

Overrides:
hashCode in class java.lang.Object
Returns:
The identity hashcode.

equals

public final boolean equals(java.lang.Object o)
Determine whether this visitor equals the specified object.

Overrides:
equals in class java.lang.Object
Parameters:
o - The object to compare to.
Returns:
true if the specified object is this visitor.

visit

public java.lang.Object visit(Annotation a)
Visit the specified annotation. This method simply applies this visitor on the node referenced by the annotation, thus ignoring the annotation.

Parameters:
a - The annotation.
Returns:
The result of applying this visitor on the referenced node.

dispatch

public final java.lang.Object dispatch(Node n)
Dispatch this visitor on the specified node. This method determines the closest matching visit() method, invokes it on the specified node, and returns the result. If the specified node is null or the selected method returns void, this method returns null.

Parameters:
n - The node.
Returns:
The result of dispatching this visitor on the specified node.
Throws:
VisitorException - Signals that no matching visit() method could be found.
VisitingException - Signals an exceptional condition while applying the specified visitor on this node.
See Also:
unableToVisit(Node)

unableToVisit

public java.lang.Object unableToVisit(Node node)
Signal that this visitor has no visit() method for the specified node. The default implementation simply raises a visitor exception.

Parameters:
node - The node.
Returns:
The result of processing the node.
Throws:
VisitorException - Signals that no matching visit() method could be found.

iterate

public void iterate(Pair<? extends Node> list)
Iterate this visitor over the specified list.

Parameters:
list - The list.

map

public <T> Pair<T> map(Pair<? extends Node> list)
Map this visitor over the specified list.

Parameters:
list - The list.
Returns:
The list of results.

mapInPlace

public <T extends Node> Pair<T> mapInPlace(Pair<T> list)
Map this visitor over the specified list while also updating the list.

Parameters:
list - The list.
Returns:
The updated list.


Copyright © 2012. All Rights Reserved.