org.test4j.tools.commons
类 MethodHelper

java.lang.Object
  继承者 org.test4j.tools.commons.MethodHelper

public final class MethodHelper
extends Object


构造方法摘要
MethodHelper()
           
 
方法摘要
static
<T> MethodAccessor<T>
findMethodByArgCount(Class targetClazz, String methodName, int args)
          根据方法的名称和参数个数查找方法访问器,如果有多于1个同名且参数个数一样的方法,那么抛出异常
static
<T> MethodAccessor<T>
findMethodByArgCount(Object target, String methodName, int args)
          根据方法的名称和参数个数查找方法访问器,如果有多于1个同名且参数个数一样的方法,那么抛出异常
static Set<Method> getAllMethods(Class clazz)
          Gets all methods of the given class and all its super-classes.
static Method getMethod(Class cls, String name, Class... parametersType)
          返回class中名称为name,参数类型为 parametersType的方法
static List<Method> getMethod(Class cls, String name, int args)
          查找名为name,参数个数为args的方法列表
static Class[] getParameterClazz(Object... paras)
           
static Set<Method> getSettersAssignableFrom(Class clazz, Type type, boolean isStatic)
          Returns all declared setter methods of fields of the given class that are assignable from the given type.
static Set<Method> getSettersOfType(Class clazz, Type type)
          Returns the setter methods in the given class that have an argument with the exact given type.
static
<T> T
invoke(Object target, String method, Object... paras)
          调用类为clazz,名称为method的方法
static
<T> T
invokeStatic(Class targetClass, String method, Object... paras)
          调用静态方法
static
<T> T
invokeUnThrow(Object target, String method, Object... paras)
           
static boolean isCloneMethod(Method method)
           
static boolean isEqualsMethod(Method method)
           
static boolean isFinalizeMethod(Method method)
           
static boolean isHashCodeMethod(Method method)
           
static boolean isPublicStaticVoid(Method method)
          测试类是否是 public static void且是无参形式的?
static boolean isSetterMethod(Method method)
          判断方法是否是setter方法
For each method, check if it can be a setter for an object of the given type.
static boolean isToStringMethod(Method method)
           
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

构造方法详细信息

MethodHelper

public MethodHelper()
方法详细信息

getMethod

public static final Method getMethod(Class cls,
                                     String name,
                                     Class... parametersType)
返回class中名称为name,参数类型为 parametersType的方法

参数:
cls -
name -
parametersType -
返回:

getMethod

public static final List<Method> getMethod(Class cls,
                                           String name,
                                           int args)
查找名为name,参数个数为args的方法列表

参数:
cls -
name -
args -
返回:

getSettersAssignableFrom

public static Set<Method> getSettersAssignableFrom(Class clazz,
                                                   Type type,
                                                   boolean isStatic)
Returns all declared setter methods of fields of the given class that are assignable from the given type.

参数:
clazz - The class to get setters from, not null
type - The type, not null
isStatic - True if static setters are to be returned, false for non-static
返回:
A list of Methods, empty list if none found

getAllMethods

public static Set<Method> getAllMethods(Class clazz)
Gets all methods of the given class and all its super-classes.

参数:
clazz - The class
返回:
The methods, not null

getSettersOfType

public static Set<Method> getSettersOfType(Class clazz,
                                           Type type)
Returns the setter methods in the given class that have an argument with the exact given type. The class's superclasses are also investigated.

参数:
clazz - The class to get the setter from, not null
type - The type, not null
isStatic - True if static setters are to be returned, false for non-static
返回:
All setters for an object of the given type

isEqualsMethod

public static boolean isEqualsMethod(Method method)
参数:
method - The method to check, not null
返回:
True if the given method is the Object.equals(java.lang.Object) method

isHashCodeMethod

public static boolean isHashCodeMethod(Method method)
参数:
method - The method to check, not null
返回:
True if the given method is the Object.hashCode() method

isToStringMethod

public static boolean isToStringMethod(Method method)
参数:
method - The method to check, not null
返回:
True if the given method is the Object.toString() method

isCloneMethod

public static boolean isCloneMethod(Method method)
参数:
method - The method to check, not null
返回:
True if the given method is the Object.clone() method

isFinalizeMethod

public static boolean isFinalizeMethod(Method method)

isSetterMethod

public static boolean isSetterMethod(Method method)
判断方法是否是setter方法
For each method, check if it can be a setter for an object of the given type. A setter is a method with the following properties:

参数:
method - The method to check, not null
返回:
True if the given method is a setter, false otherwise

invoke

public static <T> T invoke(Object target,
                           String method,
                           Object... paras)
                throws Exception
调用类为clazz,名称为method的方法

参数:
methodName -
paras -
返回:
抛出:
Exception

invokeUnThrow

public static <T> T invokeUnThrow(Object target,
                                  String method,
                                  Object... paras)

getParameterClazz

public static Class[] getParameterClazz(Object... paras)

invokeStatic

public static <T> T invokeStatic(Class targetClass,
                                 String method,
                                 Object... paras)
调用静态方法

类型参数:
T -
参数:
targetClass -
method -
paras -
返回:

findMethodByArgCount

public static <T> MethodAccessor<T> findMethodByArgCount(Class targetClazz,
                                                         String methodName,
                                                         int args)
根据方法的名称和参数个数查找方法访问器,如果有多于1个同名且参数个数一样的方法,那么抛出异常

参数:
target -
methodName -
args -
返回:

findMethodByArgCount

public static <T> MethodAccessor<T> findMethodByArgCount(Object target,
                                                         String methodName,
                                                         int args)
根据方法的名称和参数个数查找方法访问器,如果有多于1个同名且参数个数一样的方法,那么抛出异常

类型参数:
T -
参数:
target -
methodName -
args -
返回:

isPublicStaticVoid

public static boolean isPublicStaticVoid(Method method)
测试类是否是 public static void且是无参形式的?

参数:
method -
返回:


Copyright © 2013. All rights reserved.