类 MethodUtils
- java.lang.Object
-
- io.microsphere.util.BaseUtils
-
- io.microsphere.reflect.MethodUtils
-
-
字段概要
字段 修饰符和类型 字段 说明 static java.util.function.Predicate<? super java.lang.reflect.Method>
OBJECT_METHOD_PREDICATE
ThePredicate
reference toisObjectMethod(Method)
static java.util.Set<java.lang.reflect.Method>
OBJECT_METHODS
-
构造器概要
构造器 构造器 说明 MethodUtils()
-
方法概要
所有方法 静态方法 具体方法 修饰符和类型 方法 说明 static java.util.function.Predicate<java.lang.reflect.Method>
excludedDeclaredClass(java.lang.Class<?> declaredClass)
Create an instance ofPredicate
forMethod
to exclude the specified declared classstatic java.lang.reflect.Method
findDeclaredMethod(java.lang.Class<?> declaredClass, java.lang.String methodName, java.lang.Class<?>... parameterTypes)
static java.lang.reflect.Method
findMethod(java.lang.Class type, java.lang.String methodName)
Find theMethod
by the the specified type(including inherited types) and method name without the parameter type.static java.lang.reflect.Method
findMethod(java.lang.Class type, java.lang.String methodName, java.lang.Class<?>... parameterTypes)
Find theMethod
by the the specified type(including inherited types) and method name and parameter typesstatic java.lang.reflect.Method
findNearestOverriddenMethod(java.lang.reflect.Method overrider)
Find the nearest overriddenmethod
from the inherited classstatic java.lang.reflect.Method
findOverriddenMethod(java.lang.reflect.Method overrider, java.lang.Class<?> declaringClass)
Find the overriddenmethod
from the declaring classstatic java.util.List<java.lang.reflect.Method>
getAllDeclaredMethods(java.lang.Class<?> declaringClass, java.util.function.Predicate<? super java.lang.reflect.Method>... methodsToFilter)
Get all declaredmethods
of the declared class, including the inherited methods.static java.util.List<java.lang.reflect.Method>
getAllMethods(java.lang.Class<?> declaringClass, java.util.function.Predicate<java.lang.reflect.Method>... methodsToFilter)
Get all publicmethods
of the declared class, including the inherited methods.static java.lang.reflect.Method
getDeclaredMethod(java.lang.Class<?> declaredClass, java.lang.String methodName, java.lang.Class<?>... parameterTypes)
static java.util.List<java.lang.reflect.Method>
getDeclaredMethods(java.lang.Class<?> declaringClass, java.util.function.Predicate<java.lang.reflect.Method>... methodsToFilter)
Get all declaredmethods
of the declared class, excluding the inherited methodsstatic java.util.List<java.lang.reflect.Method>
getMethods(java.lang.Class<?> declaringClass, boolean includeInheritedTypes, boolean publicOnly, java.util.function.Predicate<? super java.lang.reflect.Method>... methodsToFilter)
Get allmethods
of the declared classstatic java.util.List<java.lang.reflect.Method>
getMethods(java.lang.Class<?> declaringClass, java.util.function.Predicate<java.lang.reflect.Method>... methodsToFilter)
Get all publicmethods
of the declared class, including the inherited methods.static java.lang.String
getSignature(java.lang.reflect.Method method)
Get the signature ofthe specified method
static <R> R
invokeMethod(java.lang.Object instance, java.lang.Class<?> type, java.lang.String methodName, java.lang.Object... arguments)
static <R> R
invokeMethod(java.lang.Object instance, java.lang.reflect.Method method, java.lang.Object... arguments)
Invokes the underlying method represented by thisMethod
object, on the specified object with the specified parameters.static <R> R
invokeMethod(java.lang.Object object, java.lang.String methodName, java.lang.Object... arguments)
Invoke the target objects' methodstatic <R> R
invokeStaticMethod(java.lang.Class<?> type, java.lang.String methodName, java.lang.Object... arguments)
Invoke the target classes' static methodstatic <R> R
invokeStaticMethod(java.lang.reflect.Method method, java.lang.Object... arguments)
Invoke the target classes' static methodstatic boolean
isCallerSensitiveMethod(java.lang.reflect.Method method)
Test whether the specifiedmethod
annotates jdk.internal.reflect.CallerSensitive or notstatic boolean
isObjectMethod(java.lang.reflect.Method method)
static boolean
overrides(java.lang.reflect.Method overrider, java.lang.reflect.Method overridden)
Tests whether one method, as a member of a given type, overrides another method.
-
-
-
字段详细资料
-
OBJECT_METHOD_PREDICATE
public static final java.util.function.Predicate<? super java.lang.reflect.Method> OBJECT_METHOD_PREDICATE
ThePredicate
reference toisObjectMethod(Method)
-
OBJECT_METHODS
public static final java.util.Set<java.lang.reflect.Method> OBJECT_METHODS
-
-
方法详细资料
-
excludedDeclaredClass
public static java.util.function.Predicate<java.lang.reflect.Method> excludedDeclaredClass(java.lang.Class<?> declaredClass)
Create an instance ofPredicate
forMethod
to exclude the specified declared class- 参数:
declaredClass
- the declared class to exclude- 返回:
- non-null
-
getMethods
public static java.util.List<java.lang.reflect.Method> getMethods(java.lang.Class<?> declaringClass, boolean includeInheritedTypes, boolean publicOnly, java.util.function.Predicate<? super java.lang.reflect.Method>... methodsToFilter)
Get allmethods
of the declared class- 参数:
declaringClass
- the declared classincludeInheritedTypes
- include the inherited types, e,g. super classes or interfacespublicOnly
- only public methodmethodsToFilter
- (optional) the methods to be filtered- 返回:
- non-null read-only
List
-
getDeclaredMethods
public static java.util.List<java.lang.reflect.Method> getDeclaredMethods(java.lang.Class<?> declaringClass, java.util.function.Predicate<java.lang.reflect.Method>... methodsToFilter)
Get all declaredmethods
of the declared class, excluding the inherited methods- 参数:
declaringClass
- the declared classmethodsToFilter
- (optional) the methods to be filtered- 返回:
- non-null read-only
List
- 另请参阅:
getMethods(Class, boolean, boolean, Predicate[])
-
getMethods
public static java.util.List<java.lang.reflect.Method> getMethods(java.lang.Class<?> declaringClass, java.util.function.Predicate<java.lang.reflect.Method>... methodsToFilter)
Get all publicmethods
of the declared class, including the inherited methods.- 参数:
declaringClass
- the declared classmethodsToFilter
- (optional) the methods to be filtered- 返回:
- non-null read-only
List
- 另请参阅:
getMethods(Class, boolean, boolean, Predicate[])
-
getAllDeclaredMethods
public static java.util.List<java.lang.reflect.Method> getAllDeclaredMethods(java.lang.Class<?> declaringClass, java.util.function.Predicate<? super java.lang.reflect.Method>... methodsToFilter)
Get all declaredmethods
of the declared class, including the inherited methods.- 参数:
declaringClass
- the declared classmethodsToFilter
- (optional) the methods to be filtered- 返回:
- non-null read-only
List
- 另请参阅:
getMethods(Class, boolean, boolean, Predicate[])
-
getAllMethods
public static java.util.List<java.lang.reflect.Method> getAllMethods(java.lang.Class<?> declaringClass, java.util.function.Predicate<java.lang.reflect.Method>... methodsToFilter)
Get all publicmethods
of the declared class, including the inherited methods.- 参数:
declaringClass
- the declared classmethodsToFilter
- (optional) the methods to be filtered- 返回:
- non-null read-only
List
- 另请参阅:
getMethods(Class, boolean, boolean, Predicate[])
-
findMethod
public static java.lang.reflect.Method findMethod(java.lang.Class type, java.lang.String methodName)
Find theMethod
by the the specified type(including inherited types) and method name without the parameter type.- 参数:
type
- the target typemethodName
- the specified method name- 返回:
- if not found, return
null
-
findMethod
public static java.lang.reflect.Method findMethod(java.lang.Class type, java.lang.String methodName, java.lang.Class<?>... parameterTypes)
Find theMethod
by the the specified type(including inherited types) and method name and parameter types- 参数:
type
- the target typemethodName
- the method nameparameterTypes
- the parameter types- 返回:
- if not found, return
null
-
findDeclaredMethod
public static java.lang.reflect.Method findDeclaredMethod(java.lang.Class<?> declaredClass, java.lang.String methodName, java.lang.Class<?>... parameterTypes)
-
getDeclaredMethod
public static java.lang.reflect.Method getDeclaredMethod(java.lang.Class<?> declaredClass, java.lang.String methodName, java.lang.Class<?>... parameterTypes)
-
invokeMethod
public static <R> R invokeMethod(java.lang.Object object, java.lang.String methodName, java.lang.Object... arguments)
Invoke the target objects' method- 类型参数:
R
- the return type- 参数:
object
- the target objectmethodName
- the method namearguments
- the method arguments- 返回:
- the target method's execution result
-
invokeStaticMethod
public static <R> R invokeStaticMethod(java.lang.Class<?> type, java.lang.String methodName, java.lang.Object... arguments)
Invoke the target classes' static method- 类型参数:
R
- the return type- 参数:
type
- the target classmethodName
- the method namearguments
- the method arguments- 返回:
- the target method's execution result
-
invokeStaticMethod
public static <R> R invokeStaticMethod(java.lang.reflect.Method method, java.lang.Object... arguments)
Invoke the target classes' static method- 类型参数:
R
- the return type- 参数:
method
- the methodarguments
- the method arguments- 返回:
- the target method's execution result
-
invokeMethod
public static <R> R invokeMethod(java.lang.Object instance, java.lang.Class<?> type, java.lang.String methodName, java.lang.Object... arguments)
-
invokeMethod
public static <R> R invokeMethod(@Nullable java.lang.Object instance, java.lang.reflect.Method method, java.lang.Object... arguments)
Invokes the underlying method represented by thisMethod
object, on the specified object with the specified parameters. Individual parameters are automatically unwrapped to match primitive formal parameters, and both primitive and reference parameters are subject to method invocation conversions as necessary.If the underlying method is static, then the specified
instance
argument is ignored. It may be null.If the number of formal parameters required by the underlying method is 0, the supplied
args
array may be of length 0 or null.If the underlying method is an instance method, it is invoked using dynamic method lookup as documented in The Java Language Specification, section ; in particular, overriding based on the runtime type of the target object may occur.
If the underlying method is static, the class that declared the method is initialized if it has not already been initialized.
If the method completes normally, the value it returns is returned to the caller of invoke; if the value has a primitive type, it is first appropriately wrapped in an object. However, if the value has the type of an array of a primitive type, the elements of the array are not wrapped in objects; in other words, an array of primitive type is returned. If the underlying method return type is void, the invocation returns null.
- 类型参数:
R
-- 参数:
instance
- the object the underlying method is invoked frommethod
- the underlying methodarguments
- the arguments used for the method call- 返回:
- the result of dispatching the method represented by
this object on
instance
with parametersarguments
- 抛出:
java.lang.IllegalStateException
- if thisMethod
object is enforcing Java language access control and the underlying method is inaccessible.java.lang.IllegalArgumentException
- if the method is an instance method and the specified object argument is not an instance of the class or interface declaring the underlying method (or of a subclass or implementor thereof); if the number of actual and formal parameters differ; if an unwrapping conversion for primitive arguments fails; or if, after possible unwrapping, a parameter value cannot be converted to the corresponding formal parameter type by a method invocation conversion.java.lang.RuntimeException
- if the underlying method throws an exception.
-
overrides
public static boolean overrides(java.lang.reflect.Method overrider, java.lang.reflect.Method overridden)
Tests whether one method, as a member of a given type, overrides another method.- 参数:
overrider
- the first method, possible overrideroverridden
- the second method, possibly being overridden- 返回:
true
if and only if the first method overrides the second- 另请参阅:
Elements.overrides(ExecutableElement, ExecutableElement, TypeElement)
-
findNearestOverriddenMethod
public static java.lang.reflect.Method findNearestOverriddenMethod(java.lang.reflect.Method overrider)
Find the nearest overriddenmethod
from the inherited class- 参数:
overrider
- the overridermethod
- 返回:
- if found, the overrider
method
, ornull
-
findOverriddenMethod
public static java.lang.reflect.Method findOverriddenMethod(java.lang.reflect.Method overrider, java.lang.Class<?> declaringClass)
Find the overriddenmethod
from the declaring class- 参数:
overrider
- the overridermethod
declaringClass
- the class that is declaring the overriddenmethod
- 返回:
- if found, the overrider
method
, ornull
-
getSignature
public static java.lang.String getSignature(java.lang.reflect.Method method)
Get the signature ofthe specified method
- 参数:
method
-the specified method
- 返回:
- non-null
-
isObjectMethod
public static boolean isObjectMethod(java.lang.reflect.Method method)
-
isCallerSensitiveMethod
public static boolean isCallerSensitiveMethod(java.lang.reflect.Method method)
Test whether the specifiedmethod
annotates jdk.internal.reflect.CallerSensitive or not- 参数:
method
-Method
- 返回:
true
if the specifiedmethod
annotates jdk.internal.reflect.CallerSensitive- 另请参阅:
jdk.internal.reflect.CallerSensitive
-
-