Package org.infinispan.commons.util
Class ReflectionUtil
- java.lang.Object
- 
- org.infinispan.commons.util.ReflectionUtil
 
- 
 public class ReflectionUtil extends Object Basic reflection utilities to enhance what the JDK provides.- Since:
- 4.0
- Author:
- Manik Surtani (manik@jboss.org)
 
- 
- 
Field SummaryFields Modifier and Type Field Description static Class<?>[]EMPTY_CLASS_ARRAY
 - 
Constructor SummaryConstructors Constructor Description ReflectionUtil()
 - 
Method SummaryAll Methods Static Methods Concrete Methods Modifier and Type Method Description static StringextractFieldName(String setterOrGetter)static MethodfindGetterForField(Class<?> c, String fieldName)static MethodfindMethod(Class<?> type, String methodName)static MethodfindMethod(Class<?> type, String methodName, Class<?>... parameters)static MethodfindSetterForField(Class<?> c, String fieldName)static List<Field>getAllFields(Class<?> c, Class<? extends Annotation> annotationType)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>
 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 FieldgetField(String fieldName, Class<?> objectClass)static intgetIntAccessibly(Field f, Object instance)static ObjectgetValue(Object instance, String fieldName)Retrieves the value of a field of an object instance via reflectionstatic ObjectinvokeAccessibly(Object instance, Method method, Object... parameters)Invokes a method using reflection, in an accessible manner (by usingAccessibleObject.setAccessible(boolean)static ObjectinvokeMethod(Object instance, Method method, Object[] parameters)static booleanisAnnotationPresent(Class<?> clazz, Class<? extends Annotation> annotation)Tests whether an annotation is present on a class.static voidsetAccessibly(Object instance, Field field, Object value)static voidsetField(Object instance, Field field, Object value)static Class<?>[]toClassArray(String[] typeList, ClassLoader classLoader)static String[]toStringArray(Class<?>[] classes)static <T> Tunwrap(Object obj, Class<T> clazz)static <T> TunwrapAny(Class<T> clazz, Object... objs)
 
- 
- 
- 
Field Detail- 
EMPTY_CLASS_ARRAYpublic static final Class<?>[] EMPTY_CLASS_ARRAY 
 
- 
 - 
Method Detail- 
getAllMethodspublic static List<Method> getAllMethods(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, as well as those of superclasses. Note that this does *not* include overridden methods.- Parameters:
- c- class to inspect
- annotationType- the type of annotation to look for
- Returns:
- List of Method objects that require injection.
 
 - 
getAllMethodsShallowpublic 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 inspect
- annotationType- the type of annotation to look for
- Returns:
- List of Method objects that require injection.
 
 - 
getAllFieldspublic static List<Field> getAllFields(Class<?> c, Class<? extends Annotation> annotationType) 
 - 
getAnnotatedFieldspublic static List<Field> getAnnotatedFields(Class<?> c, Class<? extends Annotation> annotationType) 
 - 
findMethodpublic static Method findMethod(Class<?> type, String methodName, Class<?>... parameters) 
 - 
invokeAccessiblypublic static Object invokeAccessibly(Object instance, Method method, Object... parameters) Invokes a method using reflection, in an accessible manner (by usingAccessibleObject.setAccessible(boolean)- Parameters:
- instance- instance on which to execute the method
- method- method to execute
- parameters- parameters
 
 - 
invokeMethodpublic static Object invokeMethod(Object instance, Method method, Object[] parameters) 
 - 
getValuepublic static Object getValue(Object instance, String fieldName) Retrieves the value of a field of an object instance via reflection- Parameters:
- instance- to inspect
- fieldName- name of field to retrieve
- Returns:
- a value
 
 - 
getAnnotationpublic static <T extends Annotation> T getAnnotation(Class<?> clazz, Class<T> ann) 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 inspect
- ann- annotation to search for. Must be a class-level annotation.
- Returns:
- the annotation instance, or null
 
 - 
isAnnotationPresentpublic static boolean isAnnotationPresent(Class<?> clazz, Class<? extends Annotation> annotation) 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 test
- annotation- annotation to look for
- Returns:
- true if the annotation is found, false otherwise
 
 - 
toClassArraypublic static Class<?>[] toClassArray(String[] typeList, ClassLoader classLoader) throws ClassNotFoundException - Throws:
- ClassNotFoundException
 
 - 
getClassForNamepublic static Class<?> getClassForName(String name, ClassLoader cl) throws ClassNotFoundException - Throws:
- ClassNotFoundException
 
 
- 
 
-