public class SecureReflections extends Object
Constructor and Description |
---|
SecureReflections() |
Modifier and Type | Method and Description |
---|---|
static <T extends AccessibleObject> |
ensureAccessible(T accessibleObject)
Makes an object accessible.
|
static Class<?>[] |
extractValues(Annotation annotation)
Helper class for reading the value of an annotation
|
static Constructor<?> |
getConstructor(Class<?> clazz,
Class<?>... parameterTypes)
Gets a constructor from a class
|
static Constructor<?>[] |
getConstructors(Class<?> clazz)
Gets all constructors from a class
|
static <T> Constructor<T> |
getDeclaredConstructor(Class<T> clazz,
Class<?>... parameterTypes)
Gets a declared constructor from a class
|
static Constructor<?>[] |
getDeclaredConstructors(Class<?> clazz)
Gets all declared constructors from a class
|
static Field |
getDeclaredField(Class<?> clazz,
String fieldName)
Returns a named, declared field from a class
|
static Field[] |
getDeclaredFields(Class<?> clazz)
Returns all declared fields of a class
|
static Method |
getDeclaredMethod(Class<?> clazz,
String methodName,
Class<?>... parameterTypes)
Returns a named, declared method of a class
|
static Method[] |
getDeclaredMethods(Class<?> clazz)
Returns all declared methods of a class
|
static Field |
getField(Class<?> clazz,
String fieldName)
Return a named field from a class
|
static Field[] |
getFields(Class<?> clazz)
Returns all fields of a class
|
static Method |
getMethod(Class<?> clazz,
String methodName,
Class<?>... parameterTypes)
Returns a named method of a class
|
static Method[] |
getMethods(Class<?> clazz)
Returns all methods of a class
|
static <T> T |
invoke(Object instance,
Method method,
Object... parameters)
Invokes a given method with given parameters on an instance
|
static <T> T |
invoke(Object instance,
String methodName,
Object... parameters)
Invokes a given method with given parameters on an instance
|
static boolean |
isMethodExists(Class<?> clazz,
String methodName,
Class<?>... parameterTypes)
Checks if a method is found in a class
|
static Method |
lookupMethod(Class<?> clazz,
String methodName,
Class<?>... parameterTypes)
Returns a method from the class or any class/interface in the inheritance
hierarchy
|
static Method |
lookupMethod(Object instance,
Method method)
Looks up a method in an inheritance hierarchy
|
static <T> T |
newInstance(Class<T> clazz)
Creates a new instance of a class
|
static <T> T |
newUnsafeInstance(Class<T> clazz)
Creates a new instance of a class using unportable methods, if available
|
public static Field getField(Class<?> clazz, String fieldName) throws NoSuchFieldException
clazz
- The class to operate onfieldName
- The name of the fieldNoSuchFieldException
- If the field cannot be foundjava.lang.Class#getField(String))
public static Field getDeclaredField(Class<?> clazz, String fieldName) throws NoSuchFieldException
clazz
- The class to operate onfieldName
- The name of the fieldNoSuchFieldException
- If the field cannot be foundClass.getDeclaredField(String)
public static Field[] getFields(Class<?> clazz)
clazz
- The class to operate onClass.getFields()
public static Field[] getDeclaredFields(Class<?> clazz)
clazz
- The class to operate onClass.getDeclaredFields()
public static Method getMethod(Class<?> clazz, String methodName, Class<?>... parameterTypes) throws NoSuchMethodException
clazz
- The class to operate onmethodName
- The name of the methodparameterTypes
- The method parameter typesNoSuchMethodException
- If the method cannot be foundClass.getMethod(String, Class...)
public static Method getDeclaredMethod(Class<?> clazz, String methodName, Class<?>... parameterTypes) throws NoSuchMethodException
clazz
- The class to operate onmethodName
- The name of the methodparameterTypes
- The method parameter typesNoSuchMethodException
- If the method cannot be foundClass.getDeclaredMethods()
public static Method[] getMethods(Class<?> clazz)
clazz
- The class to operate onClass.getMethods()
public static Method[] getDeclaredMethods(Class<?> clazz)
clazz
- The class to operate onClass.getDeclaredMethods()
public static Constructor<?> getConstructor(Class<?> clazz, Class<?>... parameterTypes) throws NoSuchMethodException
clazz
- The class to operate onparameterTypes
- The constructor parameter typesNoSuchMethodException
- If the constructor cannot be foundClass.getConstructor(Class...)
public static <T> Constructor<T> getDeclaredConstructor(Class<T> clazz, Class<?>... parameterTypes) throws NoSuchMethodException
clazz
- The class to operate onparameterTypes
- The constructor parameter typesNoSuchMethodException
- If the constructor cannot be foundClass.getDeclaredConstructor(Class...)
public static Constructor<?>[] getConstructors(Class<?> clazz)
clazz
- The class to operate onClass.getConstructors()
public static Constructor<?>[] getDeclaredConstructors(Class<?> clazz)
clazz
- The class to operate onClass.getDeclaredConstructor(Class...)
public static <T> T invoke(Object instance, Method method, Object... parameters) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException
instance
- The instance to invoke onmethod
- The method to invokeparameters
- The method parametersIllegalArgumentException
- If there was an illegal argument passedIllegalAccessException
- If there was an illegal access attemptInvocationTargetException
- If there was another error invoking the
methodMethod.invoke(Object, Object...)
public static <T extends AccessibleObject> T ensureAccessible(T accessibleObject)
accessibleObjects
- The object to manipulatepublic static <T> T invoke(Object instance, String methodName, Object... parameters) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException
instance
- The instance to invoke onmethodName
- The name of the method to invokeparameters
- The method parametersIllegalArgumentException
- If there was an illegal argument passedIllegalAccessException
- If there was an illegal access attemptInvocationTargetException
- If there was another error invoking the
methodMethod.invoke(Object, Object...)
public static <T> T newInstance(Class<T> clazz) throws InstantiationException, IllegalAccessException
T
- The type of the instanceclazz
- The class to construct fromInstantiationException
- If the instance could not be createIllegalAccessException
- If there was an illegal access attemptClass.newInstance()
public static <T> T newUnsafeInstance(Class<T> clazz) throws InstantiationException, IllegalAccessException
T
- The type of the instanceclazz
- The class to construct fromInstantiationException
- If the instance could not be createIllegalAccessException
- If there was an illegal access attemptClass.newInstance()
public static Method lookupMethod(Object instance, Method method) throws NoSuchMethodException
instance
- The instance (class) to start frommethod
- The method to look upNoSuchMethodException
- if the method could not be foundpublic static Method lookupMethod(Class<?> clazz, String methodName, Class<?>... parameterTypes) throws NoSuchMethodException
clazz
- The class to searchmethodName
- The method nameparameterTypes
- The method parameter typesNoSuchMethodException
- If the method could not be foundpublic static Class<?>[] extractValues(Annotation annotation)
annotation
- The annotation to inspectpublic static boolean isMethodExists(Class<?> clazz, String methodName, Class<?>... parameterTypes)
clazz
- The class to inspectmethodName
- The name of the methodparameterTypes
- The parameter types of the methodCopyright © 2012 Seam Framework. All Rights Reserved.