Class ReflectHelper

java.lang.Object
org.mvplugins.multiverse.core.utils.ReflectHelper

public final class ReflectHelper extends Object
Utility class used to help in doing various reflection actions.
  • Constructor Details

    • ReflectHelper

      public ReflectHelper()
  • Method Details

    • getClass

      @Nullable public static @Nullable Class<?> getClass(String classPath)
      Try to get the Class based on its classpath.
      Parameters:
      classPath - The target classpath.
      Returns:
      A Class if found, else null.
    • hasClass

      public static boolean hasClass(String classPath)
      Check if the Class for 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 a Method from 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 Method if found, else null.
    • getMethod

      @Nullable public static <C> @Nullable Method getMethod(C classInstance, String methodName, Class<?>... parameterTypes)
      Try to get a Method from 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 Method if found, else null.
    • invokeMethod

      @Nullable public static <C, R> R invokeMethod(C classInstance, Method method, Object... parameters)
      Calls a Method.
      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 Field getField(Class<C> clazz, String fieldName)
      Try to get a Field from 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 Field if found, else null.
    • getField

      @Nullable public static <C> @Nullable Field getField(C classInstance, String fieldName)
      Try to get a Field from 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 Field if 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 a Field 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.
      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.