public enum Reflections extends java.lang.Enum<Reflections>
Modifier and Type | Method and Description |
---|---|
static java.lang.Object |
getSimpleClass(java.lang.String[] clazzez,
java.lang.Object constructorParameter)
Receives a list of possible class locations for our target class
and an optional constructor parameter (only single parameter classes
are supported for now) and returns the actual class from one of the places
where it founds it.
|
static java.lang.reflect.Method |
getSimpleMethodFromObjectInstance(java.lang.Object o,
java.lang.reflect.Method m,
java.lang.String methodName,
java.lang.Object methodParameter)
Retrieves a simple method (with a single parameter)
from the instance of an object.
|
static void |
handleReflectionException(java.lang.Exception e)
A very simple error handler for the Reflections utility class.
|
static Reflections |
valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name.
|
static Reflections[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
public static Reflections[] values()
for (Reflections c : Reflections.values()) System.out.println(c);
public static Reflections valueOf(java.lang.String name)
name
- the name of the enum constant to be returned.java.lang.IllegalArgumentException
- if this enum type has no constant with the specified namejava.lang.NullPointerException
- if the argument is nullpublic static java.lang.Object getSimpleClass(java.lang.String[] clazzez, java.lang.Object constructorParameter)
Object gson = Reflections.getSimpleClass(new String[] { // mc 1.8+ "com.google.gson.Gson", // mc 1.7 "net.minecraft.util.com.google.gson.Gson", // mc 1.6 "org.bukkit.craftbukkit.libs.com.google.gson.Gson" }, null);
clazzez
- List of class locations where to look for a class we need.constructorParameter
- Optional (can be null) constructor parameter. Only single parameter constructors are supported for now.public static java.lang.reflect.Method getSimpleMethodFromObjectInstance(java.lang.Object o, java.lang.reflect.Method m, java.lang.String methodName, java.lang.Object methodParameter)
// this will be null at first Method myMethod; // try to get a simple, parameter-less method definition myMethod = Reflections.getSimpleMethodFromObjectInstance(someObjectInstance, myMethod, "myMethodName", null); // here, myMethod would already be defined, so getSimpleMethodFromObjectInstance() would simply // return myMethod's value straight away myMethod = Reflections.getSimpleMethodFromObjectInstance(someObjectInstance, myMethod, "myMethodName", null);
o
- The object instance to retrieve the method from.m
- This parameter must be either null or any Method. If a Method is passed
as this parameter, then a name check if performed if it's not the same method
as we want to retrieve. If it is, we simply return it. Otherwise, Reflection
is used and the method is retrieved that way.methodName
- Name of the method we want to retrieve from the given object.methodParameter
- An optional (can be null) parameter for the given method, if multiple
method definitions exist with different parameters.public static void handleReflectionException(java.lang.Exception e)
e
- The actual exception to log.