@Internal public interface Visitable<T extends Visitable<T>>
Visitor
on the visitable object, and
how to traverse further.
This concept makes it easy to implement for example a depth-first traversal of a tree or DAG with different types of logic during the traversal. The accept(...) method calls the visitor and then send the visitor to its children (or predecessors). Using different types of visitors, different operations can be performed during the traversal, while writing the actual traversal code only once.
Visitor
Modifier and Type | Method and Description |
---|---|
void |
accept(Visitor<T> visitor)
Contains the logic to invoke the visitor and continue the traversal.
|
void accept(Visitor<T> visitor)
A typical code example is the following:
public void accept(Visitor<Operator> visitor) {
boolean descend = visitor.preVisit(this);
if (descend) {
if (this.input != null) {
this.input.accept(visitor);
}
visitor.postVisit(this);
}
}
visitor
- The visitor to be called with this object as the parameter.Visitor.preVisit(Visitable)
,
Visitor.postVisit(Visitable)
Copyright © 2014–2023 The Apache Software Foundation. All rights reserved.