Class ReflectionUtility


  • public class ReflectionUtility
    extends java.lang.Object
    Utility class for managing reflected objects
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static @Nullable java.lang.Object createArray​(@Nullable java.lang.Class<?> clazz, @org.jetbrains.annotations.Range(from=0L, to=2147483647L) int length)
      Returns a new array of the specified class with the specified length
      static @Nullable java.lang.Class<?> getClass​(int major, int minor, int patch, @NotNull java.lang.Class<?> reflectionClass)
      Returns a Class from a reflection class if AnnoyingPlugin.MINECRAFT_VERSION is greater than or equal to the minimum version
      static @Nullable java.lang.Class<?> getClass​(int major, int minor, int patch, @NotNull java.lang.String className)
      Returns a Class if AnnoyingPlugin.MINECRAFT_VERSION is greater than or equal to the minimum version
      static @Nullable java.lang.Class<?> getClassArray​(int major, int minor, int patch, @NotNull java.lang.Class<?> reflectionClass)
      Returns an array Class from a reflection class if AnnoyingPlugin.MINECRAFT_VERSION is greater than or equal to the minimum version
      static @Nullable java.lang.Class<?> getClassArray​(int major, int minor, int patch, @NotNull java.lang.String className)
      Returns an array Class if AnnoyingPlugin.MINECRAFT_VERSION is greater than or equal to the minimum version
      static <T> @Nullable java.lang.reflect.Constructor<T> getConstructor​(int major, int minor, int patch, @Nullable java.lang.Class<T> clazz, @Nullable java.lang.Class<?>... parameterTypes)
      Returns a Constructor if AnnoyingPlugin.MINECRAFT_VERSION is greater than or equal to the minimum version, the class is not null, and none of the parameter types are null
      static @Nullable java.lang.reflect.Field getDeclaredField​(int major, int minor, int patch, @Nullable java.lang.Class<?> clazz, @NotNull java.lang.String fieldName)
      Returns a declared Field if AnnoyingPlugin.MINECRAFT_VERSION is greater than or equal to the minimum version
      static @Nullable java.lang.Class<? extends java.lang.Enum> getEnum​(int major, int minor, int patch, @NotNull java.lang.Class<?> reflectionClass)
      Returns an Enum Class from a reflection class if AnnoyingPlugin.MINECRAFT_VERSION is greater than or equal to the minimum version
      static @Nullable java.lang.Class<? extends java.lang.Enum> getEnum​(int major, int minor, int patch, @NotNull java.lang.String enumClassName)
      Returns an Enum Class if AnnoyingPlugin.MINECRAFT_VERSION is greater than or equal to the minimum version
      static <T extends java.lang.Enum>
      T
      getEnumValue​(int major, int minor, int patch, @Nullable java.lang.Class<T> enumClass, @NotNull java.lang.String enumName)
      Returns an Enum value if AnnoyingPlugin.MINECRAFT_VERSION is greater than or equal to the minimum version
      static @Nullable java.lang.reflect.Field getField​(int major, int minor, int patch, @Nullable java.lang.Class<?> clazz, @NotNull java.lang.String fieldName)
      Returns a Field if AnnoyingPlugin.MINECRAFT_VERSION is greater than or equal to the minimum version
      static <T> @Nullable java.lang.reflect.Method getMethod​(int major, int minor, int patch, @Nullable java.lang.Class<T> clazz, @NotNull java.lang.String methodName, @Nullable java.lang.Class<?>... parameterTypes)
      Returns a Method if AnnoyingPlugin.MINECRAFT_VERSION is greater than or equal to the minimum version, the class is not null, and none of the parameter types are null
      static @Nullable java.lang.Object getStaticFieldValue​(int major, int minor, int patch, @Nullable java.lang.Class<?> clazz, @NotNull java.lang.String fieldName)
      Returns the value of a static Field if the result of getField(int, int, int, Class, String) is not null
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getClass

        @Nullable
        public static @Nullable java.lang.Class<?> getClass​(int major,
                                                            int minor,
                                                            int patch,
                                                            @NotNull
                                                            @NotNull java.lang.String className)
        Returns a Class if AnnoyingPlugin.MINECRAFT_VERSION is greater than or equal to the minimum version
        Parameters:
        major - the major version of the minimum version
        minor - the minor version of the minimum version
        patch - the patch version of the minimum version
        className - the class name
        Returns:
        the class if the version is greater than or equal to the minimum version, otherwise null
      • getClass

        @Nullable
        public static @Nullable java.lang.Class<?> getClass​(int major,
                                                            int minor,
                                                            int patch,
                                                            @NotNull
                                                            @NotNull java.lang.Class<?> reflectionClass)
        Returns a Class from a reflection class if AnnoyingPlugin.MINECRAFT_VERSION is greater than or equal to the minimum version
        Parameters:
        major - the major version of the minimum version
        minor - the minor version of the minimum version
        patch - the patch version of the minimum version
        reflectionClass - the reflection class
        Returns:
        the class if the version is greater than or equal to the minimum version, otherwise null
      • getEnum

        @Nullable
        public static @Nullable java.lang.Class<? extends java.lang.Enum> getEnum​(int major,
                                                                                  int minor,
                                                                                  int patch,
                                                                                  @NotNull
                                                                                  @NotNull java.lang.String enumClassName)
        Returns an Enum Class if AnnoyingPlugin.MINECRAFT_VERSION is greater than or equal to the minimum version
        Parameters:
        major - the major version of the minimum version
        minor - the minor version of the minimum version
        patch - the patch version of the minimum version
        enumClassName - the enum class name
        Returns:
        the enum if the version is greater than or equal to the minimum version, otherwise null
      • getEnum

        @Nullable
        public static @Nullable java.lang.Class<? extends java.lang.Enum> getEnum​(int major,
                                                                                  int minor,
                                                                                  int patch,
                                                                                  @NotNull
                                                                                  @NotNull java.lang.Class<?> reflectionClass)
        Returns an Enum Class from a reflection class if AnnoyingPlugin.MINECRAFT_VERSION is greater than or equal to the minimum version
        Parameters:
        major - the major version of the minimum version
        minor - the minor version of the minimum version
        patch - the patch version of the minimum version
        reflectionClass - the reflection class
        Returns:
        the enum if the version is greater than or equal to the minimum version, otherwise null
      • getClassArray

        @Nullable
        public static @Nullable java.lang.Class<?> getClassArray​(int major,
                                                                 int minor,
                                                                 int patch,
                                                                 @NotNull
                                                                 @NotNull java.lang.String className)
        Returns an array Class if AnnoyingPlugin.MINECRAFT_VERSION is greater than or equal to the minimum version
        Parameters:
        major - the major version of the minimum version
        minor - the minor version of the minimum version
        patch - the patch version of the minimum version
        className - the class name
        Returns:
        the array class if the version is greater than or equal to the minimum version, otherwise null
      • getClassArray

        @Nullable
        public static @Nullable java.lang.Class<?> getClassArray​(int major,
                                                                 int minor,
                                                                 int patch,
                                                                 @NotNull
                                                                 @NotNull java.lang.Class<?> reflectionClass)
        Returns an array Class from a reflection class if AnnoyingPlugin.MINECRAFT_VERSION is greater than or equal to the minimum version
        Parameters:
        major - the major version of the minimum version
        minor - the minor version of the minimum version
        patch - the patch version of the minimum version
        reflectionClass - the reflection class
        Returns:
        the array class if the version is greater than or equal to the minimum version, otherwise null
      • getConstructor

        @Nullable
        public static <T> @Nullable java.lang.reflect.Constructor<T> getConstructor​(int major,
                                                                                    int minor,
                                                                                    int patch,
                                                                                    @Nullable
                                                                                    @Nullable java.lang.Class<T> clazz,
                                                                                    @Nullable
                                                                                    @Nullable java.lang.Class<?>... parameterTypes)
        Returns a Constructor if AnnoyingPlugin.MINECRAFT_VERSION is greater than or equal to the minimum version, the class is not null, and none of the parameter types are null
        Type Parameters:
        T - the type of the class
        Parameters:
        major - the major version of the minimum version
        minor - the minor version of the minimum version
        patch - the patch version of the minimum version
        clazz - the class to get the constructor from
        parameterTypes - the parameter types of the constructor
        Returns:
        the constructor if the version is greater than or equal to the minimum version, the class is not null, and none of the parameter types are null, otherwise null
      • getMethod

        @Nullable
        public static <T> @Nullable java.lang.reflect.Method getMethod​(int major,
                                                                       int minor,
                                                                       int patch,
                                                                       @Nullable
                                                                       @Nullable java.lang.Class<T> clazz,
                                                                       @NotNull
                                                                       @NotNull java.lang.String methodName,
                                                                       @Nullable
                                                                       @Nullable java.lang.Class<?>... parameterTypes)
        Returns a Method if AnnoyingPlugin.MINECRAFT_VERSION is greater than or equal to the minimum version, the class is not null, and none of the parameter types are null
        Type Parameters:
        T - the type of the class
        Parameters:
        major - the major version of the minimum version
        minor - the minor version of the minimum version
        patch - the patch version of the minimum version
        clazz - the class to get the method from
        methodName - the name of the method
        parameterTypes - the parameter types of the method
        Returns:
        the method if the version is greater than or equal to the minimum version, the class is not null, and none of the parameter types are null, otherwise null
      • getField

        @Nullable
        public static @Nullable java.lang.reflect.Field getField​(int major,
                                                                 int minor,
                                                                 int patch,
                                                                 @Nullable
                                                                 @Nullable java.lang.Class<?> clazz,
                                                                 @NotNull
                                                                 @NotNull java.lang.String fieldName)
        Returns a Field if AnnoyingPlugin.MINECRAFT_VERSION is greater than or equal to the minimum version
        Parameters:
        major - the major version of the minimum version
        minor - the minor version of the minimum version
        patch - the patch version of the minimum version
        clazz - the class to get the field from
        fieldName - the name of the field
        Returns:
        the field if the version is greater than or equal to the minimum version, otherwise null
        See Also:
        Class.getField(String)
      • getDeclaredField

        @Nullable
        public static @Nullable java.lang.reflect.Field getDeclaredField​(int major,
                                                                         int minor,
                                                                         int patch,
                                                                         @Nullable
                                                                         @Nullable java.lang.Class<?> clazz,
                                                                         @NotNull
                                                                         @NotNull java.lang.String fieldName)
        Returns a declared Field if AnnoyingPlugin.MINECRAFT_VERSION is greater than or equal to the minimum version
        Parameters:
        major - the major version of the minimum version
        minor - the minor version of the minimum version
        patch - the patch version of the minimum version
        clazz - the class to get the field from
        fieldName - the name of the field
        Returns:
        the field if the version is greater than or equal to the minimum version, otherwise null
        See Also:
        Class.getDeclaredField(String)
      • getStaticFieldValue

        @Nullable
        public static @Nullable java.lang.Object getStaticFieldValue​(int major,
                                                                     int minor,
                                                                     int patch,
                                                                     @Nullable
                                                                     @Nullable java.lang.Class<?> clazz,
                                                                     @NotNull
                                                                     @NotNull java.lang.String fieldName)
        Returns the value of a static Field if the result of getField(int, int, int, Class, String) is not null
        Parameters:
        major - the major version of the minimum version
        minor - the minor version of the minimum version
        patch - the patch version of the minimum version
        clazz - the class to get the field from
        fieldName - the name of the field
        Returns:
        the value of the field if the result of getField(int, int, int, Class, String) is not null, otherwise null
      • getEnumValue

        @Nullable
        public static <T extends java.lang.Enum> T getEnumValue​(int major,
                                                                int minor,
                                                                int patch,
                                                                @Nullable
                                                                @Nullable java.lang.Class<T> enumClass,
                                                                @NotNull
                                                                @NotNull java.lang.String enumName)
                                                         throws java.lang.IllegalArgumentException
        Returns an Enum value if AnnoyingPlugin.MINECRAFT_VERSION is greater than or equal to the minimum version
        Type Parameters:
        T - the type of the enum
        Parameters:
        major - the major version of the minimum version
        minor - the minor version of the minimum version
        patch - the patch version of the minimum version
        enumClass - the enum class
        enumName - the name of the enum
        Returns:
        the enum value if the version is greater than or equal to the minimum version, otherwise null
        Throws:
        java.lang.IllegalArgumentException - if no enum constant is found with the specified name
      • createArray

        @Nullable
        @Contract("null, _ -> null")
        public static @Nullable java.lang.Object createArray​(@Nullable
                                                             @Nullable java.lang.Class<?> clazz,
                                                             @org.jetbrains.annotations.Range(from=0L, to=2147483647L) int length)
        Returns a new array of the specified class with the specified length
        Parameters:
        clazz - the class of the array
        length - the length of the array
        Returns:
        the new array or null if the class is null/Void