dart/ast/visitor library

Defines AST visitors that support useful patterns for visiting the nodes in an AST structure.

Dart is an evolving language, and the AST structure must evolved with it. When the AST structure changes, the visitor interface will sometimes change as well. If it is desirable to get a compilation error when the structure of the AST has been modified, then you should consider implementing the interface AstVisitor directly. Doing so will ensure that changes that introduce new classes of nodes will be flagged. (Of course, not all changes to the AST structure require the addition of a new class of node, and hence cannot be caught this way.)

But if automatic detection of these kinds of changes is not necessary then you will probably want to extend one of the classes in this library because doing so will simplify the task of writing your visitor and guard against future changes to the AST structure. For example, the RecursiveAstVisitor automates the process of visiting all of the descendants of a node.

Classes

BreadthFirstVisitor<R>
An AST visitor that will recursively visit all of the nodes in an AST structure, similar to GeneralizingAstVisitor. This visitor uses a breadth-first ordering rather than the depth-first ordering of GeneralizingAstVisitor.
DelegatingAstVisitor<T>
An AST visitor that will recursively visit all of the nodes in an AST structure. For each node that is visited, the corresponding visit method on one or more other visitors (the 'delegates') will be invoked.
GeneralizingAstVisitor<R>
An AST visitor that will recursively visit all of the nodes in an AST structure (like instances of the class RecursiveAstVisitor). In addition, when a node of a specific type is visited not only will the visit method for that specific type of node be invoked, but additional methods for the superclasses of that node will also be invoked. For example, using an instance of this class to visit a Block will cause the method visitBlock to be invoked but will also cause the methods visitStatement and visitNode to be subsequently invoked. This allows visitors to be written that visit all statements without needing to override the visit method for each of the specific subclasses of Statement.
RecursiveAstVisitor<R>
An AST visitor that will recursively visit all of the nodes in an AST structure. For example, using an instance of this class to visit a Block will also cause all of the statements in the block to be visited.
SimpleAstVisitor<R>
An AST visitor that will do nothing when visiting an AST node. It is intended to be a superclass for classes that use the visitor pattern primarily as a dispatch mechanism (and hence don't need to recursively visit a whole structure) and that only need to visit a small number of node types.
ThrowingAstVisitor<R>
An AST visitor that will throw an exception if any of the visit methods that are invoked have not been overridden. It is intended to be a superclass for classes that implement the visitor pattern and need to (a) override all of the visit methods or (b) need to override a subset of the visit method and want to catch when any other visit methods have been invoked.
TimedAstVisitor<T>
An AST visitor that captures visit call timings.
UnifyingAstVisitor<R>
An AST visitor that will recursively visit all of the nodes in an AST structure (like instances of the class RecursiveAstVisitor). In addition, every node will also be visited by using a single unified visitNode method.