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<?> Deprecated, for removal: This API element is subject to removal in a future version.static <C> @Nullable FieldDeprecated, for removal: This API element is subject to removal in a future version.UsetryGetField(Class, String)instead, which returns aTrythat can be used to handle the failure case more explicitly.static <C> @Nullable FieldDeprecated, for removal: This API element is subject to removal in a future version.UsetryGetField(Class, String)instead, which returns aTrythat can be used to handle the failure case more explicitly.static <C,V> V getFieldValue(C classInstance, @Nullable String fieldName, @NotNull Class<V> fieldType) Deprecated, for removal: This API element is subject to removal in a future version.UsetryGetField(Class, String)then map totryGetFieldValue(Object, Field, Class)instead, which returns aTrythat can be used to handle the failure case more explicitly.static <C,V> V getFieldValue(C classInstance, @Nullable Field field, @NotNull Class<V> fieldType) Deprecated, for removal: This API element is subject to removal in a future version.UsetryGetFieldValue(Object, Field, Class)instead, which returns aTrythat can be used to handle the failure case more explicitly.static <C> @Nullable MethodDeprecated, for removal: This API element is subject to removal in a future version.UsetryGetMethod(Class, String, Class[])instead, which returns aTrythat can be used to handle the failure case more explicitly.static <C> @Nullable MethodDeprecated, for removal: This API element is subject to removal in a future version.UsetryGetMethod(Class, String, Class[])instead, which returns aTrythat can be used to handle the failure case more explicitly.static booleanCheck if theClassfor a give classpath is present/valid.static booleanCheck if aFieldexists on a given class.static booleanCheck if aMethodexists on a given class.static <C,R> R invokeMethod(C classInstance, Method method, Object... parameters) Deprecated, for removal: This API element is subject to removal in a future version.UsetryInvokeMethod(Object, Method, Object...)instead, which returns aTrythat can be used to handle the failure case more explicitly.static @NotNull io.vavr.control.Try<Class<?>> tryGetClass(@NotNull String classPath) Try to get theClassbased on its classpath.static <C> @NotNull io.vavr.control.Try<Field> tryGetField(@NotNull Class<C> clazz, @NotNull String fieldName) Try to get aFieldfrom a given class.static <C,V> @NotNull io.vavr.control.Try <V> tryGetFieldValue(C classInstance, @NotNull Field field, @NotNull Class<V> fieldType) Try to get the value of aFieldfrom an instance of the class responsible.static <C> @NotNull io.vavr.control.Try<Method> tryGetMethod(@NotNull Class<C> clazz, @NotNull String methodName, Class<?>... parameterTypes) Try to get aMethodfrom a given class.static <V> @NotNull io.vavr.control.Try<V> tryGetStaticFieldValue(@NotNull Field field, @NotNull Class<V> fieldType) Try to get the value of a staticField.static <C,R> @NotNull io.vavr.control.Try <R> tryInvokeMethod(C classInstance, @NotNull Method method, Object... parameters) Try to invoke aMethodon a class instance.static <R> @NotNull io.vavr.control.Try<R> tryInvokeStaticMethod(@NotNull Method method, Object... parameters) Try to invoke a staticMethod.
-
Constructor Details
-
ReflectHelper
public ReflectHelper()
-
-
Method Details
-
tryGetClass
@AvailableSince("5.7") @NotNull public static @NotNull io.vavr.control.Try<Class<?>> tryGetClass(@NotNull @NotNull String classPath) Try to get theClassbased on its classpath.- Parameters:
classPath- The target classpath.- Returns:
- A
Trycontaining theClassif found, else a failure. - Since:
- 5.7
-
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.
-
tryGetMethod
@AvailableSince("5.7") @NotNull public static <C> @NotNull io.vavr.control.Try<Method> tryGetMethod(@NotNull @NotNull Class<C> clazz, @NotNull @NotNull 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
Trycontaining theMethodif found, else a failure. - Since:
- 5.7
-
hasMethod
@AvailableSince("5.7") public static boolean hasMethod(@NotNull @NotNull Class<?> clazz, @NotNull @NotNull String methodName, Class<?>... parameterTypes) Check if aMethodexists on a given class.- Parameters:
clazz- The class to search the method on.methodName- Name of the method to check.parameterTypes- Parameters present for that method.- Returns:
- True if method exists, else false.
- Since:
- 5.7
-
tryInvokeMethod
@AvailableSince("5.7") @NotNull public static <C,R> @NotNull io.vavr.control.Try<R> tryInvokeMethod(@NotNull C classInstance, @NotNull @NotNull Method method, Object... parameters) Try to invoke aMethodon a class instance.- Type Parameters:
C- The class type.R- The return type of the method.- Parameters:
classInstance- Instance of the class responsible for the method.method- The method to invoke.parameters- Parameters needed when invoking the method.- Returns:
- A
Trycontaining the return value of the method if found, else a failure. - Since:
- 5.7
-
tryInvokeStaticMethod
@AvailableSince("5.7") @NotNull public static <R> @NotNull io.vavr.control.Try<R> tryInvokeStaticMethod(@NotNull @NotNull Method method, Object... parameters) Try to invoke a staticMethod.- Type Parameters:
R- The return type of the method.- Parameters:
method- The static method to invoke.parameters- Parameters needed when invoking the method.- Returns:
- A
Trycontaining the return value of the method if found, else a failure. - Since:
- 5.7
-
tryGetField
@AvailableSince("5.7") @NotNull public static <C> @NotNull io.vavr.control.Try<Field> tryGetField(@NotNull @NotNull Class<C> clazz, @NotNull @NotNull 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
Trycontaining theFieldif found, else a failure. - Since:
- 5.7
-
hasField
@AvailableSince("5.7") public static boolean hasField(@NotNull @NotNull Class<?> clazz, @NotNull @NotNull String fieldName) Check if aFieldexists on a given class.- Parameters:
clazz- The class to search the field on.fieldName- Name of the field to check.- Returns:
- True if field exists, else false.
- Since:
- 5.7
-
tryGetFieldValue
@AvailableSince("5.7") @NotNull public static <C,V> @NotNull io.vavr.control.Try<V> tryGetFieldValue(@NotNull C classInstance, @NotNull @NotNull Field field, @NotNull @NotNull Class<V> fieldType) Try to get 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 the value from.fieldType- Type of the field.- Returns:
- A
Trycontaining the field value if found, else a failure. - Since:
- 5.7
-
tryGetStaticFieldValue
@AvailableSince("5.7") @NotNull public static <V> @NotNull io.vavr.control.Try<V> tryGetStaticFieldValue(@NotNull @NotNull Field field, @NotNull @NotNull Class<V> fieldType) Try to get the value of a staticField.- Type Parameters:
V- The field value type.- Parameters:
field- The static field to get the value from.fieldType- Type of the field.- Returns:
- A
Trycontaining the field value if found, else a failure. - Since:
- 5.7
-
getClass
@Deprecated(forRemoval=true, since="5.7") @Nullable public static @Nullable Class<?> getClass(String classPath) Deprecated, for removal: This API element is subject to removal in a future version.UsetryGetClass(String)instead, which returns aTrythat can be used to handle the failure case more explicitly.Try to get theClassbased on its classpath.- Parameters:
classPath- The target classpath.- Returns:
- A
Classif found, else null.
-
getMethod
@Deprecated(forRemoval=true, since="5.7") @Nullable public static <C> @Nullable Method getMethod(Class<C> clazz, String methodName, Class<?>... parameterTypes) Deprecated, for removal: This API element is subject to removal in a future version.UsetryGetMethod(Class, String, Class[])instead, which returns aTrythat can be used to handle the failure case more explicitly.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
@Deprecated(forRemoval=true, since="5.7") @Nullable public static <C> @Nullable Method getMethod(C classInstance, String methodName, Class<?>... parameterTypes) Deprecated, for removal: This API element is subject to removal in a future version.UsetryGetMethod(Class, String, Class[])instead, which returns aTrythat can be used to handle the failure case more explicitly.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
@Deprecated(forRemoval=true, since="5.7") @Nullable public static <C,R> R invokeMethod(C classInstance, Method method, Object... parameters) Deprecated, for removal: This API element is subject to removal in a future version.UsetryInvokeMethod(Object, Method, Object...)instead, which returns aTrythat can be used to handle the failure case more explicitly.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
@Deprecated(forRemoval=true, since="5.7") @Nullable public static <C> @Nullable Field getField(Class<C> clazz, String fieldName) Deprecated, for removal: This API element is subject to removal in a future version.UsetryGetField(Class, String)instead, which returns aTrythat can be used to handle the failure case more explicitly.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
@Deprecated(forRemoval=true, since="5.7") @Nullable public static <C> @Nullable Field getField(C classInstance, String fieldName) Deprecated, for removal: This API element is subject to removal in a future version.UsetryGetField(Class, String)instead, which returns aTrythat can be used to handle the failure case more explicitly.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
@Deprecated(forRemoval=true, since="5.7") @Nullable public static <C,V> V getFieldValue(C classInstance, @Nullable @Nullable Field field, @NotNull @NotNull Class<V> fieldType) Deprecated, for removal: This API element is subject to removal in a future version.UsetryGetFieldValue(Object, Field, Class)instead, which returns aTrythat can be used to handle the failure case more explicitly.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
@Deprecated(forRemoval=true, since="5.7") @Nullable public static <C,V> V getFieldValue(C classInstance, @Nullable @Nullable String fieldName, @NotNull @NotNull Class<V> fieldType) Deprecated, for removal: This API element is subject to removal in a future version.UsetryGetField(Class, String)then map totryGetFieldValue(Object, Field, Class)instead, which returns aTrythat can be used to handle the failure case more explicitly.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.
-
tryGetClass(String)instead, which returns aTrythat can be used to handle the failure case more explicitly.