|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.jboss.weld.util.reflection.SecureReflections
public class SecureReflections
Constructor Summary | |
---|---|
SecureReflections()
|
Method Summary | ||
---|---|---|
static
|
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
|
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
|
invoke(Object instance,
Method method,
Object... parameters)
Invokes a given method with given parameters on an instance |
|
static
|
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
|
newInstance(Class<T> clazz)
Creates a new instance of a class |
|
static
|
newUnsafeInstance(Class<T> clazz)
Creates a new instance of a class using unportable methods, if available |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public SecureReflections()
Method Detail |
---|
public static Field getField(Class<?> clazz, String fieldName) throws NoSuchFieldException
clazz
- The class to operate onfieldName
- The name of the field
NoSuchFieldException
- 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 field
NoSuchFieldException
- If the field cannot be foundClass.getDeclaredField(String)
public static Field[] getFields(Class<?> clazz)
clazz
- The class to operate on
Class.getFields()
public static Field[] getDeclaredFields(Class<?> clazz)
clazz
- The class to operate on
Class.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 types
NoSuchMethodException
- 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 types
NoSuchMethodException
- If the method cannot be foundClass.getDeclaredMethods()
public static Method[] getMethods(Class<?> clazz)
clazz
- The class to operate on
Class.getMethods()
public static Method[] getDeclaredMethods(Class<?> clazz)
clazz
- The class to operate on
Class.getDeclaredMethods()
public static Constructor<?> getConstructor(Class<?> clazz, Class<?>... parameterTypes) throws NoSuchMethodException
clazz
- The class to operate onparameterTypes
- The constructor parameter types
NoSuchMethodException
- 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 types
NoSuchMethodException
- If the constructor cannot be foundClass.getDeclaredConstructor(Class...)
public static Constructor<?>[] getConstructors(Class<?> clazz)
clazz
- The class to operate on
Class.getConstructors()
public static Constructor<?>[] getDeclaredConstructors(Class<?> clazz)
clazz
- The class to operate on
Class.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 parameters
IllegalArgumentException
- If there was an illegal argument passed
IllegalAccessException
- If there was an illegal access attempt
InvocationTargetException
- If there was another error invoking the
methodMethod.invoke(Object, Object...)
public static <T extends AccessibleObject> T ensureAccessible(T accessibleObject)
accessibleObject
- The object to manipulate
public 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 parameters
IllegalArgumentException
- If there was an illegal argument passed
IllegalAccessException
- If there was an illegal access attempt
InvocationTargetException
- 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 from
InstantiationException
- If the instance could not be create
IllegalAccessException
- 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 from
InstantiationException
- If the instance could not be create
IllegalAccessException
- 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 up
NoSuchMethodException
- 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 types
NoSuchMethodException
- If the method could not be foundpublic static Class<?>[] extractValues(Annotation annotation)
annotation
- The annotation to inspect
public static boolean isMethodExists(Class<?> clazz, String methodName, Class<?>... parameterTypes)
clazz
- The class to inspectmethodName
- The name of the methodparameterTypes
- The parameter types of the method
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |