Class ReflectionUtils

java.lang.Object
dev.daymor.sakuraboot.util.ReflectionUtils

public class ReflectionUtils extends Object
Utility class for reflection.
Since:
0.1.1
  • Constructor Details

    • ReflectionUtils

      public ReflectionUtils()
  • Method Details

    • isFieldExists

      public boolean isFieldExists(Class<?> clazz, String fieldName)
      Check if a field exists from a class. Get the field from the superclass if the field is not found in the class.
      Parameters:
      clazz - The class to check the field from.
      fieldName - The name of the field.
      Returns:
      true if the field exists, false otherwise.
    • getField

      public Field getField(Class<?> clazz, String fieldName)
      Get a field from a class and make it accessible. Get the field from the superclass if the field is not found in the class.
      Parameters:
      clazz - The class to get the field from.
      fieldName - The name of the field.
      Returns:
      A Field.
      Throws:
      BadRequestException - If the field is not found.
    • findGenericTypeFromInterface

      public <T> Class<T> findGenericTypeFromInterface(Class<?> clazz, String interfaceTypeName, int typeIndex)
      Find bean class from interface.
      Type Parameters:
      T - the type of the bean.
      Parameters:
      clazz - the class of the bean.
      interfaceTypeName - the interface type name.
      typeIndex - index of the type from the interface.
      Returns:
      the bean class retrieved from the interface.
    • findGenericTypeFromInterface

      public <T> Class<T> findGenericTypeFromInterface(Class<?> clazz, String interfaceTypeName)
      Find bean class from interface.
      Type Parameters:
      T - the type of the bean.
      Parameters:
      clazz - the class of the bean.
      interfaceTypeName - the interface type name.
      Returns:
      the bean class retrieved from the interface.
    • getClassInfo

      public ReflectionUtils.ClassInfo getClassInfo(Type type, @Nullable ReflectionUtils.ClassInfo classInfo)
      Get the actual class from the type. If reflection can't find the actual class, return a raw class or upper-bound or lower-bound class. If the raw class is returned, return also the parameters type.
      Parameters:
      type - The type to get the class from.
      classInfo - The actual class information that can help to find the class.
      Returns:
      The class information of the given type.