Package org.apache.dubbo.common.utils
Class ReflectUtils
java.lang.Object
org.apache.dubbo.common.utils.ReflectUtils
ReflectUtils
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final Patternstatic final Stringstatic final Class<?>[]static final Patternstatic final Patternstatic final Stringstatic final Stringstatic final charboolean(Z).static final charbyte(B).static final charchar(C).static final chardouble(D).static final charfloat(F).static final charint(I).static final charlong(J).static final charshort(S).static final charvoid(V).static final Patternstatic final Stringstatic final Pattern -
Method Summary
Modifier and TypeMethodDescriptionstatic booleancheckZeroArgConstructor(Class clazz) static ObjectdefaultReturn(Class<?> classType) static Objectstatic Class<?> desc2class(String desc) desc to class.static Class<?>[]desc2classArray(String desc) get class array instance.static Stringdesc to name.static Constructor<?> findConstructor(Class<?> clazz, Class<?> paramType) findHierarchicalTypes(Class<?> sourceClass, Class<T> matchType) static MethodfindMethodByMethodName(Class<?> clazz, String methodName) Deprecated.static MethodfindMethodByMethodSignature(Class<?> clazz, String methodName, String[] parameterTypes) Deprecated.static Set<ParameterizedType> findParameterizedTypes(Class<?> sourceClass) Find theSetofParameterizedTypestatic Class<?> forName(ClassLoader cl, String name) static Class<?> getAllFieldNames(Class<?> type) Get all field names of target typestatic Class<?> getBoxedClass(Class<?> c) static StringgetCodeBase(Class<?> cls) static Stringget class desc.static Stringget class array desc.static StringgetDesc(Constructor<?> c) get constructor desc. "()V", "(Ljava/lang/String;I)V"static Stringget method desc.static StringgetDesc(javassist.CtClass c) get class desc.static StringgetDesc(javassist.CtConstructor c) get constructor desc. "()V", "(Ljava/lang/String;I)V"static StringgetDesc(javassist.CtMethod m) get method desc.static String[]static Stringget method desc.static StringgetDescWithoutMethodName(javassist.CtMethod m) get method desc.static ObjectgetEmptyObject(Class<?> returnType) static <T> TgetFieldValue(Object obj, String fieldName) static Class<?> getGenericClass(Class<?> cls) static Class<?> getGenericClass(Class<?> cls, int i) static Stringget name.static StringgetName(Constructor<?> c) get constructor name. "()", "(java.lang.String,int)"static Stringget method name.static <T> TgetProperty(Object bean, String methodName) Get the value from the specified bean and its getter method.static Stringstatic Stringstatic Type[]getReturnTypes(Method method) static StringgetSignature(String methodName, Class<?>[] parameterTypes) static booleanCheck target bean class whether has specify methodstatic booleanisBeanPropertyReadMethod(Method method) static booleanisBeanPropertyWriteMethod(Method method) static booleanisCompatible(Class<?>[] cs, Object[] os) is compatible.static booleanisCompatible(Class<?> c, Object o) is compatible.static booleanisInstance(Object obj, String interfaceClazzName) Check if one object is the implementation for a given interface.static booleanstatic booleanisPrimitive(Class<?> cls) static booleanisPrimitives(Class<?> cls) static booleanisPublicInstanceField(Field field) static voidmakeAccessible(Method method) Copy from org.springframework.util.ReflectionUtils.static Class<?> name2class(String name) name to class.static Stringname to desc.static Class[]resolveTypes(Object... values) Resolve the types of the specified values
-
Field Details
-
JVM_VOID
public static final char JVM_VOIDvoid(V).- See Also:
-
JVM_BOOLEAN
public static final char JVM_BOOLEANboolean(Z).- See Also:
-
JVM_BYTE
public static final char JVM_BYTEbyte(B).- See Also:
-
JVM_CHAR
public static final char JVM_CHARchar(C).- See Also:
-
JVM_DOUBLE
public static final char JVM_DOUBLEdouble(D).- See Also:
-
JVM_FLOAT
public static final char JVM_FLOATfloat(F).- See Also:
-
JVM_INT
public static final char JVM_INTint(I).- See Also:
-
JVM_LONG
public static final char JVM_LONGlong(J).- See Also:
-
JVM_SHORT
public static final char JVM_SHORTshort(S).- See Also:
-
EMPTY_CLASS_ARRAY
-
JAVA_IDENT_REGEX
- See Also:
-
JAVA_NAME_REGEX
- See Also:
-
CLASS_DESC
- See Also:
-
ARRAY_DESC
- See Also:
-
DESC_REGEX
- See Also:
-
DESC_PATTERN
-
METHOD_DESC_REGEX
- See Also:
-
METHOD_DESC_PATTERN
-
GETTER_METHOD_DESC_PATTERN
-
SETTER_METHOD_DESC_PATTERN
-
IS_HAS_CAN_METHOD_DESC_PATTERN
-
-
Method Details
-
isPrimitives
-
isPrimitive
-
getBoxedClass
-
isCompatible
is compatible.- Parameters:
c- class.o- instance.- Returns:
- compatible or not.
-
isCompatible
is compatible.- Parameters:
cs- class array.os- object array.- Returns:
- compatible or not.
-
getCodeBase
-
getName
get name. java.lang.Object[][].class => "java.lang.Object[][]"- Parameters:
c- class.- Returns:
- name.
-
getGenericClass
-
getGenericClass
-
getName
get method name. "void do(int)", "void do()", "int do(java.lang.String,boolean)"- Parameters:
m- method.- Returns:
- name.
-
getSignature
-
getName
get constructor name. "()", "(java.lang.String,int)"- Parameters:
c- constructor.- Returns:
- name.
-
getDesc
get class desc. boolean[].class => "[Z" Object.class => "Ljava/lang/Object;"- Parameters:
c- class.- Returns:
- desc.
- Throws:
javassist.NotFoundException
-
getDesc
get class array desc. [int.class, boolean[].class, Object.class] => "I[ZLjava/lang/Object;"- Parameters:
cs- class array.- Returns:
- desc.
- Throws:
javassist.NotFoundException
-
getDesc
get method desc. int do(int arg1) => "do(I)I" void do(String arg1,boolean arg2) => "do(Ljava/lang/String;Z)V"- Parameters:
m- method.- Returns:
- desc.
-
getDescArray
-
getDesc
get constructor desc. "()V", "(Ljava/lang/String;I)V"- Parameters:
c- constructor.- Returns:
- desc
-
getDescWithoutMethodName
get method desc. "(I)I", "()V", "(Ljava/lang/String;Z)V"- Parameters:
m- method.- Returns:
- desc.
-
getDesc
get class desc. Object.class => "Ljava/lang/Object;" boolean[].class => "[Z"- Parameters:
c- class.- Returns:
- desc.
- Throws:
javassist.NotFoundException
-
getDesc
get method desc. "do(I)I", "do()V", "do(Ljava/lang/String;Z)V"- Parameters:
m- method.- Returns:
- desc.
- Throws:
javassist.NotFoundException
-
getDesc
get constructor desc. "()V", "(Ljava/lang/String;I)V"- Parameters:
c- constructor.- Returns:
- desc
- Throws:
javassist.NotFoundException
-
getDescWithoutMethodName
public static String getDescWithoutMethodName(javassist.CtMethod m) throws javassist.NotFoundException get method desc. "(I)I", "()V", "(Ljava/lang/String;Z)V".- Parameters:
m- method.- Returns:
- desc.
- Throws:
javassist.NotFoundException
-
name2desc
name to desc. java.util.Map[][] => "[[Ljava/util/Map;"- Parameters:
name- name.- Returns:
- desc.
-
desc2name
desc to name. "[[I" => "int[][]"- Parameters:
desc- desc.- Returns:
- name.
-
forName
-
forName
-
name2class
name to class. "boolean" => boolean.class "java.util.Map[][]" => java.util.Map[][].class- Parameters:
name- name.- Returns:
- Class instance.
- Throws:
ClassNotFoundException
-
desc2class
desc to class. "[Z" => boolean[].class "[[Ljava/util/Map;" => java.util.Map[][].class- Parameters:
desc- desc.- Returns:
- Class instance.
- Throws:
ClassNotFoundException
-
desc2classArray
get class array instance.- Parameters:
desc- desc.- Returns:
- Class class array.
- Throws:
ClassNotFoundException
-
findMethodByMethodSignature
@Deprecated public static Method findMethodByMethodSignature(Class<?> clazz, String methodName, String[] parameterTypes) throws NoSuchMethodException, ClassNotFoundException Deprecated.Find method from method signature- Parameters:
clazz- Target class to find methodmethodName- Method signature, e.g.: method1(int, String). It is allowed to provide method name only, e.g.: method2- Returns:
- target method
- Throws:
NoSuchMethodExceptionClassNotFoundExceptionIllegalStateException- when multiple methods are found (overridden method when parameter info is not provided)
-
findMethodByMethodName
@Deprecated public static Method findMethodByMethodName(Class<?> clazz, String methodName) throws NoSuchMethodException, ClassNotFoundException Deprecated.- Parameters:
clazz- Target class to find methodmethodName- Method signature, e.g.: method1(int, String). It is allowed to provide method name only, e.g.: method2- Returns:
- target method
- Throws:
NoSuchMethodExceptionClassNotFoundExceptionIllegalStateException- when multiple methods are found (overridden method when parameter info is not provided)
-
findConstructor
public static Constructor<?> findConstructor(Class<?> clazz, Class<?> paramType) throws NoSuchMethodException - Throws:
NoSuchMethodException
-
isInstance
Check if one object is the implementation for a given interface.This method will not trigger classloading for the given interface, therefore it will not lead to error when the given interface is not visible by the classloader
- Parameters:
obj- Object to examineinterfaceClazzName- The given interface- Returns:
- true if the object implements the given interface, otherwise return false
-
getEmptyObject
-
defaultReturn
-
defaultReturn
-
isBeanPropertyReadMethod
-
getPropertyNameFromBeanReadMethod
-
isBeanPropertyWriteMethod
-
getPropertyNameFromBeanWriteMethod
-
isPublicInstanceField
-
getBeanPropertyFields
-
getBeanPropertyReadMethods
-
getReturnTypes
-
findParameterizedTypes
Find theSetofParameterizedType -
findHierarchicalTypes
-
getProperty
Get the value from the specified bean and its getter method.- Type Parameters:
T- the type of property value- Parameters:
bean- the bean instancemethodName- the name of getter- Returns:
- Since:
- 2.7.5
-
hasMethod
Check target bean class whether has specify method- Parameters:
beanClass-methodName-- Returns:
-
resolveTypes
Resolve the types of the specified values- Parameters:
values- the values- Returns:
- If can't be resolved, return
empty class array - Since:
- 2.7.6
-
checkZeroArgConstructor
-
isJdk
-
makeAccessible
Copy from org.springframework.util.ReflectionUtils. Make the given method accessible, explicitly setting it accessible if necessary. ThesetAccessible(true)method is only called when actually necessary, to avoid unnecessary conflicts with a JVM SecurityManager (if active).- Parameters:
method- the method to make accessible- See Also:
-
getAllFieldNames
Get all field names of target type- Parameters:
type-- Returns:
-
getFieldValue
- Throws:
RuntimeException
-
MethodUtils.findMethod(Class, String, Class[])