Class MethodMatcher


  • public class MethodMatcher
    extends java.lang.Object
    SourceMethodMatcher $8.4 of the JavaLanguage specification describes a method body as such:
     SourceMethodDeclaration: SourceMethodHeader SourceMethodBody
     SourceMethodHeader: SourceMethodModifiers TypeParameters Result SourceMethodDeclarator Throws
     SourceMethodDeclarator: Identifier ( FormalParameterList )
    
     example <T extends String & Serializable>  T   getResult(? extends T) throws Exception
             \-------------------------------/ \-/            \---------/
                   TypeParameters             Result        ParameterList
     
    Matches a given method with given ParameterList and Result type obeying the constraints in the TypeParameters block.

    For more info on java-generics: http://www.javacodegeeks.com/2011/04/java-generics-quick-tutorial.html http://www.angelikalanger.com/GenericsFAQ/FAQSections/ParameterizedTypes.html

    The following situations is not supported / tested:

    1. Multiple bounds were the bound itself is again a generic type.
    • Method Detail

      • matches

        boolean matches​(java.util.List<Type> sourceTypes,
                        Type targetType)
        Whether the given source and target types are matched by this matcher's candidate method.
        Parameters:
        sourceTypes - the source types
        targetType - the target type
        Returns:
        true when both, source type and target types match the signature of this matcher's method; false otherwise.
      • isPrimitiveToObject

        private boolean isPrimitiveToObject​(Type type,
                                            Type isAssignableTo)
        Primitive to Object (Boxed Type) should be handled by a type conversion rather than a direct mapping Direct mapping runs the risk of null pointer exceptions: e.g. in the assignment of Integer to int, Integer can be null.
        Parameters:
        type - the type to be assigned
        isAssignableTo - the type to which @param type should be assignable to
        Returns:
        true if isAssignable is a primitive type and type is an object