Class ReflectiveVisitor

  • All Implemented Interfaces:
    Visitor

    @API(status=INTERNAL,
         since="1.0")
    public abstract class ReflectiveVisitor
    extends VisitorWithResult
    This is a convenience class implementing a Visitor and it takes care of choosing the right methods to dispatch the Visitor.enter(Visitable) and Visitor.leave(Visitable) calls to.

    Classes extending this visitor need to provide corresponding enter and leave methods taking exactly one argument of the type of Visitable they are interested it.

    The type must be an exact match, this support class doesn't try to find a close match up in the class hierarchy if it doesn't find an exact match.

    Since:
    1.0
    Author:
    Michael J. Simons, Gerrit Meier
    • Field Detail

      • currentVisitedElements

        protected Deque<Visitable> currentVisitedElements
        Keeps track of the ASTs current level.
      • visitablesAndDelegates

        protected final Map<Visitable,​Visitor> visitablesAndDelegates
        If theres any special delegate for a dialect or similar for a given visitable, it will be tracked here.
    • Constructor Detail

      • ReflectiveVisitor

        public ReflectiveVisitor()
    • Method Detail

      • preEnter

        protected abstract boolean preEnter​(Visitable visitable)
        This is a hook that is called with the uncasted, raw visitable just before entering a visitable.

        The hook is called regardless wither a matching enter is found or not.

        Parameters:
        visitable - The visitable that is passed on to a matching enter after this call.
        Returns:
        true, when visiting of elements should be stopped until this element is left again.
      • postLeave

        protected abstract void postLeave​(Visitable visitable)
        This is a hook that is called with the uncasted, raw visitable just after leaving the visitable.

        The hook is called regardless wither a matching leave is found or not.

        Parameters:
        visitable - The visitable that is passed on to a matching leave after this call.
      • enterWithResult

        public final EnterResult enterWithResult​(Visitable visitable)
        Description copied from interface: Visitor
        A method that is used to pass control to some extend from the visitor to the Visitable. Not all visitables react to this and we don't give any guarantees about which will. This method has been mainly introduced in parallel to Visitor.enter(Visitable) so that existing external implementations of visitors won't break.
        Parameters:
        visitable - the segment to visit.
        Returns:
        A result indicating whether visitation of child elements should continue or not.
      • leave

        public final void leave​(Visitable visitable)
        Description copied from interface: Visitor
        Leave a Visitable.
        Parameters:
        visitable - the visited segment.