Package org.jboss.logging.processor.util
Class ElementHelper
java.lang.Object
org.jboss.logging.processor.util.ElementHelper
An utility class to work with element.
- Author:
- Kevin Pollet - SERLI - (kevin.pollet@serli.com), James R. Perkins
-
Method Summary
Modifier and TypeMethodDescriptionstatic Collection<AnnotationMirror> getAnnotations(Element element, Class<? extends Annotation> groupedAnnotation, Class<? extends Annotation> annotation) Returns annotations that are associated with the element that match theannotationparameter type.static TypeElementgetClassAnnotationValue(Element element, Class<? extends Annotation> annotation) Retrieves the first attribute value from the annotation and assumes it's aclasstype.static TypeElementgetClassAnnotationValue(Element element, Class<? extends Annotation> annotation, String attributeName) Retrieves the attribute value from the annotation and assumes it's aclasstype.static List<TypeMirror> getClassArrayAnnotationValue(Element element, Class<? extends Annotation> annotation, String attributeName) Retrieves the attribute value from the annotation and assumes it's an arrayclasses.static Optional<TypeMirror> getTypeArgument(Element element) Returns a single type argument for the element.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 booleanhasConstructor(Types types, Element element, List<TypeMirror> args) Checks whether or not a constructor matching the parameters exists.static booleanisAnnotatedWith(AnnotatedConstruct annotatedConstruct, Class<? extends Annotation> clazz) Check if an element is annotated with the given annotation.static TypeMirrortoType(ProcessingEnvironment processingEnv, Class<?> type) Returns the type as aTypeMirror.static TypeMirrorReturns the type as aTypeMirror.static TypeElementtoTypeElement(ProcessingEnvironment processingEnv, Class<?> type) Returns the type as aTypeMirror.static TypeElementtoTypeElement(Elements elements, Class<?> type) Returns the type as aTypeMirror.
-
Method Details
-
getTypeArgument
Returns a single type argument for the element. If more than one type is found only the first one is returned.- Parameters:
element- the element to get the type arguments for- Returns:
- an optional type argument
-
getTypeArguments
Returns the type arguments for the element. If the elements type is not aDeclaredTypeor the element does not have any type arguments an empty list is returned.- Parameters:
element- the element to get the type arguments for- Returns:
- the type arguments or an empty list
-
getTypeArguments
Returns the type arguments for the type. If the type is not aDeclaredTypeor the type does not have any type arguments an empty list is returned.- Parameters:
type- the type to get the type arguments for- Returns:
- the type arguments or an empty list
-
isAnnotatedWith
public static boolean isAnnotatedWith(AnnotatedConstruct annotatedConstruct, Class<? extends Annotation> clazz) Check if an element is annotated with the given annotation.- Parameters:
annotatedConstruct- the object to look for the annotation on.clazz- the annotation class- Returns:
trueif the element is annotated, otherwisefalse- Throws:
IllegalArgumentException- if element parameter is null
-
getClassAnnotationValue
public static TypeElement getClassAnnotationValue(Element element, Class<? extends Annotation> annotation) Retrieves the first attribute value from the annotation and assumes it's aclasstype.- Parameters:
element- the element the annotation is onannotation- the annotation to get the value from- Returns:
- a
TypeElementrepresenting the value for the first annotation attribute ornullif no attributes were found
-
getClassAnnotationValue
public static TypeElement getClassAnnotationValue(Element element, Class<? extends Annotation> annotation, String attributeName) Retrieves the attribute value from the annotation and assumes it's aclasstype.- Parameters:
element- the element the annotation is onannotation- the annotation to get the value fromattributeName- the name of the attribute to retrieve the class value for- Returns:
- a
TypeElementrepresenting the value for the annotation attribute ornullif the attribute was not found
-
getClassArrayAnnotationValue
public static List<TypeMirror> getClassArrayAnnotationValue(Element element, Class<? extends Annotation> annotation, String attributeName) Retrieves the attribute value from the annotation and assumes it's an arrayclasses.- Parameters:
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 for- Returns:
- a list of
TypeMirrorrepresenting the value for the annotation attribute or an empty list
-
getAnnotations
public static Collection<AnnotationMirror> getAnnotations(Element element, Class<? extends Annotation> groupedAnnotation, Class<? extends Annotation> annotation) Returns annotations that are associated with the element that match theannotationparameter type. If thegroupedAnnotationis notnullthen any repeated annotations that math theannotationparameter type are also returned.The
groupedAnnotationmust have a value attribute that includes an array of annotations that math theannotationparameter type.- Parameters:
element- the element to search for annotationsgroupedAnnotation- the grouped annotation, e.g. collector for repeatable annotations, ornullif not a repeatable annotationannotation- the annotation to search for- Returns:
- a collection matched annotations
-
hasConstructor
Checks whether or not a constructor matching the parameters exists.- Parameters:
types- the type utility used to compare the type argumentselement- the element that contains the constructorsargs- the arguments the constructor should match- Returns:
trueif a matching constructor was found otherwisefalse
-
toTypeElement
Returns the type as aTypeMirror.- Parameters:
processingEnv- the processing environment to get the elements utilitytype- the type to create theTypeMirrorfor- Returns:
- the type
-
toTypeElement
Returns the type as aTypeMirror.- Parameters:
elements- the element utility used to generate the tye typetype- the type to create theTypeMirrorfor- Returns:
- the type
-
toType
Returns the type as aTypeMirror.- Parameters:
processingEnv- the processing environment to get the elements utilitytype- the type to create theTypeMirrorfor- Returns:
- the type
-
toType
Returns the type as aTypeMirror.- Parameters:
elements- the element utility used to generate the tye typetype- the type to create theTypeMirrorfor- Returns:
- the type
-