Top Description Fields Constructors Methods
org.glassfish.pfl.basic.algorithm

public Class AnnotationAnalyzer

extends Object
Class Inheritance
Imports
java.lang.annotation.Annotation, java.lang.reflect.AnnotatedElement, .Constructor, .Field, .Method, java.util.ArrayList, .Arrays, .HashMap, .HashSet, .List, .Map, .Set, .WeakHashMap, org.glassfish.pfl.basic.contain.Pair, org.glassfish.pfl.basic.func.UnaryPredicate

Given an AnnotatedElement, fetch all of the inherited annotations. This include annotations on methods that may be overridden. Uses ClassAnalyzer to linearize the inheritance hierarchy. This also includes any added annotations for Class and Method. Constructor, Field, Parameter, and Package annotations are just translated from the standard reflective calls.
Author
ken_admin

Field Summary

Modifier and TypeField and Description
private final Map<AnnotatedElement, Map<Class<?>, Annotation>>
private final Map<AnnotatedElement, Map<Class<?>, Annotation>>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public synchronized void
addAnnotation(AnnotatedElement element, Annotation annotation)

Add an annotation to element, which must be a Class, Method, or Constructor.

public synchronized void
addInheritedAnnotations(final Class<?> cls, final Class<?> ancestor)

Add all annotations on cls (including inherited annotations and its methods (including overridden methods in super classes and interfaces) to super (which must be a super class or interface of cls).

public <A extends Annotation> A
public Map<Class<?>, Annotation>

Returns:

Map from annotation class to annotation value.
getAnnotations
(final Class<?>
Class to analyze.
cls
)

Return a map of all annotations defined on cls and its super classes and interfaces in ClassAnalyzer order.

private Map<Class<?>, Annotation>
getAnnotations(final Class<?> cls, final boolean includeAddedAnnotations)

public Map<Class<?>, Annotation>

Returns:

A map from annotation class to annotation
getAnnotations
(Method
The method to analyze
method
)

Return a map of all annotations defined in method and its overriden methods in the inheritance order of the ClassAnalyzer for the method's defining class.

private Map<Class<?>, Annotation>
getAnnotations(final Method method, final boolean includeAddedAnnotations)

public Map<Class<?>, Annotation>

Returns:

A map from annotation class to annotation value
getAnnotations
(Constructor<?>
A Java Constructor
cons
)

Same as cons.getAnnotations, with the result converted to a map.

public Map<Class<?>, Annotation>

Returns:

A map from annotation class to annotation value
getAnnotations
(Field
A Java Field
fld
)

Same as fld.getAnnotations, with the result converted to a map.

public Map<Class<?>, Annotation>

Returns:

A map from annotation class to annotation value
getAnnotations
(Package
A Java Package
pkg
)

Same as pkg.getAnnotations, with the result converted to a map.

public Map<Class<?>, Annotation>

Returns:

A map from annotation class to annotation value.
getAnnotations
(AnnotatedElement
AnnotatedElement
elem
)

Return all annotations on the element, including any added annotations.

public List<Map<Class<?>, Annotation>>

Returns:

A list of maps from annotation class to annotation value
getParameterAnnotations
(Method
A Java Method
method
)

Same as cons.getParameterAnnotations, with the result converted to a list of maps.

public List<Map<Class<?>, Annotation>>

Returns:

A list of maps from annotation class to annotation value
getParameterAnnotations
(Constructor<?>
A Java Constructor
cons
)

Same as cons.getParameterAnnotations, with the result converted to a list of maps.

private Map<Class<?>, Annotation>
private synchronized <K, V> void
putIfNotPresent(final Map<K, V> map, final K key, final V value)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

addedAnnotationsback to summary
private final Map<AnnotatedElement, Map<Class<?>, Annotation>> addedAnnotations
annotationCacheback to summary
private final Map<AnnotatedElement, Map<Class<?>, Annotation>> annotationCache

Constructor Detail

AnnotationAnalyzerback to summary
public AnnotationAnalyzer()

Method Detail

addAnnotationback to summary
public synchronized void addAnnotation(AnnotatedElement element, Annotation annotation)

Add an annotation to element, which must be a Class, Method, or Constructor.

addInheritedAnnotationsback to summary
public synchronized void addInheritedAnnotations(final Class<?> cls, final Class<?> ancestor)

Add all annotations on cls (including inherited annotations and its methods (including overridden methods in super classes and interfaces) to super (which must be a super class or interface of cls).

getAnnotationback to summary
public <A extends Annotation> A getAnnotation(AnnotatedElement elem, Class<A> cls)
getAnnotationsback to summary
public Map<Class<?>, Annotation> getAnnotations(final Class<?> cls)

Return a map of all annotations defined on cls and its super classes and interfaces in ClassAnalyzer order. Annotations nearer the front of the list replace those later in the list of the same type.

Parameters
cls:Class<?>

Class to analyze.

Returns:Map<Class<?>, Annotation>

Map from annotation class to annotation value.

getAnnotationsback to summary
private Map<Class<?>, Annotation> getAnnotations(final Class<?> cls, final boolean includeAddedAnnotations)
getAnnotationsback to summary
public Map<Class<?>, Annotation> getAnnotations(Method method)

Return a map of all annotations defined in method and its overriden methods in the inheritance order of the ClassAnalyzer for the method's defining class.

Parameters
method:Method

The method to analyze

Returns:Map<Class<?>, Annotation>

A map from annotation class to annotation

getAnnotationsback to summary
private Map<Class<?>, Annotation> getAnnotations(final Method method, final boolean includeAddedAnnotations)
getAnnotationsback to summary
public Map<Class<?>, Annotation> getAnnotations(Constructor<?> cons)

Same as cons.getAnnotations, with the result converted to a map.

Parameters
cons:Constructor<?>

A Java Constructor

Returns:Map<Class<?>, Annotation>

A map from annotation class to annotation value

getAnnotationsback to summary
public Map<Class<?>, Annotation> getAnnotations(Field fld)

Same as fld.getAnnotations, with the result converted to a map.

Parameters
fld:Field

A Java Field

Returns:Map<Class<?>, Annotation>

A map from annotation class to annotation value

getAnnotationsback to summary
public Map<Class<?>, Annotation> getAnnotations(Package pkg)

Same as pkg.getAnnotations, with the result converted to a map.

Parameters
pkg:Package

A Java Package

Returns:Map<Class<?>, Annotation>

A map from annotation class to annotation value

getAnnotationsback to summary
public Map<Class<?>, Annotation> getAnnotations(AnnotatedElement elem)

Return all annotations on the element, including any added annotations. Really just a convenience wrapper for the other getAnnotations methods.

Parameters
elem:AnnotatedElement

AnnotatedElement

Returns:Map<Class<?>, Annotation>

A map from annotation class to annotation value.

getParameterAnnotationsback to summary
public List<Map<Class<?>, Annotation>> getParameterAnnotations(Method method)

Same as cons.getParameterAnnotations, with the result converted to a list of maps.

Parameters
method:Method

A Java Method

Returns:List<Map<Class<?>, Annotation>>

A list of maps from annotation class to annotation value

getParameterAnnotationsback to summary
public List<Map<Class<?>, Annotation>> getParameterAnnotations(Constructor<?> cons)

Same as cons.getParameterAnnotations, with the result converted to a list of maps.

Parameters
cons:Constructor<?>

A Java Constructor

Returns:List<Map<Class<?>, Annotation>>

A list of maps from annotation class to annotation value

makeAnnoMapback to summary
private Map<Class<?>, Annotation> makeAnnoMap(Annotation[] annos)
putIfNotPresentback to summary
private synchronized <K, V> void putIfNotPresent(final Map<K, V> map, final K key, final V value)