Package org.tquadrat.foundation.ap
Class APBase
java.lang.Object
org.tquadrat.foundation.ap.APBase
- All Implemented Interfaces:
Messager
,ProcessingEnvironment
,Processor
,APHelper
@ClassVersion(sourceVersion="$Id: APBase.java 1061 2023-09-25 16:32:43Z tquadrat $")
@API(status=STABLE,
since="0.1.0")
public abstract class APBase
extends Object
implements Processor, APHelper
The abstract base class for annotation processors for the Foundation
Library.
- Author:
- Thomas Thrien (thomas.thrien@tquadrat.org)
- Version:
- $Id: APBase.java 1061 2023-09-25 16:32:43Z tquadrat $
- Since:
- 0.1.0
- UML Diagram
-
UML Diagram for "org.tquadrat.foundation.ap.APBase"
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
The name of the annotation processor option that enables the emission of some debug information into the generated code: "org.tquadrat.foundation.ap.addDebugOutput".private boolean
The flag that indicates whether some debug information should be emitted to the generated code.private Elements
The implementation of some utility methods for operating on elements.private ProcessingEnvironment
The processing environment.private Filer
The filer that is used to create new source, class, or auxiliary files.private boolean
A flag that indicates whether Maven is active.private Messager
TheMessager
that is used to report errors, warnings, and other notices.The options for this annotation processor.private Types
The implementation of some utility methods for operating on types.static final String
The name of the annotation processor option for the currently active Maven goal: "org.tquadrat.foundation.ap.maven.goal".static final String
Message: "%s: Only fields may be annotated with \'%s\'".static final String
Message: "Only allowed for fields".static final String
The message that indicates the illegal use of an annotation: "%s: Illegal use of annotation \'%s\'".static final String
The message that indicates that more than one element is annotated with the given annotation: "%1$s: Multiple elements are annotated with \'%2$s\'".static final String
The message that indicates that more than one field is annotated with the given annotation: "%1$s: Multiple fields are annotated with \'%2$s\'".static final String
The message that indicates that a String constant is required: "\'%s\' needs to be a String constant".static final String
The name for sub-package that holds the generated configuration bean classes: "generated". -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal boolean
Returns the flag that indicates whether some debug information should be emitted to the generated code.private final String
Adds the name of the annotation processor to the given message.final Iterable
<? extends Completion> getCompletions
(Element element, AnnotationMirror annotation, ExecutableElement member, String userText) final Elements
final Filer
getFiler()
final Locale
final Messager
Retrieves the option with the given name from the annotation processors startup options.final SourceVersion
protected abstract Collection
<Class<? extends Annotation>> Returns the classes for the supported annotations.final SourceVersion
final Types
final void
init
(ProcessingEnvironment processingEnv) final boolean
isEnumType
(TypeMirror type) Determines whether the given instance ofTypeMirror
is for anEnum
type.final void
printMessage
(Diagnostic.Kind kind, CharSequence msg) final void
printMessage
(Diagnostic.Kind kind, CharSequence msg, Element element) final void
printMessage
(Diagnostic.Kind kind, CharSequence msg, Element element, AnnotationMirror annotation) final void
printMessage
(Diagnostic.Kind kind, CharSequence msg, Element element, AnnotationMirror annotation, AnnotationValue value) abstract boolean
process
(Set<? extends TypeElement> annotations, RoundEnvironment roundEnvironment) protected final Optional
<VariableElement> retrieveAnnotatedField
(RoundEnvironment roundEnvironment, Class<? extends Annotation> annotationClass) Retrieves the field that is annotated with the given annotation.Retrieves the names of a method's arguments.Retrieves the generic types for the given type.final void
retrieveInterfaces
(TypeElement typeElement, Set<? super TypeElement> interfaces) Retrieves the interfaces are that implemented or extended by the given type element.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.tquadrat.foundation.ap.APHelper
getAnnotationMirror, getAnnotationValue, getAnnotationValue, getTypeMirrorFromAnnotationValue, getTypeMirrorFromAnnotationValue, hasAnnotation
Methods inherited from interface javax.annotation.processing.Messager
printError, printError, printNote, printNote, printWarning, printWarning
Methods inherited from interface javax.annotation.processing.ProcessingEnvironment
isPreviewEnabled
-
Field Details
-
PACKAGE_NAME
The name for sub-package that holds the generated configuration bean classes: "generated".- See Also:
-
ADD_DEBUG_OUTPUT
The name of the annotation processor option that enables the emission of some debug information into the generated code: "org.tquadrat.foundation.ap.addDebugOutput".- See Also:
-
MAVEN_GOAL
The name of the annotation processor option for the currently active Maven goal: "org.tquadrat.foundation.ap.maven.goal".- See Also:
-
MSG_AnnotationOnlyForFields
Message: "%s: Only fields may be annotated with \'%s\'".- See Also:
-
MSG_FieldsOnly
Message: "Only allowed for fields".- See Also:
-
MSG_IllegalAnnotationUse
The message that indicates the illegal use of an annotation: "%s: Illegal use of annotation \'%s\'".- See Also:
-
MSG_MultipleElements
The message that indicates that more than one element is annotated with the given annotation: "%1$s: Multiple elements are annotated with \'%2$s\'".- See Also:
-
MSG_MultipleFields
The message that indicates that more than one field is annotated with the given annotation: "%1$s: Multiple fields are annotated with \'%2$s\'".- See Also:
-
MSG_StringConstantRequired
The message that indicates that a String constant is required: "\'%s\' needs to be a String constant".- See Also:
-
m_AddDebugOutput
The flag that indicates whether some debug information should be emitted to the generated code. -
m_ElementUtils
The implementation of some utility methods for operating on elements. -
m_Environment
The processing environment. -
m_Filer
The filer that is used to create new source, class, or auxiliary files. -
m_IsMavenActive
A flag that indicates whether Maven is active. This is guessed by the existence of the option"org.tquadrat.foundation.ap.maven.goal"
. -
m_Messager
TheMessager
that is used to report errors, warnings, and other notices. -
m_Options
The options for this annotation processor. -
m_TypeUtils
The implementation of some utility methods for operating on types.
-
-
Constructor Details
-
APBase
protected APBase()Creates a newAPBase
instance.
-
-
Method Details
-
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".
- Specified by:
addDebugOutput
in interfaceAPHelper
- Returns:
true
if the debug information should be added,false
if not.
-
composeMessage
Adds the name of the annotation processor to the given message.- Parameters:
msg
- The raw message.- Returns:
- The enhanced message.
-
getCompletions
public final Iterable<? extends Completion> getCompletions(Element element, AnnotationMirror annotation, ExecutableElement member, String userText) - Specified by:
getCompletions
in interfaceProcessor
-
getElementUtils
- Specified by:
getElementUtils
in interfaceProcessingEnvironment
-
getFiler
- Specified by:
getFiler
in interfaceProcessingEnvironment
-
getLocale
- Specified by:
getLocale
in interfaceProcessingEnvironment
-
getMessager
- Specified by:
getMessager
in interfaceProcessingEnvironment
-
getOption
Retrieves the option with the given name from the annotation processors startup options.- Parameters:
option
- The name of the option.- Returns:
- An instance of
Optional
that holds the option value.
-
getOptions
- Specified by:
getOptions
in interfaceProcessingEnvironment
-
getSourceVersion
- Specified by:
getSourceVersion
in interfaceProcessingEnvironment
-
getSupportedAnnotationClasses
Returns the classes for the supported annotations.- Returns:
- The supported annotations.
-
getSupportedAnnotationTypes
- Specified by:
getSupportedAnnotationTypes
in interfaceProcessor
-
getSupportedOptions
- Specified by:
getSupportedOptions
in interfaceProcessor
-
getSupportedSourceVersion
- Specified by:
getSupportedSourceVersion
in interfaceProcessor
-
getTypeUtils
- Specified by:
getTypeUtils
in interfaceProcessingEnvironment
-
isEnumType
Determines whether the given instance ofTypeMirror
is for anEnum
type.- Specified by:
isEnumType
in interfaceAPHelper
- Parameters:
type
- The type to check.- Returns:
true
if the given type is anEnum
type,false
otherwise.
-
init
-
printMessage
- Specified by:
printMessage
in interfaceAPHelper
- Specified by:
printMessage
in interfaceMessager
-
printMessage
- Specified by:
printMessage
in interfaceAPHelper
- Specified by:
printMessage
in interfaceMessager
-
printMessage
public final void printMessage(Diagnostic.Kind kind, CharSequence msg, Element element, AnnotationMirror annotation) - Specified by:
printMessage
in interfaceAPHelper
- Specified by:
printMessage
in interfaceMessager
-
printMessage
public final void printMessage(Diagnostic.Kind kind, CharSequence msg, Element element, AnnotationMirror annotation, AnnotationValue value) - Specified by:
printMessage
in interfaceAPHelper
- Specified by:
printMessage
in interfaceMessager
-
process
public abstract boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnvironment) -
retrieveAnnotatedField
protected final Optional<VariableElement> retrieveAnnotatedField(RoundEnvironment roundEnvironment, Class<? extends Annotation> annotationClass) throws IllegalAnnotationError Retrieves the field that is annotated with the given annotation. The expectation is that there is just one
- Parameters:
roundEnvironment
- The environment for information about the current and prior round as set toprocess(Set, RoundEnvironment)
.annotationClass
- The class of the annotation.- Returns:
- An instance of
Optional
that holds the field. - Throws:
IllegalAnnotationError
- The annotation is invalid.CodeGenerationError
- Multiple fields are annotated with the given annotation.
-
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
, …).- Specified by:
retrieveArgumentNames
in interfaceAPHelper
- Parameters:
method
- The method.- Returns:
- The names of the arguments.
-
retrieveGenericTypes
Retrieves the generic types for the given type.
- Specified by:
retrieveGenericTypes
in interfaceAPHelper
- 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.- Specified by:
retrieveInterfaces
in interfaceAPHelper
- Parameters:
typeElement
- The type element to inspect.interfaces
- The already retrieved interfaces.
-