Package dev.daymor.sakuraboot.util
Class ReflectionUtils
java.lang.Object
dev.daymor.sakuraboot.util.ReflectionUtils
Utility class for reflection.
- Since:
- 0.1.1
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final record
Class information with the actual class and parameters type. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T> Class
<T> findGenericTypeFromInterface
(Class<?> clazz, String interfaceTypeName) Find bean class from interface.<T> Class
<T> findGenericTypeFromInterface
(Class<?> clazz, String interfaceTypeName, int typeIndex) Find bean class from interface.getClassInfo
(Type type, ReflectionUtils.ClassInfo classInfo) Get the actual class from the type.Get a field from a class and make it accessible.boolean
isFieldExists
(Class<?> clazz, String fieldName) Check if a field exists from a class.
-
Constructor Details
-
ReflectionUtils
public ReflectionUtils()
-
-
Method Details
-
isFieldExists
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
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
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.
-