Package org.apache.dubbo.common.utils
Interface MethodUtils
public interface MethodUtils
Miscellaneous method utility methods.
Mainly for internal use within the framework.
- Since:
- 2.7.2
-
Method Summary
Static MethodsModifier and TypeMethodDescriptionexcludedDeclaredClass(Class<?> declaredClass) static StringextractFieldName(Method method) Extract fieldName from set/get/is method. if it's not a set/get/is method, return empty string.static MethodfindMethod(Class type, String methodName) Find theMethodby the the specified type and method name without the parameter typesstatic MethodfindMethod(Class type, String methodName, Class<?>... parameterTypes) Find theMethodby the the specified type, method name and parameter typesstatic MethodfindNearestOverriddenMethod(Method overrider) Find the nearest overriddenmethodfrom the inherited classstatic MethodfindOverriddenMethod(Method overrider, Class<?> declaringClass) Find the overriddenmethodfrom the declaring classgetAllDeclaredMethods(Class<?> declaringClass, Predicate<Method>... methodsToFilter) Get all declaredmethodsof the declared class, including the inherited methods.getAllMethods(Class<?> declaringClass, Predicate<Method>... methodsToFilter) Get all publicmethodsof the declared class, including the inherited methods.getDeclaredMethods(Class<?> declaringClass, Predicate<Method>... methodsToFilter) Get all declaredmethodsof the declared class, excluding the inherited methodsgetMethods(Class<?> declaringClass, boolean includeInheritedTypes, boolean publicOnly, Predicate<Method>... methodsToFilter) Get allmethodsof the declared classgetMethods(Class<?> declaringClass, Predicate<Method>... methodsToFilter) Get all publicmethodsof the declared class, including the inherited methods.static doubleinvokeAndReturnDouble(Method method, Object targetObj) Invoke and return double value.static longinvokeAndReturnLong(Method method, Object targetObj) Invoke and return long value.static <T> TinvokeMethod(Object object, String methodName, Object... methodParameters) Invoke the target object and methodstatic booleanisDeprecated(Method method) Check if the method is a deprecated method.static booleanReturntrueif the provided method is a get method.static booleanisMetaMethod(Method method) ReturntrueIf this method is a meta method.static booleanReturntrueif the provided method is a set method.static booleanTests whether one method, as a member of a given type, overrides another method.static StringtoShortString(Method method) static String
-
Method Details
-
isSetter
Returntrueif the provided method is a set method. Otherwise, returnfalse.- Parameters:
method- the method to check- Returns:
- whether the given method is setter method
-
isGetter
Returntrueif the provided method is a get method. Otherwise, returnfalse.- Parameters:
method- the method to check- Returns:
- whether the given method is getter method
-
isMetaMethod
ReturntrueIf this method is a meta method. Otherwise, returnfalse.- Parameters:
method- the method to check- Returns:
- whether the given method is meta method
-
isDeprecated
Check if the method is a deprecated method. The standard is whether theDeprecatedannotation is declared on the class. Returntrueif this annotation is present. Otherwise, returnfalse.- Parameters:
method- the method to check- Returns:
- whether the given method is deprecated method
-
excludedDeclaredClass
- Parameters:
declaredClass- the declared class to exclude- Returns:
- non-null
- Since:
- 2.7.6
-
getMethods
static List<Method> getMethods(Class<?> declaringClass, boolean includeInheritedTypes, boolean publicOnly, Predicate<Method>... methodsToFilter) Get allmethodsof the declared class- Parameters:
declaringClass- the declared classincludeInheritedTypes- include the inherited types, e,g. super classes or interfacespublicOnly- only public methodmethodsToFilter- (optional) the methods to be filtered- Returns:
- non-null read-only
List - Since:
- 2.7.6
-
getDeclaredMethods
static List<Method> getDeclaredMethods(Class<?> declaringClass, Predicate<Method>... methodsToFilter) Get all declaredmethodsof the declared class, excluding the inherited methods- Parameters:
declaringClass- the declared classmethodsToFilter- (optional) the methods to be filtered- Returns:
- non-null read-only
List - Since:
- 2.7.6
- See Also:
-
getMethods
Get all publicmethodsof the declared class, including the inherited methods.- Parameters:
declaringClass- the declared classmethodsToFilter- (optional) the methods to be filtered- Returns:
- non-null read-only
List - Since:
- 2.7.6
- See Also:
-
getAllDeclaredMethods
static List<Method> getAllDeclaredMethods(Class<?> declaringClass, Predicate<Method>... methodsToFilter) Get all declaredmethodsof the declared class, including the inherited methods.- Parameters:
declaringClass- the declared classmethodsToFilter- (optional) the methods to be filtered- Returns:
- non-null read-only
List - Since:
- 2.7.6
- See Also:
-
getAllMethods
Get all publicmethodsof the declared class, including the inherited methods.- Parameters:
declaringClass- the declared classmethodsToFilter- (optional) the methods to be filtered- Returns:
- non-null read-only
List - Since:
- 2.7.6
- See Also:
-
findMethod
Find theMethodby the the specified type and method name without the parameter types- Parameters:
type- the target typemethodName- the specified method name- Returns:
- if not found, return
null - Since:
- 2.7.6
-
findMethod
Find theMethodby the the specified type, method name and parameter types- Parameters:
type- the target typemethodName- the method nameparameterTypes- the parameter types- Returns:
- if not found, return
null - Since:
- 2.7.6
-
invokeMethod
Invoke the target object and method- Type Parameters:
T- the return type- Parameters:
object- the target objectmethodName- the method namemethodParameters- the method parameters- Returns:
- the target method's execution result
- Since:
- 2.7.6
-
overrides
Tests whether one method, as a member of a given type, overrides another method.- Parameters:
overrider- the first method, possible overrideroverridden- the second method, possibly being overridden- Returns:
trueif and only if the first method overrides the second- See Also:
-
findNearestOverriddenMethod
Find the nearest overriddenmethodfrom the inherited class- Parameters:
overrider- the overridermethod- Returns:
- if found, the overrider
method, ornull
-
findOverriddenMethod
Find the overriddenmethodfrom the declaring class -
extractFieldName
Extract fieldName from set/get/is method. if it's not a set/get/is method, return empty string. If method equals get/is/getClass/getObject, also return empty string.- Parameters:
method- method- Returns:
- fieldName
-
invokeAndReturnDouble
Invoke and return double value.- Parameters:
method- methodtargetObj- the object the method is invoked from- Returns:
- double value
-
invokeAndReturnLong
Invoke and return long value.- Parameters:
method- methodtargetObj- the object the method is invoked from- Returns:
- long value
-
toShortString
-
toShortString
-