Class EasyLookup
java.lang.Object
com.saicone.rtag.util.EasyLookup
Deprecated.
Class to handle reflection lookups in a easy way.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceDeprecated.Boolean valued function to compare a method with return and parameter types. -
Method Summary
Modifier and TypeMethodDescriptionstatic Class<?> Deprecated.Same hasClass.forName(String)but save the class into memory.static Class<?> Deprecated.Same hasClass.forName(String)but save the class into memory.static Class<?> addClassId(String id, Class<?> clazz) Deprecated.Save class into memory with provided ID to get fromclassById(String).static Class<?> addClassId(String id, String name, String... aliases) Deprecated.Same hasClass.forName(String)but save the class into memory with provided ID to get fromclassById(String).static Class<?> addNMSClass(String name) Deprecated.Save the typically net.minecraft.server class into memory.
For +1.17 servers compatibility the name must be the full class path after "net.minecraft."static Class<?> addNMSClass(String name, String... aliases) Deprecated.Save the typically net.minecraft.server class into memory.
For +1.17 servers compatibility the name must be the full class path after "net.minecraft."static Class<?> addNMSClassId(String id, String name, String... aliases) Deprecated.Save the typically net.minecraft.server class into memory with specified ID.
For +1.17 servers compatibility the name must be the full class path after "net.minecraft."static Class<?> addOBCClass(String name) Deprecated.Save the typically org.bukkit.craftbukkit class into memory.
Name must be the full path after craftbukkit package.static Class<?> addOBCClass(String name, String... aliases) Deprecated.Save the typically org.bukkit.craftbukkit class into memory.
Name must be the full path after craftbukkit package.static Class<?> addOBCClassId(String id, String name, String... aliases) Deprecated.Save the typically org.bukkit.craftbukkit class into memory with specified ID.
Name must be the full path after craftbukkit package.static Class<?> Deprecated.Get previously saved class by it ID.static Class<?>[]Deprecated.Same hasclassOf(Object)but for multiple objects.static Class<?> Deprecated.Get class represented by Object.
If object is instance of Class will return itself, otherwise returnclassById(String).static MethodHandleconstructor(Object clazz, Object... parameterTypes) Deprecated.Easy way to invokeMethodHandles.Lookup.findConstructor(Class, MethodType)without creating a MethodType, it also provide void class at first argument has default.
Required classes can be Strings to get byclassById(String).
See alsounreflectConstructor(Object, Object...)for private constructors.static FieldDeprecated.Get accessible field from provided class.
Required classes can be Strings to get byclassById(String).static Constructor<?> findConstructor(Class<?> from, Class<?>... parameterTypes) Deprecated.Find constructor inside class using recursive searching and invokeMethodHandles.Lookup.unreflectConstructor(Constructor).
Required classes can be Strings to get byclassById(String).static FieldDeprecated.Find field inside class using recursive searching and return itstatic MethodfindMethod(Class<?> from, boolean isStatic, String name, Class<?> returnType, Class<?>... parameterTypes) Deprecated.Find method inside class using recursirve searching and invokeMethodHandles.Lookup.unreflect(Method).
Required classes can be Strings to get byclassById(String).static MethodHandleDeprecated.Easy way to invokeMethodHandles.Lookup.findGetter(Class, String, Class)without creating a MethodType, this method require to specify the return type class ofFieldand its only compatible with public instance fields, seestaticGetter(Object, String, Object)for static getter.
Required classes can be Strings to get byclassById(String).
See alsounreflectGetter(Object, String)for private getters.static booleanisAssignableFrom(Class<?>[] baseTypes, Class<?>[] checkedTypes) Deprecated.Same hasClass.isAssignableFrom(Class)but using class arrays.static MethodHandleDeprecated.Easy way to invokeMethodHandles.Lookup.findVirtual(Class, String, MethodType)without creating a MethodType, this method require to specify the return type class of reflectedMethodand its only compatible with instance public methods, seestaticMethod(Object, String, Object, Object...)for static public methods.
Required classes can be Strings to get byclassById(String).
See alsounreflectMethod(Object, String, Object...)for private methods.static MethodHandles.LookupprivateLookup(Class<?> clazz) Deprecated.Same hasMethodHandles.privateLookupIn(Class, MethodHandles.Lookup)but save the result into memory.static MethodHandleDeprecated.Easy way to invokeMethodHandles.Lookup.findSetter(Class, String, Class)without creating a MethodType, this method require to specify the return type class ofFieldand its only compatible with public instance fields, seestaticSetter(Object, String, Object)for static setter.
Required classes can be Strings to get byclassById(String).
See alsounreflectSetter(Object, String)for private setters.static MethodHandlestaticGetter(Object clazz, String name, Object returnType) Deprecated.Easy way to invokeMethodHandles.Lookup.findStaticGetter(Class, String, Class)without creating a MethodType, this method require to specify the return type class ofFieldand its only compatible with instance fields
Required classes can be Strings to get byclassById(String).
See alsounreflectGetter(Object, String)for private getters.static MethodHandlestaticMethod(Object clazz, String name, Object returnType, Object... parameterTypes) Deprecated.Easy way to invokeMethodHandles.Lookup.findStatic(Class, String, MethodType)without creating a MethodType, this method require to specify the return type class of reflectedMethodand only compatible with static methods.
Required classes can be Strings to get byclassById(String).
See alsounreflectMethod(Object, String, Object...)for private methods.static MethodHandlestaticSetter(Object clazz, String name, Object returnType) Deprecated.Easy way to invokeMethodHandles.Lookup.findStaticSetter(Class, String, Class)without creating a MethodType, this method require to specify the return type class ofFieldand its only compatible with instance fields
Required classes can be Strings to get byclassById(String).
See alsounreflectSetter(Object, String)for private setters.static booleanDeprecated.Test the availability of provided class name usingClass.forName(String).static MethodHandleunreflectConstructor(Object clazz, Object... parameterTypes) Deprecated.Easy way to invokeMethodHandles.Lookup.unreflectConstructor(Constructor), this method creates an accessibleConstructorand unreflect it, useful for private constructors.
Required classes can be Strings to get byclassById(String).static MethodHandleunreflectConstructor(Constructor<?> constructor) Deprecated.Same hasMethodHandles.Lookup.unreflectConstructor(Constructor), but this method makes the constructor accessible if unreflection fails.static MethodHandleunreflectGetter(Object clazz, String name) Deprecated.Easy way to invokeMethodHandles.Lookup.unreflectGetter(Field), this method creates an accessibleFieldand unreflect it, can be static or instance field.
Required classes can be Strings to get byclassById(String).static MethodHandleunreflectGetter(Field field) Deprecated.Same hasMethodHandles.Lookup.unreflectGetter(Field), but this method makes the field accessible if unreflection fails.
Required classes can be Strings to get byclassById(String).static MethodHandleunreflectMethod(Object clazz, String name, Object... parameterTypes) Deprecated.Easy way to invokeMethodHandles.Lookup.unreflect(Method), this method creates and accessibleMethodand unreflect it, can be static or instance method.
Required classes can be Strings to get byclassById(String).static MethodHandleunreflectMethod(Method method) Deprecated.Easy way to invokeMethodHandles.Lookup.unreflect(Method), but this method makes the method accessible if unreflection fails.static MethodHandleunreflectSetter(Object clazz, String name) Deprecated.Easy way to invokeMethodHandles.Lookup.unreflectSetter(Field), this method creates a accessibleFieldand unreflect it, can be static or instance field.
Required classes can be Strings to get byclassById(String).static MethodHandleunreflectSetter(Field field) Deprecated.Same hasMethodHandles.Lookup.unreflectSetter(Field), but this method makes the field accessible if unreflection fails.
Required classes can be Strings to get byclassById(String).
-
Method Details
-
testClass
Deprecated.Test the availability of provided class name usingClass.forName(String).- Parameters:
name- Class name.- Returns:
- true if the provided class exists.
-
classById
-
classOf
Deprecated.Get class represented by Object.
If object is instance of Class will return itself, otherwise returnclassById(String).- Parameters:
object- Class or String.- Returns:
- A class represented by provided object or null.
-
classesOf
Deprecated.Same hasclassOf(Object)but for multiple objects.- Parameters:
classes- Classes objects.- Returns:
- A array of classes represented by objects.
-
addClass
Deprecated.Same hasClass.forName(String)but save the class into memory.- Parameters:
name- Class name.- Returns:
- Added class.
- Throws:
ClassNotFoundException- if the class cannot be located.
-
addClass
Deprecated.Same hasClass.forName(String)but save the class into memory.- Parameters:
name- Class name.aliases- Alternative class names.- Returns:
- Added class.
- Throws:
ClassNotFoundException- if the class cannot be located.
-
addClassId
public static Class<?> addClassId(String id, String name, String... aliases) throws ClassNotFoundException Deprecated.Same hasClass.forName(String)but save the class into memory with provided ID to get fromclassById(String).- Parameters:
id- Class ID.name- Class name.aliases- Alternative class names.- Returns:
- Added class.
- Throws:
ClassNotFoundException- if the class cannot be located.
-
addClassId
Deprecated.Save class into memory with provided ID to get fromclassById(String).- Parameters:
id- Class ID.clazz- Class object.- Returns:
- Added class.
-
addNMSClass
Deprecated.Save the typically net.minecraft.server class into memory.
For +1.17 servers compatibility the name must be the full class path after "net.minecraft."- Parameters:
name- Class name.- Returns:
- Added class.
- Throws:
ClassNotFoundException- if the class cannot be located.
-
addNMSClass
Deprecated.Save the typically net.minecraft.server class into memory.
For +1.17 servers compatibility the name must be the full class path after "net.minecraft."- Parameters:
name- Class name.aliases- Alternative class names.- Returns:
- Added class.
- Throws:
ClassNotFoundException- if the class cannot be located.
-
addNMSClassId
public static Class<?> addNMSClassId(String id, String name, String... aliases) throws ClassNotFoundException Deprecated.Save the typically net.minecraft.server class into memory with specified ID.
For +1.17 servers compatibility the name must be the full class path after "net.minecraft."- Parameters:
id- Class ID.name- Class name.aliases- Alternative class names.- Returns:
- Added class.
- Throws:
ClassNotFoundException- if the class cannot be located.
-
addOBCClass
Deprecated.Save the typically org.bukkit.craftbukkit class into memory.
Name must be the full path after craftbukkit package.- Parameters:
name- Class name.- Returns:
- Added class.
- Throws:
ClassNotFoundException- if the class cannot be located.
-
addOBCClass
Deprecated.Save the typically org.bukkit.craftbukkit class into memory.
Name must be the full path after craftbukkit package.- Parameters:
name- Class name.aliases- Alternative class names.- Returns:
- Added class.
- Throws:
ClassNotFoundException- if the class cannot be located.
-
addOBCClassId
public static Class<?> addOBCClassId(String id, String name, String... aliases) throws ClassNotFoundException Deprecated.Save the typically org.bukkit.craftbukkit class into memory with specified ID.
Name must be the full path after craftbukkit package.- Parameters:
id- Class ID.name- Class name.aliases- Alternative class names.- Returns:
- Added class.
- Throws:
ClassNotFoundException- if the class cannot be located.
-
privateLookup
Deprecated.Same hasMethodHandles.privateLookupIn(Class, MethodHandles.Lookup)but save the result into memory.- Parameters:
clazz- Target class.- Returns:
- Private lookup or null.
-
constructor
public static MethodHandle constructor(Object clazz, Object... parameterTypes) throws NoSuchMethodException, IllegalAccessException Deprecated.Easy way to invokeMethodHandles.Lookup.findConstructor(Class, MethodType)without creating a MethodType, it also provide void class at first argument has default.
Required classes can be Strings to get byclassById(String).
See alsounreflectConstructor(Object, Object...)for private constructors.- Parameters:
clazz- Class to find constructor.parameterTypes- Required classes in constructor.- Returns:
- A MethodHandle representing class constructor.
- Throws:
NoSuchMethodException- if the constructor does not exist.IllegalAccessException- if access checking fails or if the method's variable arity modifier bit is set and asVarargsCollector fails.
-
unreflectConstructor
public static MethodHandle unreflectConstructor(Constructor<?> constructor) throws IllegalAccessException Deprecated.Same hasMethodHandles.Lookup.unreflectConstructor(Constructor), but this method makes the constructor accessible if unreflection fails.- Parameters:
constructor- The reflected constructor.- Returns:
- A MethodHandle representing constructor.
- Throws:
IllegalAccessException- if access checking fails or if the method's variable arity modifier bit is set and asVarargsCollector fails.
-
unreflectConstructor
public static MethodHandle unreflectConstructor(Object clazz, Object... parameterTypes) throws NoSuchMethodException, IllegalAccessException Deprecated.Easy way to invokeMethodHandles.Lookup.unreflectConstructor(Constructor), this method creates an accessibleConstructorand unreflect it, useful for private constructors.
Required classes can be Strings to get byclassById(String).- Parameters:
clazz- Class to find constructor.parameterTypes- Required classes in constructor.- Returns:
- A MethodHandle representing class constructor.
- Throws:
NoSuchMethodException- if a matching method is not found.IllegalAccessException- if access checking fails or if the method's variable arity modifier bit is set and asVarargsCollector fails.
-
findConstructor
public static Constructor<?> findConstructor(Class<?> from, Class<?>... parameterTypes) throws NoSuchMethodException, IllegalAccessException Deprecated.Find constructor inside class using recursive searching and invokeMethodHandles.Lookup.unreflectConstructor(Constructor).
Required classes can be Strings to get byclassById(String).- Parameters:
from- Class to find constructor.parameterTypes- Required classes in constructor.- Returns:
- A constructor for provided class.
- Throws:
NoSuchMethodException- if a matching method is not found.IllegalAccessException- if access checking fails or if the method's variable arity modifier bit is set and asVarargsCollector fails.
-
method
public static MethodHandle method(Object clazz, String name, Object returnType, Object... parameterTypes) throws NoSuchMethodException, IllegalAccessException Deprecated.Easy way to invokeMethodHandles.Lookup.findVirtual(Class, String, MethodType)without creating a MethodType, this method require to specify the return type class of reflectedMethodand its only compatible with instance public methods, seestaticMethod(Object, String, Object, Object...)for static public methods.
Required classes can be Strings to get byclassById(String).
See alsounreflectMethod(Object, String, Object...)for private methods.- Parameters:
clazz- Class to find public method.name- Method name.returnType- Return type class for method.parameterTypes- Required classes in method.- Returns:
- A MethodHandle representing a instance method for provided class.
- Throws:
NoSuchMethodException- if the method does not exist.IllegalAccessException- if access checking fails, or if the method is static, or if the method's variable arity modifier bit is set and asVarargsCollector fails.
-
unreflectMethod
Deprecated.Easy way to invokeMethodHandles.Lookup.unreflect(Method), but this method makes the method accessible if unreflection fails.- Parameters:
method- Method to unreflect.- Returns:
- A MethodHandle representing a method.
- Throws:
IllegalAccessException- if access checking fails or if the method's variable arity modifier bit is set and asVarargsCollector fails.
-
unreflectMethod
public static MethodHandle unreflectMethod(Object clazz, String name, Object... parameterTypes) throws NoSuchMethodException, IllegalAccessException Deprecated.Easy way to invokeMethodHandles.Lookup.unreflect(Method), this method creates and accessibleMethodand unreflect it, can be static or instance method.
Required classes can be Strings to get byclassById(String).- Parameters:
clazz- Class to find method.name- Method name.parameterTypes- Required classes in method.- Returns:
- A MethodHandle representing a method for provided class.
- Throws:
NoSuchMethodException- if a matching method is not found or if the name is "<init>"or "<clinit>".IllegalAccessException- if access checking fails or if the method's variable arity modifier bit is set and asVarargsCollector fails.
-
staticMethod
public static MethodHandle staticMethod(Object clazz, String name, Object returnType, Object... parameterTypes) throws NoSuchMethodException, IllegalAccessException Deprecated.Easy way to invokeMethodHandles.Lookup.findStatic(Class, String, MethodType)without creating a MethodType, this method require to specify the return type class of reflectedMethodand only compatible with static methods.
Required classes can be Strings to get byclassById(String).
See alsounreflectMethod(Object, String, Object...)for private methods.- Parameters:
clazz- Class to find method.name- Method name.returnType- Return type class for method.parameterTypes- Required classes in method.- Returns:
- A MethodHandle representing a static method for provided class.
- Throws:
NoSuchMethodException- if the method does not exist.IllegalAccessException- if access checking fails, or if the method is not static, or if the method's variable arity modifier bit is set and asVarargsCollector fails.
-
findMethod
public static Method findMethod(Class<?> from, boolean isStatic, String name, Class<?> returnType, Class<?>... parameterTypes) throws NoSuchMethodException, IllegalAccessException Deprecated.Find method inside class using recursirve searching and invokeMethodHandles.Lookup.unreflect(Method).
Required classes can be Strings to get byclassById(String).- Parameters:
from- Class to find method.isStatic- True if method is static.name- Method name.returnType- Return type class for method.parameterTypes- Required classes in method.- Returns:
- A method from provided class.
- Throws:
NoSuchMethodException- if the method does not exist.IllegalAccessException- if access checking fails, or if the method is not static, or if the method's variable arity modifier bit is set and asVarargsCollector fails.
-
isAssignableFrom
Deprecated.Same hasClass.isAssignableFrom(Class)but using class arrays.- Parameters:
baseTypes- The Class array that check.checkedTypes- The Class array to be checked.- Returns:
- true if checkedTypes can be assigned to baseTypes in respecting order.
-
getter
public static MethodHandle getter(Object clazz, String name, Object returnType) throws NoSuchFieldException, IllegalAccessException Deprecated.Easy way to invokeMethodHandles.Lookup.findGetter(Class, String, Class)without creating a MethodType, this method require to specify the return type class ofFieldand its only compatible with public instance fields, seestaticGetter(Object, String, Object)for static getter.
Required classes can be Strings to get byclassById(String).
See alsounreflectGetter(Object, String)for private getters.- Parameters:
clazz- Class to find getter.name- Field name.returnType- Return type class for provided field name.- Returns:
- A MethodHandle representing a field getter for provided class.
- Throws:
NoSuchFieldException- if the field does not exist.IllegalAccessException- if access checking fails, or if the field is static.
-
unreflectGetter
Deprecated.Same hasMethodHandles.Lookup.unreflectGetter(Field), but this method makes the field accessible if unreflection fails.
Required classes can be Strings to get byclassById(String).- Parameters:
field- Field to unreflect.- Returns:
- A MethodHandle representing a field getter for provided class.
- Throws:
IllegalAccessException- if access checking fails.
-
unreflectGetter
public static MethodHandle unreflectGetter(Object clazz, String name) throws NoSuchFieldException, IllegalAccessException Deprecated.Easy way to invokeMethodHandles.Lookup.unreflectGetter(Field), this method creates an accessibleFieldand unreflect it, can be static or instance field.
Required classes can be Strings to get byclassById(String).- Parameters:
clazz- Class to find getter.name- Field name.- Returns:
- A MethodHandle representing a field getter for provided class.
- Throws:
NoSuchFieldException- if a field with the specified name is not found.IllegalAccessException- if access checking fails.
-
staticGetter
public static MethodHandle staticGetter(Object clazz, String name, Object returnType) throws NoSuchFieldException, IllegalAccessException Deprecated.Easy way to invokeMethodHandles.Lookup.findStaticGetter(Class, String, Class)without creating a MethodType, this method require to specify the return type class ofFieldand its only compatible with instance fields
Required classes can be Strings to get byclassById(String).
See alsounreflectGetter(Object, String)for private getters.- Parameters:
clazz- Class to find getter.name- Field name.returnType- Return type class for provided field name.- Returns:
- A MethodHandle representing a field getter for provided class.
- Throws:
NoSuchFieldException- if the field does not exist.IllegalAccessException- if access checking fails, or if the field is not static.
-
setter
public static MethodHandle setter(Object clazz, String name, Object returnType) throws NoSuchFieldException, IllegalAccessException Deprecated.Easy way to invokeMethodHandles.Lookup.findSetter(Class, String, Class)without creating a MethodType, this method require to specify the return type class ofFieldand its only compatible with public instance fields, seestaticSetter(Object, String, Object)for static setter.
Required classes can be Strings to get byclassById(String).
See alsounreflectSetter(Object, String)for private setters.- Parameters:
clazz- Class to find setter.name- Field name.returnType- Return type class for provided field name.- Returns:
- A MethodHandle representing a field setter for provided class.
- Throws:
NoSuchFieldException- if the field does not exist.IllegalAccessException- if access checking fails, or if the field is static.
-
unreflectSetter
Deprecated.Same hasMethodHandles.Lookup.unreflectSetter(Field), but this method makes the field accessible if unreflection fails.
Required classes can be Strings to get byclassById(String).- Parameters:
field- Field to unreflect.- Returns:
- A MethodHandle representing a field setter for provided class.
- Throws:
IllegalAccessException- if access checking fails.
-
unreflectSetter
public static MethodHandle unreflectSetter(Object clazz, String name) throws NoSuchFieldException, IllegalAccessException Deprecated.Easy way to invokeMethodHandles.Lookup.unreflectSetter(Field), this method creates a accessibleFieldand unreflect it, can be static or instance field.
Required classes can be Strings to get byclassById(String).- Parameters:
clazz- Class to find setter.name- Field name.- Returns:
- A MethodHandle representing a field setter for provided class.
- Throws:
NoSuchFieldException- if a field with the specified name is not found.IllegalAccessException- if access checking fails.
-
staticSetter
public static MethodHandle staticSetter(Object clazz, String name, Object returnType) throws NoSuchFieldException, IllegalAccessException Deprecated.Easy way to invokeMethodHandles.Lookup.findStaticSetter(Class, String, Class)without creating a MethodType, this method require to specify the return type class ofFieldand its only compatible with instance fields
Required classes can be Strings to get byclassById(String).
See alsounreflectSetter(Object, String)for private setters.- Parameters:
clazz- Class to find setter.name- Field name.returnType- Return type class for provided field name.- Returns:
- A MethodHandle representing a field setter for provided class.
- Throws:
NoSuchFieldException- if the field does not exist.IllegalAccessException- if access checking fails, or if the field is not static.
-
findField
public static Field findField(Class<?> from, boolean isStatic, String name, Class<?> type) throws NoSuchFieldException, IllegalAccessException Deprecated.Find field inside class using recursive searching and return it- Parameters:
from- Class to find the field.isStatic- True if field is static.name- Field name.type- Return type class for provided field name.- Returns:
- A field from provided class.
- Throws:
NoSuchFieldException- if the field does not exist.IllegalAccessException- if access checking fails, or if the field is not static.
-
field
Deprecated.Get accessible field from provided class.
Required classes can be Strings to get byclassById(String).- Parameters:
clazz- Class to find setter.field- Field name.- Returns:
- A field from provided class with access permission.
- Throws:
NoSuchFieldException- if the field does not exist.
-