public abstract class AbstractReflectiveNodeHierarchicalVisitor extends java.lang.Object implements NodeHierarchicalVisitor
visitEnter(Node)
and visitLeave(Node)
.
It is completely driven by the Java Reflection API. This means that you can create a subclass containing any number of overloaded methods, provided that the one and only parameter argument must be assignment compatible
to the interface Node
.
The names of the overloaded methods must be either visitEnter
or visitLeave
.
It doesn't matter whether you return boolean
or something completely different. But, note however, that, if you want to be able to skip entering any child or sibling Node
s, you must provide a
boolean
return type and return false
. Otherwise, true
is implicitly chosen.
Any access modifier may be used, as they will all be accepted.
Modifier | Constructor and Description |
---|---|
protected |
AbstractReflectiveNodeHierarchicalVisitor()
Constructs a new
AbstractReflectiveNodeHierarchicalVisitor instance. |
Modifier and Type | Method and Description |
---|---|
boolean |
visitEnter(Node node)
Called by a concrete
Node implementation. |
boolean |
visitLeave(Node node)
Called by a concrete
Node implementation. |
protected AbstractReflectiveNodeHierarchicalVisitor()
AbstractReflectiveNodeHierarchicalVisitor
instance.public final boolean visitEnter(Node node)
Node
implementation.
It should happen soon after its accept(NodeHierarchicalVisitor)
method has been called, with this AbstractReflectiveNodeHierarchicalVisitor
as its parameter argument.
If node
is null
, a NullPointerException
will be thrown.
If node
could not be traversed by this AbstractReflectiveNodeHierarchicalVisitor
, a NodeTraversalException
will be thrown.
To visit node
s child Node
s, return true
, false
otherwise.
The implementation provided by this class, will attempt to delegate all calls to overloaded methods with a parameter argument that is assignment compatible to Node
. If no overloaded method can be found for
node
, true
will be returned. But, if it can be found, it will be called. If the return type of the overloaded method is boolean
, the value of that boolean
will be returned by this
method. If it is not boolean
, true
will be returned by default. The overloaded method may have any access modifier assigned to it. So private methods will work.
visitEnter
in interface NodeHierarchicalVisitor
node
- the Node
to entertrue
if, and only if, node
s child Node
s should be visited, false
otherwiseNodeTraversalException
- thrown if, and only if, node
could not be traversed by this AbstractReflectiveNodeHierarchicalVisitor
java.lang.NullPointerException
- thrown if, and only if, node
is null
public final boolean visitLeave(Node node)
Node
implementation.
It should happen just before its accept(NodeHierarchicalVisitor)
method returns. Actually, it should be the result returned by that method.
If node
is null
, a NullPointerException
will be thrown.
If node
could not be traversed by this AbstractReflectiveNodeHierarchicalVisitor
, a NodeTraversalException
will be thrown.
To visit node
s sibling Node
s, return true
, false
otherwise.
The implementation provided by this class, will attempt to delegate all calls to overloaded methods with a parameter argument that is assignment compatible to Node
. If no overloaded method can be found for
node
, true
will be returned. But, if it can be found, it will be called. If the return type of the overloaded method is boolean
, the value of that boolean
will be returned by this
method. If it is not boolean
, true
will be returned by default. The overloaded method may have any access modifier assigned to it. So private methods will work.
visitLeave
in interface NodeHierarchicalVisitor
node
- the Node
to leavetrue
if, and only if, node
s sibling Node
s should be visited, false
otherwiseNodeTraversalException
- thrown if, and only if, node
could not be traversed by this AbstractReflectiveNodeHierarchicalVisitor
java.lang.NullPointerException
- should be thrown if, and only if, node
is null