Class AnnotationApiHelper
java.lang.Object
org.hibernate.validator.ap.internal.util.AnnotationApiHelper
A helper class providing some useful methods to work with types
from the JSR-269-API.
- Author:
- Gunnar Morling
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondetermineUnwrapMode
(AnnotationMirror annotationMirror) Checks the annotation's payload for unwrapping option (javax.validation.valueextraction.Unwrapping.Unwrap
,javax.validation.valueextraction.Unwrapping.Skip
) of constraint.filterByType
(List<? extends AnnotationMirror> annotationMirrors, TypeMirror annotationType) Returns a list containing those annotation mirrors from the input list, which are of typeannotationType
.List<? extends AnnotationValue>
getAnnotationArrayValue
(AnnotationMirror annotationMirror, String name) Returns the given annotation mirror's array-typed annotation value with the given name.getAnnotationValue
(AnnotationMirror annotationMirror, String name) Returns the annotation value of the given annotation mirror with the given name.getAnnotationValueOrDefault
(AnnotationMirror annotationMirror, String name) Returns the annotation value of the given annotation mirror with the given name or its default value if it was not specified.getDeclaredTypeByName
(String className) Returns theDeclaredType
for the given class name.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.getMirror
(List<? extends AnnotationMirror> annotationMirrors, String annotationTypeName) Returns that mirror from the given list of annotation mirrors that represents the annotation type specified by the given class.getMirrorForType
(Class<?> clazz) Returns a TypeMirror for the given class.boolean
isClass
(TypeMirror typeMirror) Test if the givenTypeMirror
represents a class or not.boolean
isInterface
(TypeMirror typeMirror) Test if the givenTypeMirror
represents an interface or not.keepLowestTypePerHierarchy
(Set<TypeMirror> types) Returns a set containing the "lowest" type per hierarchy contained in the input set.
-
Constructor Details
-
AnnotationApiHelper
-
-
Method Details
-
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 typeannotationType
. 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.
-
getMirror
public AnnotationMirror getMirror(List<? extends AnnotationMirror> annotationMirrors, String annotationTypeName) 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.annotationTypeName
- The FQN 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
Returns a TypeMirror for the given class.- Parameters:
clazz
- The class of interest.- Returns:
- A TypeMirror for the given class.
-
getDeclaredTypeByName
Returns theDeclaredType
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
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.
-
getAnnotationValueOrDefault
Returns the annotation value of the given annotation mirror with the given name or its default value if it was not specified.- Parameters:
annotationMirror
- An annotation mirror.name
- The name of the annotation value of interest.- Returns:
- The annotation value with the given name or it's default value 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
Returns a set containing the "lowest" type per hierarchy contained in the input set. The following examples shall demonstrate the behavior.
-
Input:
String
; Output:String
-
Input:
Object
,String
; Output:String
-
Input:
Object
,Collection
,List
; Output:List
-
Input:
Collection
,Set
,List
; Output:List
,Set
- Parameters:
types
- A set of type mirrors.- Returns:
- A set with the lowest types per hierarchy or null, if the input set was null.
-
Input:
-
isInterface
Test if the givenTypeMirror
represents an interface or not. -
isClass
Test if the givenTypeMirror
represents a class or not. -
determineUnwrapMode
Checks the annotation's payload for unwrapping option (javax.validation.valueextraction.Unwrapping.Unwrap
,javax.validation.valueextraction.Unwrapping.Skip
) of constraint.- Parameters:
annotationMirror
- constraint annotation mirror under check- Returns:
- unwrapping option, if one is present in the annotation payload,
AnnotationApiHelper.UnwrapMode.NONE
otherwise
-