visitor library Null safety
Defines element visitors that support useful patterns for visiting the elements in an element model.
Dart is an evolving language, and the element model must evolved with it. When the element model changes, the visitor interface will sometimes change as well. If it is desirable to get a compilation error when the structure of the element model has been modified, then you should consider implementing the interface ElementVisitor directly. Doing so will ensure that changes that introduce new classes of elements will be flagged. (Of course, not all changes to the element model require the addition of a new class of element, 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 element model. For example, the RecursiveElementVisitor automates the process of visiting all of the descendants of an element.
- An element visitor that will recursively visit all of the elements in an element model (like instances of the class RecursiveElementVisitor). In addition, when an element of a specific type is visited not only will the visit method for that specific type of element be invoked, but additional methods for the supertypes of that element will also be invoked. For example, using an instance of this class to visit a MethodElement will cause the method visitMethodElement to be invoked but will also cause the methods visitExecutableElement and visitElement to be subsequently invoked. This allows visitors to be written that visit all executable elements without needing to override the visit method for each of the specific subclasses of ExecutableElement. [...]
- A visitor that will recursively visit all of the element in an element model. For example, using an instance of this class to visit a CompilationUnitElement will also cause all of the types in the compilation unit to be visited. [...]
- A visitor that will do nothing when visiting an element. 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 element types. [...]
- 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. [...]