Class ReflectHelper
- java.lang.Object
-
- com.onarandombox.MultiverseCore.utils.ReflectHelper
-
public class ReflectHelper extends java.lang.ObjectUtility class used to help in doing various reflection actions.
-
-
Constructor Summary
Constructors Constructor Description ReflectHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static @Nullable java.lang.Class<?>getClass(java.lang.String classPath)Try to get theClassbased on its classpath.static <C> @Nullable java.lang.reflect.FieldgetField(C classInstance, java.lang.String fieldName)Try to get aFieldfrom a given class.static <C> @Nullable java.lang.reflect.FieldgetField(java.lang.Class<C> clazz, java.lang.String fieldName)Try to get aFieldfrom a given class.static <C,V>
VgetFieldValue(C classInstance, java.lang.reflect.Field field)Gets the value of anFieldfrom an instance of the class responsible.static <C> @Nullable java.lang.reflect.MethodgetMethod(C classInstance, java.lang.String methodName, java.lang.Class<?>... parameterTypes)Try to get aMethodfrom a given class.static <C> @Nullable java.lang.reflect.MethodgetMethod(java.lang.Class<C> clazz, java.lang.String methodName, java.lang.Class<?>... parameterTypes)Try to get aMethodfrom a given class.static booleanhasClass(java.lang.String classPath)Check if theClassfor a give classpath is present/valid.static <C,R>
RinvokeMethod(C classInstance, java.lang.reflect.Method method, java.lang.Object... parameters)Calls aMethod.
-
-
-
Method Detail
-
getClass
@Nullable public static @Nullable java.lang.Class<?> getClass(java.lang.String classPath)
Try to get theClassbased on its classpath.- Parameters:
classPath- The target classpath.- Returns:
- A
Classif found, else null.
-
hasClass
public static boolean hasClass(java.lang.String classPath)
Check if theClassfor a give classpath is present/valid.- Parameters:
classPath- Target classpath.- Returns:
- True if class path is a valid class, else false.
-
getMethod
@Nullable public static <C> @Nullable java.lang.reflect.Method getMethod(java.lang.Class<C> clazz, java.lang.String methodName, java.lang.Class<?>... parameterTypes)Try to get aMethodfrom a given class.- Type Parameters:
C- The class type.- Parameters:
clazz- The class to search the method on.methodName- Name of the method to get.parameterTypes- Parameters present for that method.- Returns:
- A
Methodif found, else null.
-
getMethod
@Nullable public static <C> @Nullable java.lang.reflect.Method getMethod(C classInstance, java.lang.String methodName, java.lang.Class<?>... parameterTypes)Try to get aMethodfrom a given class.- Type Parameters:
C- The class type.- Parameters:
classInstance- Instance of the class to search the method on.methodName- Name of the method to get.parameterTypes- Parameters present for that method.- Returns:
- A
Methodif found, else null.
-
invokeMethod
@Nullable public static <C,R> R invokeMethod(C classInstance, java.lang.reflect.Method method, java.lang.Object... parameters)Calls aMethod.- Type Parameters:
C- The class type.R- The return type.- Parameters:
classInstance- Instance of the class responsible for the method.method- The method to call.parameters- Parameters needed when calling the method.- Returns:
- Return value of the method call if any, else null.
-
getField
@Nullable public static <C> @Nullable java.lang.reflect.Field getField(java.lang.Class<C> clazz, java.lang.String fieldName)Try to get aFieldfrom a given class.- Type Parameters:
C- The class type.- Parameters:
clazz- The class to search the field on.fieldName- Name of the field to get.- Returns:
- A
Fieldif found, else null.
-
getField
@Nullable public static <C> @Nullable java.lang.reflect.Field getField(C classInstance, java.lang.String fieldName)Try to get aFieldfrom a given class.- Type Parameters:
C- The class type.- Parameters:
classInstance- Instance of the class to search the field on.fieldName- Name of the field to get.- Returns:
- A
Fieldif found, else null.
-
getFieldValue
@Nullable public static <C,V> V getFieldValue(C classInstance, java.lang.reflect.Field field)Gets the value of anFieldfrom an instance of the class responsible.- Type Parameters:
C- The class type.V- The field value type.- Parameters:
classInstance- Instance of the class to get the field value from.field- The field to get value from.- Returns:
- The field value if any, else null.
-
-