public abstract class AnnotationUtils extends Object
Modifier and Type | Method and Description |
---|---|
static AnnotationMirror |
findAnnotationMirror(Element elem,
CharSequence annClassName)
Find an annotation mirror of an element, given the annotation's fully qualified class name.
|
static AnnotationMirror |
findAnnotationMirror(Element elem,
Class<? extends Annotation> annClass)
Find an annotation mirror of an element, given the annotation's
Class object. |
static AnnotationValue |
findAnnotationValue(AnnotationMirror am,
CharSequence valueName)
Get an element value from an annotation mirror.
|
static <A extends Annotation> |
getAncestorAnnotation(Element elem,
Class<A> annotationType)
Checks if the element or one of its ancestors (i.e., reflexive-transitively enclosing elements)
is annotated with the given annotation type, and if so, returns the annotation object.
|
static Map<String,AnnotationValue> |
getAnnotationValues(AnnotationMirror am) |
static Map<String,AnnotationValue> |
getAnnotationValues(Element element,
Class<? extends Annotation> annotationClazz) |
static <A extends Annotation> |
getEnclosingAnnotation(Element elem,
Class<A> annotationType,
boolean onlyDirect) |
static <A extends Annotation> |
getParentAnnotation(Element elem,
Class<A> annotationType)
Checks if the direct parent (i.e., enclosing element) of this element is annotated
with the given annotation type, and if so, returns the annotation object.
|
static boolean |
isAncestorAnnotated(Element elem,
Class<? extends Annotation>... expectedAnnotations) |
static boolean |
isAnnotated(Element elem,
Class<? extends Annotation>... expectedAnnotations) |
static boolean |
isEnclosingAnnotated(Element elem,
boolean onlyDirect,
Class<? extends Annotation>... expectedAnnotations) |
static boolean |
isParentAnnotated(Element elem,
Class<? extends Annotation>... expectedAnnotations) |
public static <A extends Annotation> A getParentAnnotation(Element elem, Class<A> annotationType)
This method is safe in the sense that it won't result in a NullPointerException
when the specified element does not have a parent, or a null element reference
is specified.
elem
- the elementannotationType
- the annotation type to check forpublic static <A extends Annotation> A getAncestorAnnotation(Element elem, Class<A> annotationType)
This method is safe in the sense that it won't result in a NullPointerException
when the specified element does not have a parent, or a null element reference
is specified.
elem
- the elementannotationType
- the annotation type to check forpublic static <A extends Annotation> A getEnclosingAnnotation(Element elem, Class<A> annotationType, boolean onlyDirect)
@SafeVarargs public static boolean isAnnotated(Element elem, Class<? extends Annotation>... expectedAnnotations)
@SafeVarargs public static boolean isParentAnnotated(Element elem, Class<? extends Annotation>... expectedAnnotations)
@SafeVarargs public static boolean isAncestorAnnotated(Element elem, Class<? extends Annotation>... expectedAnnotations)
@SafeVarargs public static boolean isEnclosingAnnotated(Element elem, boolean onlyDirect, Class<? extends Annotation>... expectedAnnotations)
public static AnnotationMirror findAnnotationMirror(Element elem, CharSequence annClassName)
elem
- the elementannClassName
- the fully qualified class name of the annotationpublic static AnnotationMirror findAnnotationMirror(Element elem, Class<? extends Annotation> annClass)
Class
object.elem
- the elementannClass
- the annotation's Class
objectpublic static AnnotationValue findAnnotationValue(AnnotationMirror am, CharSequence valueName)
Note: Annotation mirrors usually do not contain default values, only those that were set explicitly.
am
- the annotation mirrorvalueName
- the name of the valuepublic static Map<String,AnnotationValue> getAnnotationValues(AnnotationMirror am)
public static Map<String,AnnotationValue> getAnnotationValues(Element element, Class<? extends Annotation> annotationClazz)
Copyright © 2013–2014. All rights reserved.