com.mockrunner.util.common
Class MethodUtil

java.lang.Object
  extended by com.mockrunner.util.common.MethodUtil

public class MethodUtil
extends java.lang.Object


Constructor Summary
MethodUtil()
           
 
Method Summary
static boolean areMethodsEqual(java.lang.reflect.Method method1, java.lang.reflect.Method method2)
          Returns if the two specified methods are equal as defined by Method.equals() except that the methods can be defined by different classes.
static java.lang.reflect.Method[] getMatchingDeclaredMethods(java.lang.Class theClass, java.lang.String expr)
          Returns the declared methods of the specified class whose names are matching the specified regular expression.
static java.lang.reflect.Method[][] getMethodsSortedByInheritanceHierarchy(java.lang.Class theClass)
          Returns all non-static methods declared by the specified class and its superclasses.
static java.util.Set getOverriddenMethods(java.lang.Class clazz, java.lang.reflect.Method[] methods)
          Returns all methods in methods that are overridden in the specified class hierarchy.
static java.lang.Object invoke(java.lang.Object object, java.lang.String methodName)
          Invokes the method with the specified name on the specified object and throws a NestedApplicationException, if the invocation fails.
static java.lang.Object invoke(java.lang.Object object, java.lang.String methodName, java.lang.Object parameter)
          Invokes the method with the specified name on the specified object and throws a NestedApplicationException, if the invocation fails.
static boolean overrides(java.lang.reflect.Method method1, java.lang.reflect.Method method2)
          Returns if method2 overrides method1.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MethodUtil

public MethodUtil()
Method Detail

invoke

public static java.lang.Object invoke(java.lang.Object object,
                                      java.lang.String methodName)
Invokes the method with the specified name on the specified object and throws a NestedApplicationException, if the invocation fails. The method must be public and must not have any parameters.

Parameters:
object - the object the method is invoked from
methodName - the name of the method
Returns:
the result of the method invocation

invoke

public static java.lang.Object invoke(java.lang.Object object,
                                      java.lang.String methodName,
                                      java.lang.Object parameter)
Invokes the method with the specified name on the specified object and throws a NestedApplicationException, if the invocation fails. The method must be public and must have exactly one paremeter of the type specified by the given parameter.

Parameters:
object - the object the method is invoked from
methodName - the name of the method
parameter - the parameter, must not be null
Returns:
the result of the method invocation

areMethodsEqual

public static boolean areMethodsEqual(java.lang.reflect.Method method1,
                                      java.lang.reflect.Method method2)
Returns if the two specified methods are equal as defined by Method.equals() except that the methods can be defined by different classes.

Parameters:
method1 - the first method to compare
method2 - the second method to compare
Returns:
true if the methods are equal, false otherwise
Throws:
java.lang.NullPointerException - if one of the methods is null

overrides

public static boolean overrides(java.lang.reflect.Method method1,
                                java.lang.reflect.Method method2)
Returns if method2 overrides method1.

Parameters:
method1 - method to be overridden
method2 - overriding method
Returns:
true if method2 overrides method1, false otherwise
Throws:
java.lang.NullPointerException - if one of the methods is null

getOverriddenMethods

public static java.util.Set getOverriddenMethods(java.lang.Class clazz,
                                                 java.lang.reflect.Method[] methods)
Returns all methods in methods that are overridden in the specified class hierarchy. The returned Set contains all overridden methods and all overriding methods.

Parameters:
clazz - the class hierarchy
methods - the Set of methods
Returns:
all overridden and overriding methods.

getMatchingDeclaredMethods

public static java.lang.reflect.Method[] getMatchingDeclaredMethods(java.lang.Class theClass,
                                                                    java.lang.String expr)
Returns the declared methods of the specified class whose names are matching the specified regular expression.

Parameters:
theClass - the class whose methods are examined
expr - the regular expression
Returns:
the matching methods

getMethodsSortedByInheritanceHierarchy

public static java.lang.reflect.Method[][] getMethodsSortedByInheritanceHierarchy(java.lang.Class theClass)
Returns all non-static methods declared by the specified class and its superclasses. The returned array contains the methods of all classes in the inheritance hierarchy, starting with the methods of the most general superclass, which is java.lang.Object.

Parameters:
theClass - the class whose methods are examined
Returns:
the array of method arrays