public class ReflectionUtil extends Object
Modifier and Type | Field and Description |
---|---|
static Class<?>[] |
EMPTY_CLASS_ARRAY |
Constructor and Description |
---|
ReflectionUtil() |
Modifier and Type | Method and Description |
---|---|
static String |
extractFieldName(String setterOrGetter) |
static Method |
findGetterForField(Class<?> c,
String fieldName) |
static Method |
findMethod(Class<?> type,
String methodName) |
static Method |
findMethod(Class<?> type,
String methodName,
Class<?>[] parameters) |
static Method |
findMethod(Class<?> type,
String methodName,
String[] parameters) |
static Method |
findSetterForField(Class<?> c,
String fieldName) |
static List<Method> |
getAllMethods(Class<?> c,
Class<? extends Annotation> annotationType)
Returns a set of Methods that contain the given method annotation.
|
static List<Method> |
getAllMethodsShallow(Class<?> c,
Class<? extends Annotation> annotationType)
Returns a set of Methods that contain the given method annotation.
|
static List<Field> |
getAnnotatedFields(Class<?> c,
Class<? extends Annotation> annotationType) |
static <T extends Annotation> |
getAnnotation(Class<?> clazz,
Class<T> ann)
Inspects the class passed in for the class level annotation specified.
|
static Class<?> |
getClassForName(String name,
ClassLoader cl) |
static Field |
getField(String fieldName,
Class<?> objectClass) |
static List<Field> |
getFields(Class<?> c,
Class<?> type) |
static Object |
getValue(Object instance,
String fieldName)
Retrieves the value of a field of an object instance via reflection
|
static Object |
invokeAccessibly(Object instance,
Method method,
Object[] parameters)
Invokes a method using reflection, in an accessible manner (by using
AccessibleObject.setAccessible(boolean) |
static boolean |
isAnnotationPresent(Class<?> clazz,
Class<? extends Annotation> annotation)
Tests whether an annotation is present on a class.
|
static boolean |
isGetMethod(Method method) |
static boolean |
isIsMethod(Method method) |
static boolean |
isSetMethod(Method method) |
static void |
setValue(Object instance,
String fieldName,
Object value) |
static Class<?>[] |
toClassArray(String[] typeList) |
static String[] |
toStringArray(Class<?>[] classes) |
public static final Class<?>[] EMPTY_CLASS_ARRAY
public static List<Method> getAllMethods(Class<?> c, Class<? extends Annotation> annotationType)
c
- class to inspectannotationType
- the type of annotation to look forpublic static List<Method> getAllMethodsShallow(Class<?> c, Class<? extends Annotation> annotationType)
c
- class to inspectannotationType
- the type of annotation to look forpublic static List<Field> getAnnotatedFields(Class<?> c, Class<? extends Annotation> annotationType)
public static Method findMethod(Class<?> type, String methodName, String[] parameters) throws ClassNotFoundException
ClassNotFoundException
public static Object invokeAccessibly(Object instance, Method method, Object[] parameters)
AccessibleObject.setAccessible(boolean)
instance
- instance on which to execute the methodmethod
- method to executeparameters
- parameterspublic static Object getValue(Object instance, String fieldName)
instance
- to inspectfieldName
- name of field to retrievepublic static <T extends Annotation> T getAnnotation(Class<?> clazz, Class<T> ann)
clazz
- class to inspectann
- annotation to search for. Must be a class-level annotation.public static boolean isAnnotationPresent(Class<?> clazz, Class<? extends Annotation> annotation)
clazz
- class to testannotation
- annotation to look forpublic static boolean isSetMethod(Method method)
public static boolean isGetMethod(Method method)
public static boolean isIsMethod(Method method)
public static Class<?>[] toClassArray(String[] typeList) throws ClassNotFoundException
ClassNotFoundException
public static Class<?> getClassForName(String name, ClassLoader cl) throws ClassNotFoundException
ClassNotFoundException
Copyright © 2012 JBoss by Red Hat. All Rights Reserved.