Package xyz.srnyx.annoyingapi.utility
Class ReflectionUtility
- java.lang.Object
-
- xyz.srnyx.annoyingapi.utility.ReflectionUtility
-
public class ReflectionUtility extends java.lang.ObjectUtility class for managing reflected objects
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static @Nullable java.lang.ObjectcreateArray(@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 lengthstatic @Nullable java.lang.Class<?>getClass(int major, int minor, int patch, @NotNull java.lang.Class<?> reflectionClass)Returns aClassfrom a reflection class ifAnnoyingPlugin.MINECRAFT_VERSIONis greater than or equal to the minimum versionstatic @Nullable java.lang.Class<?>getClass(int major, int minor, int patch, @NotNull java.lang.String className)Returns aClassifAnnoyingPlugin.MINECRAFT_VERSIONis greater than or equal to the minimum versionstatic @Nullable java.lang.Class<?>getClassArray(int major, int minor, int patch, @NotNull java.lang.Class<?> reflectionClass)Returns an arrayClassfrom a reflection class ifAnnoyingPlugin.MINECRAFT_VERSIONis greater than or equal to the minimum versionstatic @Nullable java.lang.Class<?>getClassArray(int major, int minor, int patch, @NotNull java.lang.String className)Returns an arrayClassifAnnoyingPlugin.MINECRAFT_VERSIONis greater than or equal to the minimum versionstatic <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 aConstructorifAnnoyingPlugin.MINECRAFT_VERSIONis greater than or equal to the minimum version, the class is not null, and none of the parameter types are nullstatic @Nullable java.lang.reflect.FieldgetDeclaredField(int major, int minor, int patch, @Nullable java.lang.Class<?> clazz, @NotNull java.lang.String fieldName)Returns a declaredFieldifAnnoyingPlugin.MINECRAFT_VERSIONis greater than or equal to the minimum versionstatic @Nullable java.lang.Class<? extends java.lang.Enum>getEnum(int major, int minor, int patch, @NotNull java.lang.Class<?> reflectionClass)Returns anEnumClassfrom a reflection class ifAnnoyingPlugin.MINECRAFT_VERSIONis greater than or equal to the minimum versionstatic @Nullable java.lang.Class<? extends java.lang.Enum>getEnum(int major, int minor, int patch, @NotNull java.lang.String enumClassName)Returns anEnumClassifAnnoyingPlugin.MINECRAFT_VERSIONis greater than or equal to the minimum versionstatic <T extends java.lang.Enum>
TgetEnumValue(int major, int minor, int patch, @Nullable java.lang.Class<T> enumClass, @NotNull java.lang.String enumName)Returns anEnumvalue ifAnnoyingPlugin.MINECRAFT_VERSIONis greater than or equal to the minimum versionstatic @Nullable java.lang.reflect.FieldgetField(int major, int minor, int patch, @Nullable java.lang.Class<?> clazz, @NotNull java.lang.String fieldName)Returns aFieldifAnnoyingPlugin.MINECRAFT_VERSIONis greater than or equal to the minimum versionstatic <T> @Nullable java.lang.reflect.MethodgetMethod(int major, int minor, int patch, @Nullable java.lang.Class<T> clazz, @NotNull java.lang.String methodName, @Nullable java.lang.Class<?>... parameterTypes)Returns aMethodifAnnoyingPlugin.MINECRAFT_VERSIONis greater than or equal to the minimum version, the class is not null, and none of the parameter types are nullstatic @Nullable java.lang.ObjectgetStaticFieldValue(int major, int minor, int patch, @Nullable java.lang.Class<?> clazz, @NotNull java.lang.String fieldName)Returns the value of a staticFieldif the result ofgetField(int, int, int, Class, String)is not null
-
-
-
Method Detail
-
getClass
@Nullable public static @Nullable java.lang.Class<?> getClass(int major, int minor, int patch, @NotNull @NotNull java.lang.String className)Returns aClassifAnnoyingPlugin.MINECRAFT_VERSIONis greater than or equal to the minimum version- Parameters:
major- the major version of the minimum versionminor- the minor version of the minimum versionpatch- the patch version of the minimum versionclassName- 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 aClassfrom a reflection class ifAnnoyingPlugin.MINECRAFT_VERSIONis greater than or equal to the minimum version- Parameters:
major- the major version of the minimum versionminor- the minor version of the minimum versionpatch- the patch version of the minimum versionreflectionClass- 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 anEnumClassifAnnoyingPlugin.MINECRAFT_VERSIONis greater than or equal to the minimum version- Parameters:
major- the major version of the minimum versionminor- the minor version of the minimum versionpatch- the patch version of the minimum versionenumClassName- 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 anEnumClassfrom a reflection class ifAnnoyingPlugin.MINECRAFT_VERSIONis greater than or equal to the minimum version- Parameters:
major- the major version of the minimum versionminor- the minor version of the minimum versionpatch- the patch version of the minimum versionreflectionClass- 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 arrayClassifAnnoyingPlugin.MINECRAFT_VERSIONis greater than or equal to the minimum version- Parameters:
major- the major version of the minimum versionminor- the minor version of the minimum versionpatch- the patch version of the minimum versionclassName- 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 arrayClassfrom a reflection class ifAnnoyingPlugin.MINECRAFT_VERSIONis greater than or equal to the minimum version- Parameters:
major- the major version of the minimum versionminor- the minor version of the minimum versionpatch- the patch version of the minimum versionreflectionClass- 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 aConstructorifAnnoyingPlugin.MINECRAFT_VERSIONis 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 versionminor- the minor version of the minimum versionpatch- the patch version of the minimum versionclazz- the class to get the constructor fromparameterTypes- 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 aMethodifAnnoyingPlugin.MINECRAFT_VERSIONis 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 versionminor- the minor version of the minimum versionpatch- the patch version of the minimum versionclazz- the class to get the method frommethodName- the name of the methodparameterTypes- 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 aFieldifAnnoyingPlugin.MINECRAFT_VERSIONis greater than or equal to the minimum version- Parameters:
major- the major version of the minimum versionminor- the minor version of the minimum versionpatch- the patch version of the minimum versionclazz- the class to get the field fromfieldName- 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 declaredFieldifAnnoyingPlugin.MINECRAFT_VERSIONis greater than or equal to the minimum version- Parameters:
major- the major version of the minimum versionminor- the minor version of the minimum versionpatch- the patch version of the minimum versionclazz- the class to get the field fromfieldName- 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 staticFieldif the result ofgetField(int, int, int, Class, String)is not null- Parameters:
major- the major version of the minimum versionminor- the minor version of the minimum versionpatch- the patch version of the minimum versionclazz- the class to get the field fromfieldName- 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.IllegalArgumentExceptionReturns anEnumvalue ifAnnoyingPlugin.MINECRAFT_VERSIONis greater than or equal to the minimum version- Type Parameters:
T- the type of the enum- Parameters:
major- the major version of the minimum versionminor- the minor version of the minimum versionpatch- the patch version of the minimum versionenumClass- the enum classenumName- 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 arraylength- the length of the array- Returns:
- the new array or null if the class is null/Void
-
-