public class ObfuscationReflectionHelper
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
ObfuscationReflectionHelper.UnableToAccessFieldException |
static class |
ObfuscationReflectionHelper.UnableToFindFieldException |
static class |
ObfuscationReflectionHelper.UnableToFindMethodException |
static class |
ObfuscationReflectionHelper.UnknownConstructorException |
Modifier and Type | Field and Description |
---|---|
private static org.apache.logging.log4j.Logger |
LOGGER |
private static org.apache.logging.log4j.Marker |
REFLECTION |
Constructor and Description |
---|
ObfuscationReflectionHelper() |
Modifier and Type | Method and Description |
---|---|
static <T> java.lang.reflect.Constructor<T> |
findConstructor(java.lang.Class<T> clazz,
java.lang.Class<?>... parameterTypes)
Finds a constructor with the specified parameter types in the given class and makes it accessible.
|
static <T> java.lang.reflect.Field |
findField(java.lang.Class<? super T> clazz,
java.lang.String fieldName)
Finds a field with the specified name in the given class and makes it accessible.
|
static java.lang.reflect.Method |
findMethod(java.lang.Class<?> clazz,
java.lang.String methodName,
java.lang.Class<?>... parameterTypes)
Finds a method with the specified name and parameters in the given class and makes it accessible.
|
static <T,E> T |
getPrivateValue(java.lang.Class<? super E> classToAccess,
E instance,
java.lang.String fieldName)
Gets the value a field with the specified name in the given class.
|
static java.lang.String |
remapName(cpw.mods.modlauncher.api.INameMappingService.Domain domain,
java.lang.String name)
Remaps a name using the SRG naming function
|
static <T,E> void |
setPrivateValue(java.lang.Class<? super T> classToAccess,
T instance,
E value,
java.lang.String fieldName)
Sets the value a field with the specified name in the given class.
|
private static final org.apache.logging.log4j.Logger LOGGER
private static final org.apache.logging.log4j.Marker REFLECTION
@Nonnull public static java.lang.String remapName(cpw.mods.modlauncher.api.INameMappingService.Domain domain, java.lang.String name)
domain
- The INameMappingService.Domain
to use to remap the name.name
- The name to try and remap.@Nullable public static <T,E> T getPrivateValue(java.lang.Class<? super E> classToAccess, E instance, java.lang.String fieldName)
findField(Class, String)
if you are getting the value more than once.
Throws an exception if the field is not found or the value of the field cannot be gotten.
T
- The type of the value.E
- The type of the classToAccess
.classToAccess
- The class to find the field on.instance
- The instance of the classToAccess
.fieldName
- The SRG (unmapped) name of the field to find (e.g. "field_181725_a").classToAccess
.ObfuscationReflectionHelper.UnableToAccessFieldException
- If there was a problem getting the field.ObfuscationReflectionHelper.UnableToAccessFieldException
- If there was a problem getting the value.public static <T,E> void setPrivateValue(@Nonnull java.lang.Class<? super T> classToAccess, @Nonnull T instance, @Nullable E value, @Nonnull java.lang.String fieldName)
findField(Class, String)
if you are setting the value more than once.
Throws an exception if the field is not found or the value of the field cannot be set.
T
- The type of the value.E
- The type of the classToAccess
.classToAccess
- The class to find the field on.instance
- The instance of the classToAccess
.value
- The new value for the fieldfieldName
- The name of the field in the classToAccess
.ObfuscationReflectionHelper.UnableToFindFieldException
- If there was a problem getting the field.ObfuscationReflectionHelper.UnableToAccessFieldException
- If there was a problem setting the value of the field.@Nonnull public static java.lang.reflect.Method findMethod(@Nonnull java.lang.Class<?> clazz, @Nonnull java.lang.String methodName, @Nonnull java.lang.Class<?>... parameterTypes)
Throws an exception if the method is not found.
clazz
- The class to find the method on.methodName
- The SRG (unmapped) name of the method to find (e.g. "func_12820_D").parameterTypes
- The parameter types of the method to find.java.lang.NullPointerException
- If clazz
is null.java.lang.NullPointerException
- If methodName
is null.java.lang.IllegalArgumentException
- If methodName
is empty.java.lang.NullPointerException
- If parameterTypes
is null.ObfuscationReflectionHelper.UnableToFindMethodException
- If the method could not be found.@Nonnull public static <T> java.lang.reflect.Constructor<T> findConstructor(@Nonnull java.lang.Class<T> clazz, @Nonnull java.lang.Class<?>... parameterTypes)
Throws an exception if the constructor is not found.
T
- The type.clazz
- The class to find the constructor in.parameterTypes
- The parameter types of the constructor.java.lang.NullPointerException
- If clazz
is null.java.lang.NullPointerException
- If parameterTypes
is null.ObfuscationReflectionHelper.UnknownConstructorException
- If the constructor could not be found.@Nonnull public static <T> java.lang.reflect.Field findField(@Nonnull java.lang.Class<? super T> clazz, @Nonnull java.lang.String fieldName)
Throws an exception if the field is not found.
T
- The type.clazz
- The class to find the field on.fieldName
- The SRG (unmapped) name of the field to find (e.g. "field_181725_a").java.lang.NullPointerException
- If clazz
is null.java.lang.NullPointerException
- If fieldName
is null.java.lang.IllegalArgumentException
- If fieldName
is empty.ObfuscationReflectionHelper.UnableToFindFieldException
- If the field could not be found.