net.sf.mmm.util.reflect.api
Interface AnnotationUtil

All Known Implementing Classes:
AnnotationUtilImpl

@ComponentSpecification
public interface AnnotationUtil

This is the interface for a collection of utility functions to deal with annotations.

Since:
1.0.2
Author:
Joerg Hohwiller (hohwille at users.sourceforge.net)
See Also:
AnnotationUtil

Field Summary
static ElementType[] NO_TARGET
          an empty element-type array
 
Method Summary
<A extends Annotation>
A
getClassAnnotation(Class<?> annotatedClass, Class<A> annotationClass)
          This method gets the first annotation of the type given by annotation in the class hierarchy of the given annotatedClass.
<A extends Annotation>
A
getMethodAnnotation(Method annotatedMethod, Class<A> annotationClass)
          This method gets the first annotation of the type given by annotation in the hierarchy of the given method.
<A extends Annotation>
A
getTypeAnnotation(Class<?> annotatedType, Class<A> annotationClass)
          This method gets the first annotation of the type given by annotation in the declaration of the given annotatedType.
<A extends Annotation>
boolean
isAnnotationForType(Class<A> annotationType, ElementType targetType)
          This method determines if the given annotationType represents an Annotation that has a Target compatible with the given targetType.
<A extends Annotation>
boolean
isRuntimeAnnotation(Class<A> annotationType)
          This method determines if the given annotationType represents an Annotation that has the Retention runtime and can therefore be resolved at runtime.
 

Field Detail

NO_TARGET

static final ElementType[] NO_TARGET
an empty element-type array

Method Detail

isRuntimeAnnotation

<A extends Annotation> boolean isRuntimeAnnotation(Class<A> annotationType)
This method determines if the given annotationType represents an Annotation that has the Retention runtime and can therefore be resolved at runtime.

Type Parameters:
A - is the type of the annotation to check.
Parameters:
annotationType - is the type of the annotation to check.
Returns:
true if the given annotationType can be resolved at runtime.

isAnnotationForType

<A extends Annotation> boolean isAnnotationForType(Class<A> annotationType,
                                                   ElementType targetType)
This method determines if the given annotationType represents an Annotation that has a Target compatible with the given targetType.

Type Parameters:
A - is the type of the annotation to check.
Parameters:
annotationType - is the type of the annotation to check.
targetType - is the expected target-type to check.
Returns:
true if the given annotationType can be used to annotate elements of the given targetType.

getClassAnnotation

<A extends Annotation> A getClassAnnotation(Class<?> annotatedClass,
                                            Class<A> annotationClass)
                                        throws IllegalArgumentException
This method gets the first annotation of the type given by annotation in the class hierarchy of the given annotatedClass.
INFORMATION:
This method is only useful if the given annotation is a runtime annotation that is applicable for classes. If the annotation is inherited you may want to directly use Class.getAnnotation(Class) instead.

Type Parameters:
A - is the type of the requested annotation.
Parameters:
annotatedClass - is the class potentially annotated with the given annotation. This should NOT be an interface, primitive, array, enum, or annotation.
annotationClass - is the type of the requested annotation.
Returns:
the requested annotation or null if neither the annotatedClass nor one of its super-classes are annotated with the given annotation.
Throws:
IllegalArgumentException - if the given annotation is no runtime annotation or is NOT applicable for classes.
See Also:
getTypeAnnotation(Class, Class)

getTypeAnnotation

<A extends Annotation> A getTypeAnnotation(Class<?> annotatedType,
                                           Class<A> annotationClass)
This method gets the first annotation of the type given by annotation in the declaration of the given annotatedType.
Instead of getClassAnnotation(Class, Class) this method will also scan implemented interfaces for the given annotation.
This method is only useful if the given annotation is a runtime annotation.

Type Parameters:
A - is the type of the requested annotation.
Parameters:
annotatedType - is the class or interface potentially annotated with the given annotation. This should NOT be an primitive, array , enum, or annotation.
annotationClass - is the type of the requested annotation.
Returns:
the requested annotation or null if neither the annotatedType nor one of its super-classes, or any implemented interfaces (no matter if implemented directly or indirectly) are annotated with the given annotation.

getMethodAnnotation

<A extends Annotation> A getMethodAnnotation(Method annotatedMethod,
                                             Class<A> annotationClass)
This method gets the first annotation of the type given by annotation in the hierarchy of the given method.
This method is only useful if the given annotation is a runtime annotation.

Type Parameters:
A - is the type of the requested annotation.
Parameters:
annotatedMethod - is the method potentially annotated with the given annotation.
annotationClass - is the type of the requested annotation.
Returns:
the requested annotation or null if neither the annotatedMethod nor one of its parent methods are annotated with the given annotation.


Copyright © 2001-2010 mmm-Team. All Rights Reserved.