Class APContext
java.lang.Object
io.avaje.spi.internal.APContext
Utiliy Class that stores the
ProcessingEnvironment
and provides various helper methods-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic TypeElement
Returns the element corresponding to a type.The type may be a DeclaredType or TypeVariable.Returns null if the type is not one with a corresponding element.static void
clear()
Clears the ThreadLocal containing theProcessingEnvironment
.static JavaFileObject
createSourceFile
(CharSequence name, Element... originatingElements) Create a file writer for the given class name.static Elements
elements()
Get currentElements
from theProcessingEnvironment
elementsAnnotatedWith
(RoundEnvironment round, String annotationFQN) Returns the elements annotated with the given annotation interface.static Filer
filer()
Get currentFiler
from theProcessingEnvironment
static Path
getBuildResource
(String path) static BufferedReader
Gets aBufferedReader
for the project'smodule-info.java
source file.Returns processor-specific option passed to the annotation processing tool.static ModuleElement
Retrieve the project'sModuleElement
.static void
init
(APContext.Ctx context, int jdkVersion, boolean preview) Initialize the ThreadLocal containing theProcessingEnvironment
.static void
init
(ProcessingEnvironment processingEnv) Initialize the ThreadLocal containing the Processing Enviroment. this typically should be called during the init phase of processing.static boolean
isAssignable
(String type, String superType) Determine whether the first type can be assigned to the secondstatic boolean
isAssignable
(TypeElement type, String superType) Determine whether the first type can be assigned to the secondstatic boolean
Return true if the compiler is creating test classes.static int
Returns the source version that any generated source and class files should conform tostatic void
Prints an error.static void
Prints an error at the location of the element.static void
Prints a note at the location of the element.static void
Prints a note.static void
Prints a warning.static void
Prints an warning at the location of the element.static Messager
messager()
Get currentMessager
from theProcessingEnvironment
static Optional
<ModuleInfoReader> Retrieve the root module-info reader if it can be readstatic boolean
Returns whether--preview-enabled
has been added to compiler flags.static ProcessingEnvironment
Get currentProcessingEnvironment
static void
setProjectModuleElement
(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) Discover theModuleElement
for the project being processed and set in the context.static TypeElement
typeElement
(String name) Returns a type element given its canonical name.static Types
types()
Get currentTypes
from theProcessingEnvironment
-
Method Details
-
init
Initialize the ThreadLocal containing the Processing Enviroment. this typically should be called during the init phase of processing. Be sure to run the clear method at the last round of processing- Parameters:
processingEnv
- the current annotation processing enviroment
-
init
Initialize the ThreadLocal containing theProcessingEnvironment
. Be sure to run the clear method at the last round of processing- Parameters:
context
- the current annotation processing enviromentjdkVersion
- the JDK version numberpreview
- whether preview features are enabled
-
clear
public static void clear()Clears the ThreadLocal containing theProcessingEnvironment
. -
jdkVersion
public static int jdkVersion()Returns the source version that any generated source and class files should conform to- Returns:
- the source version as an int
-
previewEnabled
public static boolean previewEnabled()Returns whether--preview-enabled
has been added to compiler flags.- Returns:
- true if preview features are enabled
-
logError
-
logError
-
logWarn
-
logWarn
-
logNote
-
logNote
-
elementsAnnotatedWith
public static Set<? extends Element> elementsAnnotatedWith(RoundEnvironment round, String annotationFQN) Returns the elements annotated with the given annotation interface.- Parameters:
round
- RoundEnviroment to extract the elementsannotationFQN
- the fqn of the annotation- Returns:
- the elements annotated with the given annotation interface,or an empty set if there are none
-
createSourceFile
public static JavaFileObject createSourceFile(CharSequence name, Element... originatingElements) throws IOException Create a file writer for the given class name.- Parameters:
name
- canonical (fully qualified) name of the principal class or interface being declared in this file or a package name followed by".package-info"
for a package information fileoriginatingElements
- class, interface, package, or module elements causally associated with the creation of this file, may be elided ornull
- Returns:
- a JavaFileObject to write the new source file
- Throws:
IOException
-
typeElement
Returns a type element given its canonical name.- Parameters:
name
- the canonical name- Returns:
- the named type element, or null if no type element can be uniquely determined
-
asTypeElement
Returns the element corresponding to a type.The type may be a DeclaredType or TypeVariable.Returns null if the type is not one with a corresponding element.- Parameters:
t
- the type to map to an element- Returns:
- the element corresponding to the given type
-
processingEnv
Get currentProcessingEnvironment
- Returns:
- the enviroment
-
filer
-
elements
Get currentElements
from theProcessingEnvironment
- Returns:
- the filer
-
messager
Get currentMessager
from theProcessingEnvironment
- Returns:
- the messager
-
types
-
getOption
-
isAssignable
-
isAssignable
Determine whether the first type can be assigned to the second- Parameters:
type
- type to checksuperType
- the type that should be assignable to.- Returns:
- true if type can be assinged to supertype
-
setProjectModuleElement
public static void setProjectModuleElement(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) Discover theModuleElement
for the project being processed and set in the context.- Parameters:
annotations
- the annotation interfaces requested to be processedroundEnv
- environment for information about the current and prior round
-
getProjectModuleElement
Retrieve the project'sModuleElement
.setProjectModuleElement
must be called before this.- Returns:
- the
ModuleElement
associated with the current project
-
moduleInfoReader
Retrieve the root module-info reader if it can be read -
getModuleInfoReader
Gets aBufferedReader
for the project'smodule-info.java
source file.Calling
ModuleElement
'sgetDirectives()
method has a chance of making compilation fail in certain situations. Therefore, manually parsingmodule-info.java
seems to be the safest way to get module information.- Returns:
- Throws:
IOException
- if unable to read the module-info
-
getBuildResource
- Parameters:
path
- the relative path of the file in the target/build folder- Returns:
- the file object
- Throws:
IOException
- if unable to retrieve the file
-
isTestCompilation
public static boolean isTestCompilation()Return true if the compiler is creating test classes.- Returns:
- Whether the current apt compilation is for test-compile.
-