类 ReflectUtils
- java.lang.Object
-
- com.alibaba.dubbo.common.utils.ReflectUtils
-
public final class ReflectUtils extends Object
ReflectUtils
-
-
字段概要
字段 修饰符和类型 字段 说明 static String
ARRAY_DESC
static String
CLASS_DESC
static Pattern
DESC_PATTERN
static String
DESC_REGEX
static Class<?>[]
EMPTY_CLASS_ARRAY
static Pattern
GETTER_METHOD_DESC_PATTERN
static Pattern
IS_HAS_CAN_METHOD_DESC_PATTERN
static String
JAVA_IDENT_REGEX
static String
JAVA_NAME_REGEX
static char
JVM_BOOLEAN
boolean(Z).static char
JVM_BYTE
byte(B).static char
JVM_CHAR
char(C).static char
JVM_DOUBLE
double(D).static char
JVM_FLOAT
float(F).static char
JVM_INT
int(I).static char
JVM_LONG
long(J).static char
JVM_SHORT
short(S).static char
JVM_VOID
void(V).static Pattern
METHOD_DESC_PATTERN
static String
METHOD_DESC_REGEX
static Pattern
SETTER_METHOD_DESC_PATTERN
-
方法概要
所有方法 静态方法 具体方法 修饰符和类型 方法 说明 static Class<?>
desc2class(String desc)
desc to class.static Class<?>[]
desc2classArray(String desc)
get class array instance.static String
desc2name(String desc)
desc to name.static Constructor<?>
findConstructor(Class<?> clazz, Class<?> paramType)
static Method
findMethodByMethodName(Class<?> clazz, String methodName)
static Method
findMethodByMethodSignature(Class<?> clazz, String methodName, String[] parameterTypes)
Find method from method signaturestatic Class<?>
forName(String name)
static Map<String,Field>
getBeanPropertyFields(Class cl)
static Map<String,Method>
getBeanPropertyReadMethods(Class cl)
static Class<?>
getBoxedClass(Class<?> c)
static String
getCodeBase(Class<?> cls)
static String
getDesc(Class<?> c)
get class desc.static String
getDesc(Class<?>[] cs)
get class array desc.static String
getDesc(Constructor<?> c)
get constructor desc. "()V", "(Ljava/lang/String;I)V"static String
getDesc(Method m)
get method desc.static String
getDesc(javassist.CtClass c)
get class desc.static String
getDesc(javassist.CtConstructor c)
get constructor desc. "()V", "(Ljava/lang/String;I)V"static String
getDesc(javassist.CtMethod m)
get method desc.static String
getDescWithoutMethodName(Method m)
get method desc.static String
getDescWithoutMethodName(javassist.CtMethod m)
get method desc.static Object
getEmptyObject(Class<?> returnType)
static Class<?>
getGenericClass(Class<?> cls)
static Class<?>
getGenericClass(Class<?> cls, int i)
static String
getName(Class<?> c)
get name.static String
getName(Constructor<?> c)
get constructor name. "()", "(java.lang.String,int)"static String
getName(Method m)
get method name.static String
getPropertyNameFromBeanReadMethod(Method method)
static String
getPropertyNameFromBeanWriteMethod(Method method)
static String
getSignature(String methodName, Class<?>[] parameterTypes)
static boolean
isBeanPropertyReadMethod(Method method)
static boolean
isBeanPropertyWriteMethod(Method method)
static boolean
isCompatible(Class<?>[] cs, Object[] os)
is compatible.static boolean
isCompatible(Class<?> c, Object o)
is compatible.static boolean
isInstance(Object obj, String interfaceClazzName)
Check if one object is the implementation for a given interface.static boolean
isPrimitive(Class<?> cls)
static boolean
isPrimitives(Class<?> cls)
static boolean
isPublicInstanceField(Field field)
static Class<?>
name2class(String name)
name to class.static String
name2desc(String name)
name to desc.
-
-
-
字段详细资料
-
JVM_VOID
public static final char JVM_VOID
void(V).- 另请参阅:
- 常量字段值
-
JVM_BOOLEAN
public static final char JVM_BOOLEAN
boolean(Z).- 另请参阅:
- 常量字段值
-
JVM_BYTE
public static final char JVM_BYTE
byte(B).- 另请参阅:
- 常量字段值
-
JVM_CHAR
public static final char JVM_CHAR
char(C).- 另请参阅:
- 常量字段值
-
JVM_DOUBLE
public static final char JVM_DOUBLE
double(D).- 另请参阅:
- 常量字段值
-
JVM_FLOAT
public static final char JVM_FLOAT
float(F).- 另请参阅:
- 常量字段值
-
JVM_INT
public static final char JVM_INT
int(I).- 另请参阅:
- 常量字段值
-
JVM_LONG
public static final char JVM_LONG
long(J).- 另请参阅:
- 常量字段值
-
JVM_SHORT
public static final char JVM_SHORT
short(S).- 另请参阅:
- 常量字段值
-
EMPTY_CLASS_ARRAY
public static final Class<?>[] EMPTY_CLASS_ARRAY
-
DESC_PATTERN
public static final Pattern DESC_PATTERN
-
METHOD_DESC_PATTERN
public static final Pattern METHOD_DESC_PATTERN
-
GETTER_METHOD_DESC_PATTERN
public static final Pattern GETTER_METHOD_DESC_PATTERN
-
SETTER_METHOD_DESC_PATTERN
public static final Pattern SETTER_METHOD_DESC_PATTERN
-
IS_HAS_CAN_METHOD_DESC_PATTERN
public static final Pattern IS_HAS_CAN_METHOD_DESC_PATTERN
-
-
方法详细资料
-
isPrimitives
public static boolean isPrimitives(Class<?> cls)
-
isPrimitive
public static boolean isPrimitive(Class<?> cls)
-
isCompatible
public static boolean isCompatible(Class<?> c, Object o)
is compatible.- 参数:
c
- class.o
- instance.- 返回:
- compatible or not.
-
isCompatible
public static boolean isCompatible(Class<?>[] cs, Object[] os)
is compatible.- 参数:
cs
- class array.os
- object array.- 返回:
- compatible or not.
-
getName
public static String getName(Class<?> c)
get name. java.lang.Object[][].class => "java.lang.Object[][]"- 参数:
c
- class.- 返回:
- name.
-
getName
public static String getName(Method m)
get method name. "void do(int)", "void do()", "int do(java.lang.String,boolean)"- 参数:
m
- method.- 返回:
- name.
-
getName
public static String getName(Constructor<?> c)
get constructor name. "()", "(java.lang.String,int)"- 参数:
c
- constructor.- 返回:
- name.
-
getDesc
public static String getDesc(Class<?> c)
get class desc. boolean[].class => "[Z" Object.class => "Ljava/lang/Object;"- 参数:
c
- class.- 返回:
- desc.
- 抛出:
javassist.NotFoundException
-
getDesc
public static String getDesc(Class<?>[] cs)
get class array desc. [int.class, boolean[].class, Object.class] => "I[ZLjava/lang/Object;"- 参数:
cs
- class array.- 返回:
- desc.
- 抛出:
javassist.NotFoundException
-
getDesc
public static String getDesc(Method m)
get method desc. int do(int arg1) => "do(I)I" void do(String arg1,boolean arg2) => "do(Ljava/lang/String;Z)V"- 参数:
m
- method.- 返回:
- desc.
-
getDesc
public static String getDesc(Constructor<?> c)
get constructor desc. "()V", "(Ljava/lang/String;I)V"- 参数:
c
- constructor.- 返回:
- desc
-
getDescWithoutMethodName
public static String getDescWithoutMethodName(Method m)
get method desc. "(I)I", "()V", "(Ljava/lang/String;Z)V"- 参数:
m
- method.- 返回:
- desc.
-
getDesc
public static String getDesc(javassist.CtClass c) throws javassist.NotFoundException
get class desc. Object.class => "Ljava/lang/Object;" boolean[].class => "[Z"- 参数:
c
- class.- 返回:
- desc.
- 抛出:
javassist.NotFoundException
-
getDesc
public static String getDesc(javassist.CtMethod m) throws javassist.NotFoundException
get method desc. "do(I)I", "do()V", "do(Ljava/lang/String;Z)V"- 参数:
m
- method.- 返回:
- desc.
- 抛出:
javassist.NotFoundException
-
getDesc
public static String getDesc(javassist.CtConstructor c) throws javassist.NotFoundException
get constructor desc. "()V", "(Ljava/lang/String;I)V"- 参数:
c
- constructor.- 返回:
- desc
- 抛出:
javassist.NotFoundException
-
getDescWithoutMethodName
public static String getDescWithoutMethodName(javassist.CtMethod m) throws javassist.NotFoundException
get method desc. "(I)I", "()V", "(Ljava/lang/String;Z)V".- 参数:
m
- method.- 返回:
- desc.
- 抛出:
javassist.NotFoundException
-
name2desc
public static String name2desc(String name)
name to desc. java.util.Map[][] => "[[Ljava/util/Map;"- 参数:
name
- name.- 返回:
- desc.
-
desc2name
public static String desc2name(String desc)
desc to name. "[[I" => "int[][]"- 参数:
desc
- desc.- 返回:
- name.
-
name2class
public static Class<?> name2class(String name) throws ClassNotFoundException
name to class. "boolean" => boolean.class "java.util.Map[][]" => java.util.Map[][].class- 参数:
name
- name.- 返回:
- Class instance.
- 抛出:
ClassNotFoundException
-
desc2class
public static Class<?> desc2class(String desc) throws ClassNotFoundException
desc to class. "[Z" => boolean[].class "[[Ljava/util/Map;" => java.util.Map[][].class- 参数:
desc
- desc.- 返回:
- Class instance.
- 抛出:
ClassNotFoundException
-
desc2classArray
public static Class<?>[] desc2classArray(String desc) throws ClassNotFoundException
get class array instance.- 参数:
desc
- desc.- 返回:
- Class class array.
- 抛出:
ClassNotFoundException
-
findMethodByMethodSignature
public static Method findMethodByMethodSignature(Class<?> clazz, String methodName, String[] parameterTypes) throws NoSuchMethodException, ClassNotFoundException
Find method from method signature- 参数:
clazz
- Target class to find methodmethodName
- Method signature, e.g.: method1(int, String). It is allowed to provide method name only, e.g.: method2- 返回:
- target method
- 抛出:
NoSuchMethodException
ClassNotFoundException
IllegalStateException
- when multiple methods are found (overridden method when parameter info is not provided)
-
findMethodByMethodName
public static Method findMethodByMethodName(Class<?> clazz, String methodName) throws NoSuchMethodException, ClassNotFoundException
-
findConstructor
public static Constructor<?> findConstructor(Class<?> clazz, Class<?> paramType) throws NoSuchMethodException
-
isInstance
public static boolean isInstance(Object obj, String interfaceClazzName)
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
- 参数:
obj
- Object to examineinterfaceClazzName
- The given interface- 返回:
- true if the object implements the given interface, otherwise return false
-
isBeanPropertyReadMethod
public static boolean isBeanPropertyReadMethod(Method method)
-
getPropertyNameFromBeanReadMethod
public static String getPropertyNameFromBeanReadMethod(Method method)
-
isBeanPropertyWriteMethod
public static boolean isBeanPropertyWriteMethod(Method method)
-
getPropertyNameFromBeanWriteMethod
public static String getPropertyNameFromBeanWriteMethod(Method method)
-
isPublicInstanceField
public static boolean isPublicInstanceField(Field field)
-
-