Class ReflectHelper
java.lang.Object
org.mvplugins.multiverse.core.utils.ReflectHelper
Utility class used to help in doing various reflection actions.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic @Nullable Class<?> Try to get theClassbased on its classpath.static <C> @Nullable FieldTry to get aFieldfrom a given class.static <C> @Nullable FieldTry to get aFieldfrom a given class.static <C,V> V getFieldValue(C classInstance, @Nullable String fieldName, @NotNull Class<V> fieldType) Gets the value of a field name from an instance of the class responsible.static <C,V> V getFieldValue(C classInstance, @Nullable Field field, @NotNull Class<V> fieldType) Gets the value of aFieldfrom an instance of the class responsible.static <C> @Nullable MethodTry to get aMethodfrom a given class.static <C> @Nullable MethodTry to get aMethodfrom a given class.static booleanCheck if theClassfor a give classpath is present/valid.static <C,R> R invokeMethod(C classInstance, Method method, Object... parameters) Calls aMethod.
-
Constructor Details
-
ReflectHelper
public ReflectHelper()
-
-
Method Details
-
getClass
Try to get theClassbased on its classpath.- Parameters:
classPath- The target classpath.- Returns:
- A
Classif found, else null.
-
hasClass
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 Method getMethod(Class<C> clazz, String methodName, 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 Method getMethod(C classInstance, String methodName, 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
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
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
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, @Nullable @Nullable Field field, @NotNull @NotNull Class<V> fieldType) Gets the value of aFieldfrom 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.fieldType- Type of the field.- Returns:
- The field value if any, else null.
-
getFieldValue
@Nullable public static <C,V> V getFieldValue(C classInstance, @Nullable @Nullable String fieldName, @NotNull @NotNull Class<V> fieldType) Gets the value of a field name from 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.fieldName- Name of the field to get value from.fieldType- Type of the field.- Returns:
- The field value if any, else null.
-