public class ReflectionUtil
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static java.lang.Class<?>[] |
EMPTY_CLASS_ARRAY |
| Constructor and Description |
|---|
ReflectionUtil() |
| Modifier and Type | Method and Description |
|---|---|
static java.lang.String |
extractFieldName(java.lang.String setterOrGetter) |
static java.lang.reflect.Method |
findGetterForField(java.lang.Class<?> c,
java.lang.String fieldName) |
static java.lang.reflect.Method |
findMethod(java.lang.Class<?> type,
java.lang.String methodName) |
static java.lang.reflect.Method |
findMethod(java.lang.Class<?> type,
java.lang.String methodName,
java.lang.Class<?>[] parameters) |
static java.lang.reflect.Method |
findSetterForField(java.lang.Class<?> c,
java.lang.String fieldName) |
static java.util.List<java.lang.reflect.Field> |
getAllFields(java.lang.Class<?> c,
java.lang.Class<? extends java.lang.annotation.Annotation> annotationType) |
static java.util.List<java.lang.reflect.Method> |
getAllMethods(java.lang.Class<?> c,
java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Returns a set of Methods that contain the given method annotation.
|
static java.util.List<java.lang.reflect.Method> |
getAllMethodsShallow(java.lang.Class<?> c,
java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Returns a set of Methods that contain the given method annotation.
|
static java.util.List<java.lang.reflect.Field> |
getAnnotatedFields(java.lang.Class<?> c,
java.lang.Class<? extends java.lang.annotation.Annotation> annotationType) |
static <T extends java.lang.annotation.Annotation> |
getAnnotation(java.lang.Class<?> clazz,
java.lang.Class<T> ann)
Inspects the class passed in for the class level annotation specified.
|
static java.lang.Class<?> |
getClassForName(java.lang.String name,
java.lang.ClassLoader cl) |
static java.lang.reflect.Field |
getField(java.lang.String fieldName,
java.lang.Class<?> objectClass) |
static int |
getIntAccessibly(java.lang.reflect.Field f,
java.lang.Object instance) |
static java.lang.Object |
getValue(java.lang.Object instance,
java.lang.String fieldName)
Retrieves the value of a field of an object instance via reflection
|
static java.lang.Object |
invokeAccessibly(java.lang.Object instance,
java.lang.reflect.Method method,
java.lang.Object[] parameters)
Invokes a method using reflection, in an accessible manner (by using
AccessibleObject.setAccessible(boolean) |
static boolean |
isAnnotationPresent(java.lang.Class<?> clazz,
java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
Tests whether an annotation is present on a class.
|
static void |
setAccessibly(java.lang.Object instance,
java.lang.reflect.Field field,
java.lang.Object value) |
static java.lang.Class<?>[] |
toClassArray(java.lang.String[] typeList,
java.lang.ClassLoader classLoader) |
static java.lang.String[] |
toStringArray(java.lang.Class<?>[] classes) |
static <T> T |
unwrap(java.lang.Object obj,
java.lang.Class<T> clazz) |
static <T> T |
unwrapAny(java.lang.Class<T> clazz,
java.lang.Object... objs) |
public static java.util.List<java.lang.reflect.Method> getAllMethods(java.lang.Class<?> c,
java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
c - class to inspectannotationType - the type of annotation to look forpublic static java.util.List<java.lang.reflect.Method> getAllMethodsShallow(java.lang.Class<?> c,
java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
c - class to inspectannotationType - the type of annotation to look forpublic static java.util.List<java.lang.reflect.Field> getAllFields(java.lang.Class<?> c,
java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
public static java.util.List<java.lang.reflect.Field> getAnnotatedFields(java.lang.Class<?> c,
java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
public static java.lang.reflect.Method findMethod(java.lang.Class<?> type,
java.lang.String methodName)
public static java.lang.reflect.Method findMethod(java.lang.Class<?> type,
java.lang.String methodName,
java.lang.Class<?>[] parameters)
public static java.lang.Object invokeAccessibly(java.lang.Object instance,
java.lang.reflect.Method method,
java.lang.Object[] parameters)
AccessibleObject.setAccessible(boolean)instance - instance on which to execute the methodmethod - method to executeparameters - parameterspublic static void setAccessibly(java.lang.Object instance,
java.lang.reflect.Field field,
java.lang.Object value)
public static java.lang.reflect.Method findGetterForField(java.lang.Class<?> c,
java.lang.String fieldName)
public static java.lang.reflect.Method findSetterForField(java.lang.Class<?> c,
java.lang.String fieldName)
public static java.lang.String extractFieldName(java.lang.String setterOrGetter)
public static java.lang.Object getValue(java.lang.Object instance,
java.lang.String fieldName)
instance - to inspectfieldName - name of field to retrievepublic static <T extends java.lang.annotation.Annotation> T getAnnotation(java.lang.Class<?> clazz,
java.lang.Class<T> ann)
clazz - class to inspectann - annotation to search for. Must be a class-level annotation.public static boolean isAnnotationPresent(java.lang.Class<?> clazz,
java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
clazz - class to testannotation - annotation to look forpublic static java.lang.Class<?>[] toClassArray(java.lang.String[] typeList,
java.lang.ClassLoader classLoader)
throws java.lang.ClassNotFoundException
java.lang.ClassNotFoundExceptionpublic static java.lang.Class<?> getClassForName(java.lang.String name,
java.lang.ClassLoader cl)
throws java.lang.ClassNotFoundException
java.lang.ClassNotFoundExceptionpublic static java.lang.String[] toStringArray(java.lang.Class<?>[] classes)
public static java.lang.reflect.Field getField(java.lang.String fieldName,
java.lang.Class<?> objectClass)
public static <T> T unwrap(java.lang.Object obj,
java.lang.Class<T> clazz)
public static <T> T unwrapAny(java.lang.Class<T> clazz,
java.lang.Object... objs)
public static int getIntAccessibly(java.lang.reflect.Field f,
java.lang.Object instance)