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 |
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 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 Class<?>[] |
toClassArray(String[] typeList,
ClassLoader classLoader) |
static String[] |
toStringArray(Class<?>[] classes) |
static <T> T |
unwrap(Object obj,
Class<T> clazz) |
static <T> T |
unwrapAny(Class<T> clazz,
Object... objs) |
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, Class<?>[] 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 Class<?>[] toClassArray(String[] typeList, ClassLoader classLoader) throws ClassNotFoundException
ClassNotFoundException
public static Class<?> getClassForName(String name, ClassLoader cl) throws ClassNotFoundException
ClassNotFoundException
Copyright © 2017 JBoss, a division of Red Hat. All rights reserved.