Modifier and Type | Method and Description |
---|---|
static ExecutableElement |
asExecutable(Element element)
Returns the given
Element instance as ExecutableElement . |
static PackageElement |
asPackage(Element element)
Returns the given
Element instance as PackageElement . |
static TypeElement |
asType(Element element)
Returns the given
Element instance as TypeElement . |
static VariableElement |
asVariable(Element element)
Returns the given
Element instance as VariableElement . |
static com.google.common.base.Optional<AnnotationMirror> |
getAnnotationMirror(Element element,
Class<? extends Annotation> annotationClass)
Returns an
AnnotationMirror for the annotation of type annotationClass on
element , or Optional.absent() if no such annotation exists. |
static PackageElement |
getPackage(Element element)
An alternate implementation of
Elements.getPackageOf(javax.lang.model.element.Element) that does not require an
Elements instance. |
static boolean |
isAnnotationPresent(Element element,
Class<? extends Annotation> annotationClass)
Returns
true iff the given element has an AnnotationMirror whose
annotation type has the same canonical name
as that of annotationClass . |
public static PackageElement getPackage(Element element)
Elements.getPackageOf(javax.lang.model.element.Element)
that does not require an
Elements
instance.NullPointerException
- if element
is null
public static PackageElement asPackage(Element element)
Element
instance as PackageElement
.
This method is functionally equivalent to an instanceof
check and a cast, but should
always be used over that idiom as instructed in the documentation for Element
.
NullPointerException
- if element
is null
IllegalArgumentException
- if element
isn't a PackageElement
.public static TypeElement asType(Element element)
Element
instance as TypeElement
.
This method is functionally equivalent to an instanceof
check and a cast, but should
always be used over that idiom as instructed in the documentation for Element
.
NullPointerException
- if element
is null
IllegalArgumentException
- if element
isn't a TypeElement
.public static VariableElement asVariable(Element element)
Element
instance as VariableElement
.
This method is functionally equivalent to an instanceof
check and a cast, but should
always be used over that idiom as instructed in the documentation for Element
.
NullPointerException
- if element
is null
IllegalArgumentException
- if element
isn't a VariableElement
.public static ExecutableElement asExecutable(Element element)
Element
instance as ExecutableElement
.
This method is functionally equivalent to an instanceof
check and a cast, but should
always be used over that idiom as instructed in the documentation for Element
.
NullPointerException
- if element
is null
IllegalArgumentException
- if element
isn't a ExecutableElement
.public static boolean isAnnotationPresent(Element element, Class<? extends Annotation> annotationClass)
true
iff the given element has an AnnotationMirror
whose
annotation type has the same canonical name
as that of annotationClass
. This method is a safer alternative to calling
Element.getAnnotation(java.lang.Class<A>)
and checking for null
as it avoids any interaction with
annotation proxies.public static com.google.common.base.Optional<AnnotationMirror> getAnnotationMirror(Element element, Class<? extends Annotation> annotationClass)
AnnotationMirror
for the annotation of type annotationClass
on
element
, or Optional.absent()
if no such annotation exists. This method is a
safer alternative to calling Element.getAnnotation(java.lang.Class<A>)
as it avoids any interaction with
annotation proxies.Copyright © 2015 Google, Inc.. All rights reserved.