Package org.infinispan.commons.util
Class ReflectionUtil
java.lang.Object
org.infinispan.commons.util.ReflectionUtil
Basic reflection utilities to enhance what the JDK provides.
- Since:
- 4.0
- Author:
- Manik Surtani (manik@jboss.org)
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic 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) getAllFields
(Class<?> c, Class<? extends Annotation> annotationType) getAllMethods
(Class<?> c, Class<? extends Annotation> annotationType) Returns a set of Methods that contain the given method annotation.getAllMethodsShallow
(Class<?> c, Class<? extends Annotation> annotationType) Returns a set of Methods that contain the given method annotation.getAnnotatedFields
(Class<?> c, Class<? extends Annotation> annotationType) static <T extends Annotation>
TgetAnnotation
(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
static int
getIntAccessibly
(Field f, Object instance) static Object
Retrieves the value of a field of an object instance via reflectionstatic Object
invokeAccessibly
(Object instance, Method method, Object... parameters) Invokes a method using reflection, in an accessible manner (by usingMethod.setAccessible(boolean)
static Object
invokeMethod
(Object instance, Method method, Object[] parameters) static boolean
isAnnotationPresent
(Class<?> clazz, Class<? extends Annotation> annotation) Tests whether an annotation is present on a class.static void
setAccessibly
(Object instance, Field field, Object value) static void
static Class<?>[]
toClassArray
(String[] typeList, ClassLoader classLoader) static String[]
toStringArray
(Class<?>[] classes) static <T> T
static <T> T
-
Field Details
-
EMPTY_CLASS_ARRAY
-
-
Constructor Details
-
ReflectionUtil
public ReflectionUtil()
-
-
Method Details
-
getAllMethods
Returns a set of Methods that contain the given method annotation. This includes all public, protected, package and private methods, as well as those of superclasses. Note that this does *not* include overridden methods.- Parameters:
c
- class to inspectannotationType
- the type of annotation to look for- Returns:
- List of Method objects that require injection.
-
getAllMethodsShallow
public static List<Method> getAllMethodsShallow(Class<?> c, Class<? extends Annotation> annotationType) Returns a set of Methods that contain the given method annotation. This includes all public, protected, package and private methods, but not those of superclasses and interfaces.- Parameters:
c
- class to inspectannotationType
- the type of annotation to look for- Returns:
- List of Method objects that require injection.
-
getAllFields
-
getAnnotatedFields
public static List<Field> getAnnotatedFields(Class<?> c, Class<? extends Annotation> annotationType) -
findMethod
-
findMethod
-
invokeAccessibly
Invokes a method using reflection, in an accessible manner (by usingMethod.setAccessible(boolean)
- Parameters:
instance
- instance on which to execute the methodmethod
- method to executeparameters
- parameters
-
invokeMethod
-
setAccessibly
-
setField
-
findGetterForField
-
findSetterForField
-
extractFieldName
-
getValue
Retrieves the value of a field of an object instance via reflection- Parameters:
instance
- to inspectfieldName
- name of field to retrieve- Returns:
- a value
-
getAnnotation
Inspects the class passed in for the class level annotation specified. If the annotation is not available, this method recursively inspects superclasses and interfaces until it finds the required annotation. Returns null if the annotation cannot be found.- Parameters:
clazz
- class to inspectann
- annotation to search for. Must be a class-level annotation.- Returns:
- the annotation instance, or null
-
isAnnotationPresent
Tests whether an annotation is present on a class. The order tested is:- The class itself
- All implemented interfaces
- Any superclasses
- Parameters:
clazz
- class to testannotation
- annotation to look for- Returns:
- true if the annotation is found, false otherwise
-
toClassArray
public static Class<?>[] toClassArray(String[] typeList, ClassLoader classLoader) throws ClassNotFoundException - Throws:
ClassNotFoundException
-
getClassForName
- Throws:
ClassNotFoundException
-
toStringArray
-
getField
-
unwrap
-
unwrapAny
-
getIntAccessibly
-