public final class ElementHelper extends Object
| Modifier and Type | Method and Description |
|---|---|
static Collection<AnnotationMirror> |
getAnnotations(Element element,
Class<? extends Annotation> groupedAnnotation,
Class<? extends Annotation> annotation)
Returns annotations that are associated with the element that match the
annotation parameter type. |
static TypeElement |
getClassAnnotationValue(Element element,
Class<? extends Annotation> annotation)
Retrieves the first attribute value from the annotation and assumes it's a
class type. |
static TypeElement |
getClassAnnotationValue(Element element,
Class<? extends Annotation> annotation,
String attributeName)
Retrieves the attribute value from the annotation and assumes it's a
class type. |
static List<TypeMirror> |
getClassArrayAnnotationValue(Element element,
Class<? extends Annotation> annotation,
String attributeName)
Retrieves the attribute value from the annotation and assumes it's an array
classes. |
static List<? extends TypeMirror> |
getTypeArguments(Element element)
Returns the type arguments for the element.
|
static List<? extends TypeMirror> |
getTypeArguments(TypeMirror type)
Returns the type arguments for the type.
|
static boolean |
hasConstructor(Types types,
Element element,
List<TypeMirror> args)
Checks whether or not a constructor matching the parameters exists.
|
static boolean |
isAnnotatedWith(AnnotatedConstruct annotatedConstruct,
Class<? extends Annotation> clazz)
Check if an element is annotated with the given annotation.
|
static TypeMirror |
toType(Elements elements,
Class<?> type)
Returns the type as a
TypeMirror. |
static TypeMirror |
toType(ProcessingEnvironment processingEnv,
Class<?> type)
Returns the type as a
TypeMirror. |
static TypeElement |
toTypeElement(Elements elements,
Class<?> type)
Returns the type as a
TypeMirror. |
static TypeElement |
toTypeElement(ProcessingEnvironment processingEnv,
Class<?> type)
Returns the type as a
TypeMirror. |
public static List<? extends TypeMirror> getTypeArguments(Element element)
DeclaredType or the element does not have any type arguments an empty list is returned.element - the element to get the type arguments forpublic static List<? extends TypeMirror> getTypeArguments(TypeMirror type)
DeclaredType or the type does not have any
type arguments an empty list is returned.type - the type to get the type arguments forpublic static boolean isAnnotatedWith(AnnotatedConstruct annotatedConstruct, Class<? extends Annotation> clazz)
annotatedConstruct - the object to look for the annotation on.clazz - the annotation classtrue if the element is annotated, otherwise falseIllegalArgumentException - if element parameter is nullpublic static TypeElement getClassAnnotationValue(Element element, Class<? extends Annotation> annotation)
class type.element - the element the annotation is onannotation - the annotation to get the value fromTypeElement representing the value for the first annotation attribute or null if no
attributes were foundpublic static TypeElement getClassAnnotationValue(Element element, Class<? extends Annotation> annotation, String attributeName)
class type.element - the element the annotation is onannotation - the annotation to get the value fromattributeName - the name of the attribute to retrieve the class value forTypeElement representing the value for the annotation attribute or null if the
attribute was not foundpublic static List<TypeMirror> getClassArrayAnnotationValue(Element element, Class<? extends Annotation> annotation, String attributeName)
classes.element - the element the annotation is onannotation - the annotation to get the value fromattributeName - the name of the attribute to retrieve the class value array forTypeMirror representing the value for the annotation attribute or an empty listpublic static Collection<AnnotationMirror> getAnnotations(Element element, Class<? extends Annotation> groupedAnnotation, Class<? extends Annotation> annotation)
annotation parameter type. If the
groupedAnnotation is not null then any repeated annotations that math the annotation
parameter type are also returned.
The groupedAnnotation must have a value attribute that includes an array of annotations that math the
annotation parameter type.
element - the element to search for annotationsgroupedAnnotation - the grouped annotation, e.g. collector for repeatable annotations, or null if not a repeatable annotationannotation - the annotation to search forpublic static boolean hasConstructor(Types types, Element element, List<TypeMirror> args)
types - the type utility used to compare the type argumentselement - the element that contains the constructorsargs - the arguments the constructor should matchtrue if a matching constructor was found otherwise falsepublic static TypeElement toTypeElement(ProcessingEnvironment processingEnv, Class<?> type)
TypeMirror.processingEnv - the processing environment to get the elements utilitytype - the type to create the TypeMirror forpublic static TypeElement toTypeElement(Elements elements, Class<?> type)
TypeMirror.elements - the element utility used to generate the tye typetype - the type to create the TypeMirror forpublic static TypeMirror toType(ProcessingEnvironment processingEnv, Class<?> type)
TypeMirror.processingEnv - the processing environment to get the elements utilitytype - the type to create the TypeMirror forpublic static TypeMirror toType(Elements elements, Class<?> type)
TypeMirror.elements - the element utility used to generate the tye typetype - the type to create the TypeMirror forCopyright © 2019 JBoss by Red Hat. All rights reserved.