Package dev.voidframework.core.helper
Class Reflection
java.lang.Object
dev.voidframework.core.helper.Reflection
Reflection-based utility methods.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classAllows to wrap a complex class type (ie: Map{String, Integer}) -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcallMethod(Object classInstance, String methodeName, Class<?>[] argumentTypeArray, Object... argumentArray) Calls a method.static <RETURN_TYPE>
RETURN_TYPEcallMethod(Object classInstance, String methodeName, Class<RETURN_TYPE> 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 <VALUE_TYPE>
VALUE_TYPEgetFieldValue(Object classInstance, String fieldName, Reflection.WrappedClass<VALUE_TYPE> wrappedClass) Retrieves the value of a specific field.static <VALUE_TYPE>
VALUE_TYPEgetFieldValue(Object classInstance, String fieldName, Class<VALUE_TYPE> 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.
-
Constructor Details
-
Reflection
public Reflection()
-
-
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
public static <VALUE_TYPE> VALUE_TYPE getFieldValue(Object classInstance, String fieldName, Class<VALUE_TYPE> valueTypeClass) Retrieves the value of a specific field.- Type Parameters:
VALUE_TYPE- 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 <VALUE_TYPE> VALUE_TYPE getFieldValue(Object classInstance, String fieldName, Reflection.WrappedClass<VALUE_TYPE> wrappedClass) Retrieves the value of a specific field.- Type Parameters:
VALUE_TYPE- 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 <RETURN_TYPE> RETURN_TYPE callMethod(Object classInstance, String methodeName, Class<RETURN_TYPE> returnTypeClass, Class<?>[] argumentTypeArray, Object... argumentArray) Calls a method.- Type Parameters:
RETURN_TYPE- 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
-