public class ReflectionMethodUtils extends Object
限定符和类型 | 类和说明 |
---|---|
static interface |
ReflectionMethodUtils.MethodCallback
Action to take on each method.
|
static interface |
ReflectionMethodUtils.MethodFilter
Callback optionally used to filter methods to be operated on by a method callback.
|
限定符和类型 | 字段和说明 |
---|---|
static ReflectionMethodUtils.MethodFilter |
NON_BRIDGED_METHODS
Pre-built MethodFilter that matches all non-bridge methods.
|
static ReflectionMethodUtils.MethodFilter |
USER_DECLARED_METHODS
Pre-built MethodFilter that matches all non-bridge methods
which are not declared on
java.lang.Object . |
构造器和说明 |
---|
ReflectionMethodUtils() |
限定符和类型 | 方法和说明 |
---|---|
static boolean |
declaresException(Method method,
Class<?> exceptionType)
Determine whether the given method explicitly declares the given
exception or one of its superclasses, which means that an exception of
that type can be propagated as-is within a reflective invocation.
|
static void |
doWithMethods(Class<?> clazz,
ReflectionMethodUtils.MethodCallback mc) |
static void |
doWithMethods(Class<?> clazz,
ReflectionMethodUtils.MethodCallback mc,
ReflectionMethodUtils.MethodFilter mf)
Perform the given callback operation on all matching methods of the given
class and superclasses (or given interface and super-interfaces).
|
static Method |
findMethod(Class<?> clazz,
String name,
Class<?>... paramTypes)
Attempt to find a
Method on the supplied class with the supplied name
and parameter types. |
static List<Method> |
getAllDeclaredMethods(Class<?> leafClass)
Get all declared methods on the leaf class and all superclasses.
|
static <T> Constructor<T> |
getConstructor(Class<T> clazz,
Class<?>... paramTypes)
Determine whether the given class has a public constructor with the given signature,
and return it if available (else return
null ). |
static <T> Constructor<T> |
getDeclaredConstructor(Class<T> clazz,
Class<?>... paramTypes) |
static Method |
getDeclaredMethod(Class<?> clazz,
String methodName,
Class<?>... paramTypes) |
static Method |
getMethod(Class<?> clazz,
String methodName,
Class<?>... paramTypes)
Determine whether the given class has a method with the given signature,
and return it if available (else return
null ). |
static String |
getQualifiedMethodName(Method method)
Return the qualified name of the given method, consisting of
fully qualified interface/class name + "." + method name.
|
static Method |
getStaticMethod(Class<?> clazz,
String methodName,
Class<?>... args)
Return a public static method of a class.
|
static List<Method> |
getUniqueDeclaredMethods(Class<?> leafClass)
Get the unique set of declared methods on the leaf class and all superclasses.
|
static Object |
invokeConstructor(Class<?> clazz,
Class<?>[] parameterTypes,
Object... args) |
static Object |
invokeConstructor(Constructor<?> constructor,
Object... args) |
static Object |
invokeMethod(Method method,
Object target,
Object... args)
Invoke the specified
Method against the supplied target object with the
supplied arguments. |
static Object |
invokeMethod(String methodName,
Class<?>[] parameterTypes,
Object target,
Object... args) |
static Object |
invokeMethod(String methodName,
Object target,
Object... args) |
static Object |
invokeStaticMethod(String methodName,
Class<?>[] parameterTypes,
Class<?> target,
Object... args) |
static Object |
invokeStaticMethod(String methodName,
Class<?> clazz,
Object... args) |
static boolean |
isEqualsMethod(Method method)
Determine whether the given method is an "equals" method.
|
static boolean |
isHashCodeMethod(Method method)
Determine whether the given method is a "hashCode" method.
|
static boolean |
isObjectMethod(Method method)
Determine whether the given method is originally declared by
Object . |
static boolean |
isToStringMethod(Method method)
Determine whether the given method is a "toString" method.
|
public static final ReflectionMethodUtils.MethodFilter NON_BRIDGED_METHODS
public static final ReflectionMethodUtils.MethodFilter USER_DECLARED_METHODS
java.lang.Object
.public static String getQualifiedMethodName(Method method)
method
- the methodpublic static boolean isEqualsMethod(Method method)
Object.equals(Object)
public static boolean isHashCodeMethod(Method method)
Object.hashCode()
public static boolean isToStringMethod(Method method)
Object.toString()
public static boolean isObjectMethod(Method method)
Object
.public static Object invokeMethod(Method method, Object target, Object... args)
Method
against the supplied target object with the
supplied arguments. The target object can be null
when invoking a
static Method
.method
- the method to invoketarget
- the target object to invoke the method onargs
- the invocation arguments (may be null
)public static Object invokeMethod(String methodName, Class<?>[] parameterTypes, Object target, Object... args)
public static Object invokeStaticMethod(String methodName, Class<?> clazz, Object... args)
public static Object invokeStaticMethod(String methodName, Class<?>[] parameterTypes, Class<?> target, Object... args)
public static Object invokeConstructor(Constructor<?> constructor, Object... args)
public static Object invokeConstructor(Class<?> clazz, Class<?>[] parameterTypes, Object... args)
public static Method getStaticMethod(Class<?> clazz, String methodName, Class<?>... args)
methodName
- the static method nameclazz
- the class which defines the methodargs
- the parameter types to the methodnull
if no static method was foundIllegalArgumentException
- if the method name is blank or the clazz is nullpublic static Method getMethod(Class<?> clazz, String methodName, Class<?>... paramTypes)
null
).
Essentially translates NoSuchMethodException
to null
.
clazz
- the clazz to analyzemethodName
- the name of the methodparamTypes
- the parameter types of the methodnull
if not foundClass.getMethod(java.lang.String, java.lang.Class<?>...)
public static Method getDeclaredMethod(Class<?> clazz, String methodName, Class<?>... paramTypes)
public static Method findMethod(Class<?> clazz, String name, Class<?>... paramTypes)
Method
on the supplied class with the supplied name
and parameter types. Searches all superclasses up to Object
.
Returns null
if no Method
can be found.
clazz
- the class to introspectname
- the name of the methodparamTypes
- the parameter types of the method
(may be null
to indicate any signature)null
if none foundpublic static <T> Constructor<T> getConstructor(Class<T> clazz, Class<?>... paramTypes)
null
).
Essentially translates NoSuchMethodException
to null
.
clazz
- the clazz to analyzeparamTypes
- the parameter types of the methodnull
if not foundClass.getConstructor(java.lang.Class<?>...)
public static <T> Constructor<T> getDeclaredConstructor(Class<T> clazz, Class<?>... paramTypes)
public static List<Method> getAllDeclaredMethods(Class<?> leafClass)
public static List<Method> getUniqueDeclaredMethods(Class<?> leafClass)
public static boolean declaresException(Method method, Class<?> exceptionType)
method
- the declaring methodexceptionType
- the exception to throwtrue
if the exception can be thrown as-is;
false
if it needs to be wrappedpublic static void doWithMethods(Class<?> clazz, ReflectionMethodUtils.MethodCallback mc)
public static void doWithMethods(Class<?> clazz, ReflectionMethodUtils.MethodCallback mc, ReflectionMethodUtils.MethodFilter mf)
The same named method occurring on subclass and superclass will appear
twice, unless excluded by the specified ReflectionMethodUtils.MethodFilter
.
clazz
- class to start looking atmc
- the callback to invoke for each methodmf
- the filter that determines the methods to apply the callback toCopyright © 2018 jretty-org. All rights reserved.