org.unitils.util
Class AnnotationUtils

java.lang.Object
  extended by org.unitils.util.AnnotationUtils

public class AnnotationUtils
extends Object

Utilities for retrieving and working with annotations.

Author:
Filip Neven, Tim Ducheyne

Constructor Summary
AnnotationUtils()
           
 
Method Summary
static
<T> T
getAnnotationPropertyValue(Method annotationProperty, Annotation annotation)
           
static Method getAnnotationPropertyWithName(Class<? extends Annotation> annotation, String annotationPropertyName)
           
static
<T extends Annotation>
T
getClassLevelAnnotation(Class<T> annotationClass, Class<?> clazz)
           
static
<S extends Annotation,T>
T
getClassLevelAnnotationProperty(Class<S> annotationClass, String annotationPropertyName, T defaultValue, Class<?> clazz)
           
static
<T extends Annotation>
Set<T>
getFieldLevelAnnotations(Class<?> clazz, Class<T> annotation)
           
static
<T extends Annotation>
Set<Field>
getFieldsAnnotatedWith(Class<? extends Object> clazz, Class<T> annotation)
          Returns the given class's declared fields that are marked with the given annotation
static
<T extends Annotation>
Set<T>
getMethodLevelAnnotations(Class<?> clazz, Class<T> annotation)
           
static
<T extends Annotation>
T
getMethodOrClassLevelAnnotation(Class<T> annotationClass, Method method, Class<?> clazz)
           
static
<S extends Annotation,T>
T
getMethodOrClassLevelAnnotationProperty(Class<S> annotationClass, String annotationPropertyName, T defaultValue, Method method, Class<?> clazz)
           
static
<T extends Annotation>
Set<Method>
getMethodsAnnotatedWith(Class<?> clazz, Class<T> annotation)
          Returns the given class's (and superclasses) declared methods that are marked with the given annotation
static
<T extends Annotation>
Set<Method>
getMethodsAnnotatedWith(Class<?> clazz, Class<T> annotation, boolean includeInherited)
          Returns the given class's declared methods that are marked with the given annotation
static boolean hasClassMethodOrFieldLevelAnnotation(Class<?> clazz, Class<? extends Annotation> annotation)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AnnotationUtils

public AnnotationUtils()
Method Detail

getFieldsAnnotatedWith

public static <T extends Annotation> Set<Field> getFieldsAnnotatedWith(Class<? extends Object> clazz,
                                                                       Class<T> annotation)
Returns the given class's declared fields that are marked with the given annotation

Parameters:
clazz - The class, not null
annotation - The annotation, not null
Returns:
A List containing fields annotated with the given annotation, empty list if none found

getMethodsAnnotatedWith

public static <T extends Annotation> Set<Method> getMethodsAnnotatedWith(Class<?> clazz,
                                                                         Class<T> annotation)
Returns the given class's (and superclasses) declared methods that are marked with the given annotation

Parameters:
clazz - The class, not null
annotation - The annotation, not null
Returns:
A List containing methods annotated with the given annotation, empty list if none found

getMethodLevelAnnotations

public static <T extends Annotation> Set<T> getMethodLevelAnnotations(Class<?> clazz,
                                                                      Class<T> annotation)

getFieldLevelAnnotations

public static <T extends Annotation> Set<T> getFieldLevelAnnotations(Class<?> clazz,
                                                                     Class<T> annotation)

getMethodsAnnotatedWith

public static <T extends Annotation> Set<Method> getMethodsAnnotatedWith(Class<?> clazz,
                                                                         Class<T> annotation,
                                                                         boolean includeInherited)
Returns the given class's declared methods that are marked with the given annotation

Parameters:
clazz - The class, not null
annotation - The annotation, not null
includeInherited - True for also looking for methods in super-classes
Returns:
A List containing methods annotated with the given annotation, empty list if none found

getMethodOrClassLevelAnnotation

public static <T extends Annotation> T getMethodOrClassLevelAnnotation(Class<T> annotationClass,
                                                                       Method method,
                                                                       Class<?> clazz)

getClassLevelAnnotation

public static <T extends Annotation> T getClassLevelAnnotation(Class<T> annotationClass,
                                                               Class<?> clazz)

getMethodOrClassLevelAnnotationProperty

public static <S extends Annotation,T> T getMethodOrClassLevelAnnotationProperty(Class<S> annotationClass,
                                                                                 String annotationPropertyName,
                                                                                 T defaultValue,
                                                                                 Method method,
                                                                                 Class<?> clazz)

getClassLevelAnnotationProperty

public static <S extends Annotation,T> T getClassLevelAnnotationProperty(Class<S> annotationClass,
                                                                         String annotationPropertyName,
                                                                         T defaultValue,
                                                                         Class<?> clazz)

getAnnotationPropertyWithName

public static Method getAnnotationPropertyWithName(Class<? extends Annotation> annotation,
                                                   String annotationPropertyName)

getAnnotationPropertyValue

public static <T> T getAnnotationPropertyValue(Method annotationProperty,
                                               Annotation annotation)

hasClassMethodOrFieldLevelAnnotation

public static boolean hasClassMethodOrFieldLevelAnnotation(Class<?> clazz,
                                                           Class<? extends Annotation> annotation)


Copyright © 2011. All Rights Reserved.