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