类 ReflectUtils

java.lang.Object
com.dtflys.forest.utils.ReflectUtils

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

    • ReflectUtils

      public ReflectUtils()
  • 方法详细资料

    • toType

      public static Type toType(Type type)
      转换为 Type 接口实例
      参数:
      type - Type接口实例
      返回:
      Type 接口实例
    • toClass

      public static Class<?> toClass(Type genericType)
      转换为 Class 类型对象

      将抽象的 Type 接口实例转换为具体的 Class 类型对象实例

      参数:
      genericType - Type接口实例
      返回:
      Java类,Class类实例
    • toParameterizedType

      public static ParameterizedType toParameterizedType(Type type)
      转换为 ParameterizedType 类型对象

      将普通的 Type 类型对象转换为 ParameterizedType 类型对象

      通过 ParameterizedType 对象可以获取泛型的类型参数

      参数:
      type - 普通 Java Type 类型, Type 接口实例
      返回:
      带泛型参数的 Type 类型, ParameterizedType 接口实例
    • getGenericTypeArguments

      public static Type[] getGenericTypeArguments(Type type)
      获取所有泛型参数类型

      从一个带泛型的类型中获取其所有的泛型参数类型

      参数:
      type - Type 接口实例
      返回:
      多个泛型参数类型, Type 接口数组
    • getGenericArgument

      public static Type getGenericArgument(Type type, int index)
      根据下标获取单个泛型参数类型

      从一个带泛型的类型中获取其第 index 个泛型参数类型

      参数:
      type - Type 接口实例
      index - 泛型参数类型下标, 表示第几个泛型参数, 从0开始记
      返回:
      泛型参数类型, Type 接口实例
    • getGenericArgument

      public static Type getGenericArgument(Type type)
      获取第一个泛型参数类型

      从一个带泛型的类型中获取其第一个泛型参数类型

      参数:
      type - Type 接口实例
      返回:
      泛型参数类型, Type 接口实例
    • isPrimaryType

      public static boolean isPrimaryType(Class<?> type)
      是否是Java基本类型
      参数:
      type - Java类,Class类实例
      返回:
      true:是基本类型,false:不是基本类型
    • isPrimaryArrayType

      public static boolean isPrimaryArrayType(Class<?> type)
      是否为基本数组类型
      参数:
      type - Java类,Class类实例
      返回:
      true:是基本数组类型,false:不是基本数组类型
    • getAttributesFromAnnotation

      public static Map<String,Object> getAttributesFromAnnotation(Annotation ann)
    • getAttributesFromAnnotation

      public static Map<String,Object> getAttributesFromAnnotation(Annotation ann, boolean checkOverrideAttribute)
      从注解对象中获取所有属性
      参数:
      ann - 注解对象,Annotation接口实例
      checkOverrideAttribute - 是否检测属性重写
      返回:
      注解对象中有属性 Map表对象,Key:属性名 Value:属性值
    • isForestAnnotation

      public static boolean isForestAnnotation(Annotation annotation)
      判断是否为Forest注解
      参数:
      annotation - 注解对象
      返回:
      true: 是Forest注解;false: 不是Forest注解
    • isForestAnnotation

      public static boolean isForestAnnotation(Class<?> annotationType)
      判断是否为Forest注解
      参数:
      annotationType - 注解类
      返回:
      true: 是Forest注解;false: 不是Forest注解
    • isForestBaseAnnotation

      public static boolean isForestBaseAnnotation(Class<?> annotationType)
      判断是否为Forest接口注解
      参数:
      annotationType - 注解类
      返回:
      true: 是Forest接口注解;false: 不是Forest接口注解
    • isForestMethodAnnotation

      public static boolean isForestMethodAnnotation(Annotation annotation)
      判断是否为Forest方法注解
      参数:
      annotation - 注解对象
      返回:
      true: 是Forest方法注解;false: 不是Forest方法注解
    • isForestMethodAnnotation

      public static boolean isForestMethodAnnotation(Class<?> annotationType)
      判断是否为Forest方法注解
      参数:
      annotationType - 注解类
      返回:
      true: 是Forest方法注解;false: 不是Forest方法注解
    • isForestParamAnnotation

      public static boolean isForestParamAnnotation(Annotation annotation)
      判断是否为Forest注解
      参数:
      annotation - 注解对象
      返回:
      true: 是Forest参数注解;false: 不是Forest参数注解
    • isForestParamAnnotation

      public static boolean isForestParamAnnotation(Class<?> annotationType)
      判断是否为Forest参数注解
      参数:
      annotationType - 注解类
      返回:
      true: 是Forest参数注解;false: 不是Forest参数注解
    • canAnnotationUseForInterface

      public static boolean canAnnotationUseForInterface(Class<?> annotationType)
    • canAnnotationUseForMethod

      public static boolean canAnnotationUseForMethod(Class<?> annotationType)
    • canAnnotationUseForParam

      public static boolean canAnnotationUseForParam(Class<?> annotationType)
    • copyAnnotationAttributes

      public static void copyAnnotationAttributes(Annotation source, Object target)
    • convertObjectToMap

      public static Map convertObjectToMap(Object srcObj, ForestConfiguration configuration)
    • getFields

      public static Field[] getFields(Class<?> clazz)
      获取类中所有的字段 (包括所有父类的)
      参数:
      clazz - 类
      返回:
      字段列表
      从以下版本开始:
      1.5.30
    • getMethods

      public static Method[] getMethods(Class<?> clazz)
      获取类中所有的方法 (包括所有父类的)
      参数:
      clazz - 类
      返回:
      方法列表