org.hibernate.validator.ap.util
Class AnnotationApiHelper

java.lang.Object
  extended by org.hibernate.validator.ap.util.AnnotationApiHelper

public class AnnotationApiHelper
extends Object

A helper class providing some useful methods to work with types from the JSR-269-API.

Author:
Gunnar Morling

Constructor Summary
AnnotationApiHelper(Elements elementUtils, Types typeUtils)
           
 
Method Summary
 List<AnnotationMirror> filterByType(List<? extends AnnotationMirror> annotationMirrors, TypeMirror annotationType)
          Returns a list containing those annotation mirrors from the input list, which are of type annotationType.
 List<? extends AnnotationValue> getAnnotationArrayValue(AnnotationMirror annotationMirror, String name)
          Returns the given annotation mirror's array-typed annotation value with the given name.
 AnnotationValue getAnnotationValue(AnnotationMirror annotationMirror, String name)
          Returns the annotation value of the given annotation mirror with the given name.
 DeclaredType getDeclaredTypeByName(String className)
          Returns the DeclaredType for the given class name.
 AnnotationMirror getMirror(List<? extends AnnotationMirror> annotationMirrors, Class<? extends Annotation> annotationClazz)
          Returns that mirror from the given list of annotation mirrors that represents the annotation type specified by the given class.
 TypeMirror getMirrorForType(Class<?> clazz)
          Returns a TypeMirror for the given class.
 Set<TypeMirror> keepLowestTypePerHierarchy(Set<TypeMirror> types)
           Returns a set containing the "lowest" type per hierarchy contained in the input set.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AnnotationApiHelper

public AnnotationApiHelper(Elements elementUtils,
                           Types typeUtils)
Method Detail

filterByType

public List<AnnotationMirror> filterByType(List<? extends AnnotationMirror> annotationMirrors,
                                           TypeMirror annotationType)
Returns a list containing those annotation mirrors from the input list, which are of type annotationType. The input collection remains untouched.

Parameters:
annotationMirrors - A list of annotation mirrors.
annotationType - The type to be compared against.
Returns:
A list with those annotation mirrors from the input list, which are of type annotationType. May be empty but never null.

getMirror

public AnnotationMirror getMirror(List<? extends AnnotationMirror> annotationMirrors,
                                  Class<? extends Annotation> annotationClazz)
Returns that mirror from the given list of annotation mirrors that represents the annotation type specified by the given class.

Parameters:
annotationMirrors - A list of annotation mirrors.
annotationClazz - The class of the annotation of interest.
Returns:
The mirror from the given list that represents the specified annotation or null, if the given list doesn't contain such a mirror.

getMirrorForType

public TypeMirror getMirrorForType(Class<?> clazz)
Returns a TypeMirror for the given class.

Parameters:
clazz - The class of interest.
Returns:
A TypeMirror for the given class.

getDeclaredTypeByName

public DeclaredType getDeclaredTypeByName(String className)
Returns the DeclaredType for the given class name.

Parameters:
className - A fully qualified class name, e.g. "java.lang.String".
Returns:
A DeclaredType representing the type with the given name, or null, if no such type exists.

getAnnotationValue

public AnnotationValue getAnnotationValue(AnnotationMirror annotationMirror,
                                          String name)
Returns the annotation value of the given annotation mirror with the given name.

Parameters:
annotationMirror - An annotation mirror.
name - The name of the annotation value of interest.
Returns:
The annotation value with the given name or null, if one of the input values is null or if no value with the given name exists within the given annotation mirror.

getAnnotationArrayValue

public List<? extends AnnotationValue> getAnnotationArrayValue(AnnotationMirror annotationMirror,
                                                               String name)
Returns the given annotation mirror's array-typed annotation value with the given name.

Parameters:
annotationMirror - An annotation mirror.
name - The name of the annotation value of interest.
Returns:
The annotation value with the given name or an empty list, if no such value exists within the given annotation mirror or such a value exists but is not an array-typed one.

keepLowestTypePerHierarchy

public Set<TypeMirror> keepLowestTypePerHierarchy(Set<TypeMirror> types)

Returns a set containing the "lowest" type per hierarchy contained in the input set. The following examples shall demonstrate the behavior.

Parameters:
types - A set of type mirrors.
Returns:
A set with the lowest types per hierarchy or null, if the input set was null.


Copyright © 2007-2011 Red Hat Middleware, LLC. All Rights Reserved