org.unitils.util
Class AnnotationUtils

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

public class AnnotationUtils
extends java.lang.Object

Utilities for retrieving and working with annotations.

Author:
Filip Neven, Tim Ducheyne

Constructor Summary
AnnotationUtils()
           
 
Method Summary
static
<T> T
getAnnotationPropertyValue(java.lang.reflect.Method annotationProperty, java.lang.annotation.Annotation annotation)
           
static java.lang.reflect.Method getAnnotationPropertyWithName(java.lang.Class<? extends java.lang.annotation.Annotation> annotation, java.lang.String annotationPropertyName)
           
static
<T extends java.lang.annotation.Annotation>
T
getClassLevelAnnotation(java.lang.Class<T> annotationClass, java.lang.Class<?> clazz)
           
static
<S extends java.lang.annotation.Annotation,T>
T
getClassLevelAnnotationProperty(java.lang.Class<S> annotationClass, java.lang.String annotationPropertyName, T defaultValue, java.lang.Class<?> clazz)
           
static
<T extends java.lang.annotation.Annotation>
java.util.Set<T>
getFieldLevelAnnotations(java.lang.Class<?> clazz, java.lang.Class<T> annotation)
           
static
<T extends java.lang.annotation.Annotation>
java.util.Set<java.lang.reflect.Field>
getFieldsAnnotatedWith(java.lang.Class<? extends java.lang.Object> clazz, java.lang.Class<T> annotation)
          Returns the given class's declared fields that are marked with the given annotation
static
<T extends java.lang.annotation.Annotation>
java.util.Set<T>
getMethodLevelAnnotations(java.lang.Class<?> clazz, java.lang.Class<T> annotation)
           
static
<T extends java.lang.annotation.Annotation>
T
getMethodOrClassLevelAnnotation(java.lang.Class<T> annotationClass, java.lang.reflect.Method method, java.lang.Class<?> clazz)
           
static
<S extends java.lang.annotation.Annotation,T>
T
getMethodOrClassLevelAnnotationProperty(java.lang.Class<S> annotationClass, java.lang.String annotationPropertyName, T defaultValue, java.lang.reflect.Method method, java.lang.Class<?> clazz)
           
static
<T extends java.lang.annotation.Annotation>
java.util.Set<java.lang.reflect.Method>
getMethodsAnnotatedWith(java.lang.Class<?> clazz, java.lang.Class<T> annotation)
          Returns the given class's (and superclasses) declared methods that are marked with the given annotation
static
<T extends java.lang.annotation.Annotation>
java.util.Set<java.lang.reflect.Method>
getMethodsAnnotatedWith(java.lang.Class<?> clazz, java.lang.Class<T> annotation, boolean includeInherited)
          Returns the given class's declared methods that are marked with the given annotation
static boolean hasClassMethodOrFieldLevelAnnotation(java.lang.Class<?> clazz, java.lang.Class<? extends java.lang.annotation.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 java.lang.annotation.Annotation> java.util.Set<java.lang.reflect.Field> getFieldsAnnotatedWith(java.lang.Class<? extends java.lang.Object> clazz,
                                                                                                                        java.lang.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 java.lang.annotation.Annotation> java.util.Set<java.lang.reflect.Method> getMethodsAnnotatedWith(java.lang.Class<?> clazz,
                                                                                                                          java.lang.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 java.lang.annotation.Annotation> java.util.Set<T> getMethodLevelAnnotations(java.lang.Class<?> clazz,
                                                                                                     java.lang.Class<T> annotation)

getFieldLevelAnnotations

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

getMethodsAnnotatedWith

public static <T extends java.lang.annotation.Annotation> java.util.Set<java.lang.reflect.Method> getMethodsAnnotatedWith(java.lang.Class<?> clazz,
                                                                                                                          java.lang.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 java.lang.annotation.Annotation> T getMethodOrClassLevelAnnotation(java.lang.Class<T> annotationClass,
                                                                                            java.lang.reflect.Method method,
                                                                                            java.lang.Class<?> clazz)

getClassLevelAnnotation

public static <T extends java.lang.annotation.Annotation> T getClassLevelAnnotation(java.lang.Class<T> annotationClass,
                                                                                    java.lang.Class<?> clazz)

getMethodOrClassLevelAnnotationProperty

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

getClassLevelAnnotationProperty

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

getAnnotationPropertyWithName

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

getAnnotationPropertyValue

public static <T> T getAnnotationPropertyValue(java.lang.reflect.Method annotationProperty,
                                               java.lang.annotation.Annotation annotation)

hasClassMethodOrFieldLevelAnnotation

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


Copyright © 2009. All Rights Reserved.