Package dev.voidframework.core.utils
Class ReflectionUtils
java.lang.Object
dev.voidframework.core.utils.ReflectionUtils
Reflection-based utility methods.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classAllows to wrap a complex class type (ie: Map{String, Integer}) -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcallMethod(Object classInstance, String methodeName, Class<?>[] argumentTypeArray, Object... argumentArray) Calls a method.static <T> TcallMethod(Object classInstance, String methodeName, Class<T> returnTypeClass, Class<?>[] argumentTypeArray, Object... argumentArray) Calls a method.static FieldgetAnnotatedField(Class<?> classType, Class<? extends Annotation> annotationClassType) Retrieves a specific annotated field.static FieldgetAnnotatedField(Object classInstance, Class<? extends Annotation> annotationClassType) Retrieves a specific annotated field.static <T> TgetFieldValue(Object classInstance, String fieldName, ReflectionUtils.WrappedClass<T> wrappedClass) Retrieves the value of a specific field.static <T> TgetFieldValue(Object classInstance, String fieldName, Class<T> valueTypeClass) Retrieves the value of a specific field.static MethodresolveMethod(String methodName, Class<?> classType) Resolves a methode from it name.static voidsetFieldValue(Object classInstance, String fieldName, Object value) Sets the value of a specific field.
-
Method Details
-
getAnnotatedField
public static Field getAnnotatedField(Object classInstance, Class<? extends Annotation> annotationClassType) Retrieves a specific annotated field.- Parameters:
classInstance- The instance of the class in which the field is locatedannotationClassType- The annotation- Returns:
- The field, otherwise, null
-
getAnnotatedField
public static Field getAnnotatedField(Class<?> classType, Class<? extends Annotation> annotationClassType) Retrieves a specific annotated field.- Parameters:
classType- The class type in which the field is locatedannotationClassType- The annotation- Returns:
- The field, otherwise, null
-
getFieldValue
Retrieves the value of a specific field.- Type Parameters:
T- The value type- Parameters:
classInstance- The instance of the class in which the field is locatedfieldName- The field namevalueTypeClass- The value class type- Returns:
- The field value, otherwise, null
-
getFieldValue
public static <T> T getFieldValue(Object classInstance, String fieldName, ReflectionUtils.WrappedClass<T> wrappedClass) Retrieves the value of a specific field.- Type Parameters:
T- The value type- Parameters:
classInstance- The instance of the class in which the field is locatedfieldName- The field namewrappedClass- The value class type (wrapped)- Returns:
- The field value, otherwise, null
-
setFieldValue
Sets the value of a specific field.- Parameters:
classInstance- The instance of the class in which the field is locatedfieldName- The field namevalue- The value
-
resolveMethod
Resolves a methode from it name.- Parameters:
methodName- The method nameclassType- The class where are located this method- Returns:
- The method
-
callMethod
public static <T> T callMethod(Object classInstance, String methodeName, Class<T> returnTypeClass, Class<?>[] argumentTypeArray, Object... argumentArray) Calls a method.- Type Parameters:
T- Type of the return value- Parameters:
classInstance- The instance of the class in which the method is locatedmethodeName- The method namereturnTypeClass- The returned value typeargumentTypeArray- The method argument typesargumentArray- The method arguments- Returns:
- The method call result
-
callMethod
public static void callMethod(Object classInstance, String methodeName, Class<?>[] argumentTypeArray, Object... argumentArray) Calls a method.- Parameters:
classInstance- The instance of the class in which the method is locatedmethodeName- The method nameargumentTypeArray- The method argument typesargumentArray- The method arguments
-