Interface APHelper
- All Superinterfaces:
Messager
,ProcessingEnvironment
- All Known Implementing Classes:
APBase
- Author:
- Thomas Thrien (thomas.thrien@tquadrat.org)
- Version:
- $Id: APHelper.java 1061 2023-09-25 16:32:43Z tquadrat $
- Since:
- 0.1.0
- UML Diagram
-
UML Diagram for "org.tquadrat.foundation.ap.APHelper"
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Returns the flag that indicates whether some debug information should be emitted to the generated code.default Optional
<? extends AnnotationMirror> getAnnotationMirror
(Element element, Class<? extends Annotation> annotationClass) Retrieves theAnnotationMirror
for the given annotation from the givenElement
instance.default Optional
<? extends AnnotationValue> getAnnotationValue
(AnnotationMirror annotationMirror) Retrieves the annotation value from the given annotation mirror.default Optional
<? extends AnnotationValue> getAnnotationValue
(AnnotationMirror annotationMirror, String name) Retrieves the annotation value with the given name from the given annotation mirror.default Optional
<TypeMirror> getTypeMirrorFromAnnotationValue
(Element element, Class<? extends Annotation> annotationClass) Retrieves aTypeMirror
instance from an annotation.default Optional
<TypeMirror> getTypeMirrorFromAnnotationValue
(Element element, Class<? extends Annotation> annotationClass, String attributeName) Retrieves aTypeMirror
instance from an annotation.default <A extends Annotation>
booleanhasAnnotation
(Element element, Class<A> annotationType) Checks whether the given element has the given annotation.boolean
isEnumType
(TypeMirror type) Determines whether the given instance ofTypeMirror
is for anEnum
type.default void
printMessage
(Diagnostic.Kind kind, CharSequence msg) default void
printMessage
(Diagnostic.Kind kind, CharSequence msg, Element element) default void
printMessage
(Diagnostic.Kind kind, CharSequence msg, Element element, AnnotationMirror annotation) default void
printMessage
(Diagnostic.Kind kind, CharSequence msg, Element element, AnnotationMirror annotation, AnnotationValue value) Retrieves the names of a method's arguments.List
<? extends TypeMirror> Retrieves the generic types for the given type.default void
retrieveInterfaces
(TypeElement typeElement, Set<? super TypeElement> interfaces) Retrieves the interfaces are that implemented or extended by the given type element.Methods inherited from interface javax.annotation.processing.Messager
printError, printError, printNote, printNote, printWarning, printWarning
Methods inherited from interface javax.annotation.processing.ProcessingEnvironment
getElementUtils, getFiler, getLocale, getMessager, getOptions, getSourceVersion, getTypeUtils, isPreviewEnabled
-
Method Details
-
addDebugOutput
boolean addDebugOutput()Returns the flag that indicates whether some debug information should be emitted to the generated code.
The value is controlled by the value of the annotation processor option "org.tquadrat.foundation.ap.addDebugOutput".
- Returns:
true
if the debug information should be added,false
if not.
-
getAnnotationMirror
default Optional<? extends AnnotationMirror> getAnnotationMirror(Element element, Class<? extends Annotation> annotationClass) Retrieves theAnnotationMirror
for the given annotation from the givenElement
instance. Only declared annotations are considered, not the inherited ones.- Parameters:
element
- The element.annotationClass
- The annotation to look for.- Returns:
- An instance of
Optional
that holds the foundAnnotationMirror
instance. - See Also:
-
getAnnotationValue
Retrieves the annotation value from the given annotation mirror.- Parameters:
annotationMirror
- The annotation mirror.- Returns:
- An instance of
Optional
that holds the found annotation value.
-
getAnnotationValue
default Optional<? extends AnnotationValue> getAnnotationValue(AnnotationMirror annotationMirror, String name) Retrieves the annotation value with the given name from the given annotation mirror.- Parameters:
annotationMirror
- The annotation mirror.name
- The name of the desired value.- Returns:
- An instance of
Optional
that holds the found annotation value.
-
getTypeMirrorFromAnnotationValue
default Optional<TypeMirror> getTypeMirrorFromAnnotationValue(Element element, Class<? extends Annotation> annotationClass) Retrieves a
TypeMirror
instance from an annotation.In case an annotation defines a
Class<?>
attribute, the value for that attribute is eithernull
or something strange, but never an instance ofClass<?>
. So we need some special code to get something useful from the annotation.This implementations assumes the default name "
value
" for the attribute.- Parameters:
element
- The annotated element.annotationClass
- The type of the annotation.- Returns:
- An instance of
Optional
that holds theTypeMirror
instance. - Throws:
NoSuchElementException
- The given element is not annotated with an annotation of the given type.
-
getTypeMirrorFromAnnotationValue
default Optional<TypeMirror> getTypeMirrorFromAnnotationValue(Element element, Class<? extends Annotation> annotationClass, String attributeName) Retrieves a
TypeMirror
instance from an annotation.In case an annotation defines a
Class<?>
attribute, the value for that attribute is eithernull
or something strange, but never an instance ofClass<?>
. So we need some special code to get something useful from the annotation.- Parameters:
element
- The annotated element.annotationClass
- The type of the annotation.attributeName
- The name of the attribute that holds the class.- Returns:
- An instance of
Optional
that holds theTypeMirror
instance. - Throws:
NoSuchElementException
- The given element is not annotated with an annotation of the given type.
-
hasAnnotation
Checks whether the given element has the given annotation.- Note:
-
- If the retention for the given annotation is not it could have been removed from the element in an earlier compile run.
- Type Parameters:
A
- The type of the annotation.- Parameters:
element
- The element to inspect.annotationType
- The type of the annotation to look for.- Returns:
true
if the element is annotated with the given annotation,false
if not.- See Also:
-
isEnumType
Determines whether the given instance ofTypeMirror
is for anEnum
type.- Parameters:
type
- The type to check.- Returns:
true
if the given type is anEnum
type,false
otherwise.
-
printMessage
- Specified by:
printMessage
in interfaceMessager
-
printMessage
- Specified by:
printMessage
in interfaceMessager
-
printMessage
default void printMessage(Diagnostic.Kind kind, CharSequence msg, Element element, AnnotationMirror annotation) - Specified by:
printMessage
in interfaceMessager
-
printMessage
default void printMessage(Diagnostic.Kind kind, CharSequence msg, Element element, AnnotationMirror annotation, AnnotationValue value) - Specified by:
printMessage
in interfaceMessager
-
retrieveArgumentNames
Retrieves the names of a method's arguments.
This method will return the names of the arguments as defined only if the compiler flag
-parameters
is set; otherwise, the arguments are just counted (arg0
,arg1
,arg2
, …).- Parameters:
method
- The method.- Returns:
- The names of the arguments.
-
retrieveGenericTypes
Retrieves the generic types for the given type.
- Parameters:
type
- TheTypeMirror
instance to inspect.- Returns:
- The type arguments the given type was defined with; will be the empty list if that type was not generic.
-
retrieveInterfaces
Retrieves the interfaces are that implemented or extended by the given type element.- Parameters:
typeElement
- The type element to inspect.interfaces
- The already retrieved interfaces.
-