Interface ReflectiveVisitDispatcher<R extends ReflectiveVisitor,​E>

    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      boolean invokeVisitor​(R visitor, E visitee, java.lang.String visitMethodName)
      Implements the Glossary.VISITOR_PATTERN via reflection.
      java.lang.reflect.Method lookupVisitMethod​(java.lang.Class<? extends R> visitorClass, java.lang.Class<? extends E> visiteeClass, java.lang.String visitMethodName)
      Looks up a visit method.
      java.lang.reflect.Method lookupVisitMethod​(java.lang.Class<? extends R> visitorClass, java.lang.Class<? extends E> visiteeClass, java.lang.String visitMethodName, java.util.List<java.lang.Class> additionalParameterTypes)
      Looks up a visit method taking additional parameters beyond the overloaded visitee type.
    • Method Detail

      • lookupVisitMethod

        java.lang.reflect.Method lookupVisitMethod​(java.lang.Class<? extends R> visitorClass,
                                                   java.lang.Class<? extends E> visiteeClass,
                                                   java.lang.String visitMethodName,
                                                   java.util.List<java.lang.Class> additionalParameterTypes)
        Looks up a visit method taking additional parameters beyond the overloaded visitee type.
        Parameters:
        visitorClass - class of object whose visit method is to be invoked
        visiteeClass - class of object to be passed as a parameter to the visit method
        visitMethodName - name of visit method
        additionalParameterTypes - list of additional parameter types
        Returns:
        method found, or null if none found
      • lookupVisitMethod

        java.lang.reflect.Method lookupVisitMethod​(java.lang.Class<? extends R> visitorClass,
                                                   java.lang.Class<? extends E> visiteeClass,
                                                   java.lang.String visitMethodName)
        Looks up a visit method.
        Parameters:
        visitorClass - class of object whose visit method is to be invoked
        visiteeClass - class of object to be passed as a parameter to the visit method
        visitMethodName - name of visit method
        Returns:
        method found, or null if none found
      • invokeVisitor

        boolean invokeVisitor​(R visitor,
                              E visitee,
                              java.lang.String visitMethodName)
        Implements the Glossary.VISITOR_PATTERN via reflection. The basic technique is taken from a Javaworld article. For an example of how to use it, see ReflectVisitorTest.

        Visit method lookup follows the same rules as if compile-time resolution for VisitorClass.visit(VisiteeClass) were performed. An ambiguous match due to multiple interface inheritance results in an IllegalArgumentException. A non-match is indicated by returning false.

        Parameters:
        visitor - object whose visit method is to be invoked
        visitee - object to be passed as a parameter to the visit method
        visitMethodName - name of visit method, e.g. "visit"
        Returns:
        true if a matching visit method was found and invoked