类 ReflectionUtils

java.lang.Object
com.github.aqiu202.util.ReflectionUtils

public abstract class ReflectionUtils extends Object
  • 构造器详细资料

    • ReflectionUtils

      public ReflectionUtils()
  • 方法详细资料

    • makeAccessible

      public static void makeAccessible(@Nonnull Constructor<?> ctor)
      使构造器可访问
      参数:
      ctor - 构造器
    • makeAccessible

      public static void makeAccessible(@Nonnull Method method)
      使方法可访问
      参数:
      method - 方法
    • makeAccessible

      public static void makeAccessible(@Nonnull Field field)
      使字段可访问
      参数:
      field - 字段
    • newInstance

      public static Object newInstance(Constructor<?> constructor, Object... args)
    • getAllMethod

      public static ReflectionUtils.ClassMethods getAllMethod(@Nonnull Class<?> type)
      获取所有的方法(包含私有方法,但不包含abstract和static修饰的方法)
      参数:
      type - 类型
      返回:
      所有方法集合
    • getAllMethod

      public static ReflectionUtils.ClassMethods getAllMethod(@Nonnull Class<?> type, ReflectionUtils.ScanDirection direction)
      获取所有的方法(包含私有方法,但不包含abstract和static修饰的方法)
      参数:
      type - 类型
      direction - 扫描方向
      返回:
      所有方法集合
    • getMethods

      public static ReflectionUtils.ClassMethods getMethods(@Nonnull Class<?> type)
      获取所有的方法(不包含私有方法)
      参数:
      type - 类型
      返回:
      所有方法集合
    • getMethod

      public static Method getMethod(@Nonnull Class<?> type, String methodName, Class<?>... args)
    • invokeMethod

      public static Object invokeMethod(@Nonnull Method method, Object instance, Object... args)
    • getAllField

      public static ReflectionUtils.ClassFields getAllField(@Nonnull Class<?> type)
      获取所有的属性(包含私有属性,但不包含final和static修饰的属性)
      参数:
      type - 类型
      返回:
      所有属性集合
    • getAllField

      public static ReflectionUtils.ClassFields getAllField(@Nonnull Class<?> type, ReflectionUtils.ScanDirection direction)
    • getFields

      public static ReflectionUtils.ClassFields getFields(@Nonnull Class<?> type)
      获取所有的属性(不包含私有属性)
      参数:
      type - 类型
      返回:
      所有属性集合
    • getField

      public static Field getField(@Nonnull Class<?> type, String fieldName)
    • getDeclaredConstructors

      public static Constructor<?>[] getDeclaredConstructors(@Nonnull Class<?> type)
    • getConstructors

      public static Constructor<?>[] getConstructors(@Nonnull Class<?> type)
    • getDefaultConstructor

      public static Constructor<?> getDefaultConstructor(@Nonnull Class<?> type)
    • getValue

      public static Object getValue(@Nullable Object target, Field field)
      获取对象某个字段的值
      参数:
      target - 对象
      field - 字段
      返回:
      字段值
    • getComplexValue

      public static Object getComplexValue(@Nonnull Object target, String complexFieldName)
      获取对象某个字段的值
      参数:
      target - 对象
      complexFieldName - 字段名称 以点"."拼接
      返回:
      字段值
    • getComplexValue

      public static Object getComplexValue(@Nonnull Object target, String complexFieldName, String separator)
      获取对象某个字段的值
      参数:
      target - 对象
      complexFieldName - 字段名称
      separator - 字段分隔符
      返回:
      字段值
    • getValue

      public static Object getValue(@Nonnull Object target, String[] fieldNames)
      获取对象某个字段的值
      参数:
      target - 对象
      fieldNames - 字段名称数组
      返回:
      字段值
    • getValue

      public static Object getValue(@Nonnull Object target, String fieldName)
      获取对象某个字段的值
      参数:
      target - 对象
      fieldName - 字段名称
      返回:
      字段值
    • setValue

      public static Object setValue(@Nonnull Object target, String fieldName, Object value)
      给对象的某个字段赋值
      参数:
      target - 对象
      fieldName - 字段名称
      value - 字段值
      返回:
      字段值
    • setValue

      public static Object setValue(@Nonnull Object target, Field field, Object value)
      获取对象某个字段的值
      参数:
      target - 对象
      field - 字段
      value - 字段值
      返回:
      字段值
    • getAnnotation

      public static <T extends Annotation> T getAnnotation(@Nonnull AnnotatedElement element, Class<T> annotationType)
    • getAnnotations

      public static <T extends Annotation> List<T> getAnnotations(@Nonnull AnnotatedElement element, Class<T> annotationType)
    • findAnnotation

      public static <T extends Annotation> T findAnnotation(@Nonnull AnnotatedElement element, Class<T> annotationType)
    • findAnnotations

      public static <T extends Annotation> List<T> findAnnotations(@Nonnull AnnotatedElement element, Class<T> annotationType)
    • isAnnotationPresent

      public static boolean isAnnotationPresent(@Nonnull AnnotatedElement element, Class<? extends Annotation> annotation)
    • hasAnnotationPresent

      public static boolean hasAnnotationPresent(@Nonnull AnnotatedElement element, Class<? extends Annotation>... annotationTypes)
    • hasAnnotation

      public static boolean hasAnnotation(@Nonnull AnnotatedElement element, Class<? extends Annotation>... annotationTypes)
    • hasAnnotation

      public static boolean hasAnnotation(@Nonnull AnnotatedElement element, Class<? extends Annotation> annotationType)
    • generateMethodKey

      public static String generateMethodKey(@Nonnull Method method)
    • generateKey

      public static String generateKey(@Nonnull Class<?> type, String methodName, Class<?>... parameterTypes)
    • generateKey

      public static String generateKey(String methodName, Class<?>... parameterTypes)
    • getMethodDescriptor

      public static String getMethodDescriptor(Method method)
    • getTypeDescriptor

      public static String getTypeDescriptor(Class<?> type)