public class ReflectUtils extends Object
| Modifier and Type | Class and Description |
|---|---|
static interface |
ReflectUtils.FieldCallback
Callback interface invoked on each field in the hierarchy.
|
static interface |
ReflectUtils.FieldFilter
Callback optionally used to filter fields to be operated on by a field callback.
|
static interface |
ReflectUtils.MethodCallback
Action to take on each method.
|
static interface |
ReflectUtils.MethodFilter
Callback optionally used to filter methods to be operated on by a method callback.
|
| Modifier and Type | Method and Description |
|---|---|
static void |
doWithFields(Class<?> clazz,
ReflectUtils.FieldCallback fc)
Invoke the given callback on all fields in the target class, going up the
class hierarchy to get all declared fields.
|
static void |
doWithFields(Class<?> clazz,
ReflectUtils.FieldCallback fc,
ReflectUtils.FieldFilter ff)
Invoke the given callback on all fields in the target class, going up the
class hierarchy to get all declared fields.
|
static void |
doWithMethods(Class<?> clazz,
ReflectUtils.MethodCallback mc)
Perform the given callback operation on all matching methods of the given
class and superclasses.
|
static void |
doWithMethods(Class<?> clazz,
ReflectUtils.MethodCallback mc,
ReflectUtils.MethodFilter mf)
Perform the given callback operation on all matching methods of the given
class and superclasses (or given interface and super-interfaces).
|
static Object |
get(Field field,
Object object) |
static Set<Field> |
getAllDeclaredFields(Class<?> theClass) |
static Field[] |
getAnnotatedFields(Class<?> targetClass,
Class<? extends Annotation> annotationClass) |
static List<Method> |
getAnnotatedMethods(Class<?> targetClass,
Class<? extends Annotation> annotationClass) |
static <T extends Annotation> |
getAnnotation(Class<?> theClass,
Class<T> theAnnotation)
Return the given annotation from the class.
|
static Class<?> |
getClass(String className) |
static <T> Constructor<T> |
getConstructor(Class<T> type,
Class<?>[] parameterTypes) |
static Field |
getField(Class<?> clazz,
String fieldName)
searches for the field in the given class and in its super classes
|
static Method |
getFirstMethodOfName(Class<?> clazz,
String name) |
static Method |
getMethod(Class<?> clazz,
String methodName,
Class<?>[] parameterTypes)
searches for the method in the given class and in its super classes
|
static String |
getPackageName(String className) |
static Object |
getStatic(Field field) |
static Class<?>[] |
getSuperclasses(Class<?> type)
Returns all superclasses.
|
static boolean |
hasAnnotation(Class<?> theClass,
Class<? extends Annotation> theAnnotation)
Return whether or not the class has the given annotation.
|
static Object |
invoke(Method method,
Object target) |
static Object |
invoke(Method method,
Object target,
Object[] args) |
static Object |
invokeStatic(Method method) |
static Object |
invokeStatic(Method method,
Object[] args) |
static boolean |
isAnnotatedWith(Object obj,
Class<? extends Annotation> theAnnotation) |
static boolean |
isBeanProperty(Method method)
Returns
true if method is a bean property. |
static boolean |
isUserDefinedMethod(Method method)
Returns
true if method is user defined and not defined in Object class. |
static String |
logMethod(Method method) |
static <T> T |
newInstance(Class<T> clazz) |
static <T> T |
newInstance(Constructor<T> constructor) |
static <T> T |
newInstance(Constructor<T> constructor,
Object[] args) |
static <T> T |
newInstance(String className) |
static void |
set(Field field,
Object object,
Object value) |
static void |
setStatic(Field field,
Object value) |
public static Field getField(Class<?> clazz, String fieldName)
public static Method getMethod(Class<?> clazz, String methodName, Class<?>[] parameterTypes)
public static <T extends Annotation> T getAnnotation(Class<?> theClass, Class<T> theAnnotation)
theClass - the class to inspecttheAnnotation - the annotation to retrievepublic static boolean hasAnnotation(Class<?> theClass, Class<? extends Annotation> theAnnotation)
theClass - the class to checktheAnnotation - the annotation to look forpublic static List<Method> getAnnotatedMethods(Class<?> targetClass, Class<? extends Annotation> annotationClass)
public static Field[] getAnnotatedFields(Class<?> targetClass, Class<? extends Annotation> annotationClass)
public static boolean isAnnotatedWith(Object obj, Class<? extends Annotation> theAnnotation)
public static <T> Constructor<T> getConstructor(Class<T> type, Class<?>[] parameterTypes)
public static <T> T newInstance(String className)
public static <T> T newInstance(Class<T> clazz)
public static <T> T newInstance(Constructor<T> constructor)
public static <T> T newInstance(Constructor<T> constructor, Object[] args)
public static void doWithFields(Class<?> clazz, ReflectUtils.FieldCallback fc) throws IllegalArgumentException
clazz - the target class to analyzefc - the callback to invoke for each fieldIllegalArgumentExceptionpublic static void doWithFields(Class<?> clazz, ReflectUtils.FieldCallback fc, ReflectUtils.FieldFilter ff) throws IllegalArgumentException
clazz - the target class to analyzefc - the callback to invoke for each fieldff - the filter that determines the fields to apply the callback toIllegalArgumentExceptionpublic static void doWithMethods(Class<?> clazz, ReflectUtils.MethodCallback mc) throws IllegalArgumentException
The same named method occurring on subclass and superclass will appear
twice, unless excluded by a ReflectUtils.MethodFilter.
clazz - class to start looking atmc - the callback to invoke for each methodIllegalArgumentExceptiondoWithMethods(Class, MethodCallback, MethodFilter)public static void doWithMethods(Class<?> clazz, ReflectUtils.MethodCallback mc, ReflectUtils.MethodFilter mf) throws IllegalArgumentException
The same named method occurring on subclass and superclass will appear
twice, unless excluded by the specified ReflectUtils.MethodFilter.
clazz - class to start looking atmc - the callback to invoke for each methodmf - the filter that determines the methods to apply the callback toIllegalArgumentExceptionpublic static boolean isUserDefinedMethod(Method method)
true if method is user defined and not defined in Object class.public static boolean isBeanProperty(Method method)
true if method is a bean property.Copyright © 2013–2016. All rights reserved.