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 TypeElementReturns 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 voidclear()Clears the ThreadLocal containing theProcessingEnvironment.static JavaFileObjectcreateSourceFile(CharSequence name, Element... originatingElements) Create a file writer for the given class name.static Elementselements()Get currentElementsfrom theProcessingEnvironmentelementsAnnotatedWith(RoundEnvironment round, String annotationFQN) Returns the elements annotated with the given annotation interface.static Filerfiler()Get currentFilerfrom theProcessingEnvironmentstatic BufferedReaderGets aBufferedReaderfor the project'smodule-info.javasource file.static ModuleElementRetrieve the project'sModuleElement.static voidinit(APContext.Ctx context, int jdkVersion, boolean preview) Initialize the ThreadLocal containing theProcessingEnvironment.static voidinit(ProcessingEnvironment processingEnv) Initialize the ThreadLocal containing the Processing Enviroment.static booleanisAssignable(String type, String superType) Determine whether the first type can be assigned to the secondstatic booleanisAssignable(TypeElement type, String superType) Determine whether the first type can be assigned to the secondstatic intReturns the source version that any generated source and class files should conform tostatic voidPrints an error.static voidPrints an error at the location of the element.static voidPrints a note at the location of the element.static voidPrints a note.static voidPrints a warning.static voidPrints an warning at the location of the element.static Messagermessager()Get currentMessagerfrom theProcessingEnvironmentstatic booleanReturns whether--preview-enabledhas been added to compiler flags.static ProcessingEnvironmentGet currentProcessingEnvironmentstatic voidsetProjectModuleElement(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) Discover theModuleElementfor the project being processed and set in the context.static TypeElementtypeElement(String name) Returns a type element given its canonical name.static Typestypes()Get currentTypesfrom 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-enabledhas been added to compiler flags.- Returns:
- true if preview features are enabled
-
logError
Prints an error at the location of the element.- Parameters:
e- the element to use as a position hintmsg- the message, or an empty string if noneargs-String#formatarguments
-
logError
Prints an error.- Parameters:
msg- the message, or an empty string if noneargs-String#formatarguments
-
logWarn
Prints an warning at the location of the element.- Parameters:
e- the element to use as a position hintmsg- the message, or an empty string if noneargs-String#formatarguments
-
logWarn
Prints a warning.- Parameters:
msg- the message, or an empty string if noneargs-String#formatarguments
-
logNote
Prints a note.- Parameters:
msg- the message, or an empty string if noneargs-String#formatarguments
-
logNote
Prints a note at the location of the element.- Parameters:
msg- the message, or an empty string if noneargs-String#formatargumentse- the element to use as a position hint
-
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
Get currentFilerfrom theProcessingEnvironment- Returns:
- the filer
-
elements
Get currentElementsfrom theProcessingEnvironment- Returns:
- the filer
-
messager
Get currentMessagerfrom theProcessingEnvironment- Returns:
- the messager
-
types
Get currentTypesfrom theProcessingEnvironment- Returns:
- the types
-
isAssignable
Determine whether the first type can be assigned to the second- Parameters:
type- string type to checksuperType- the type that should be assignable to.- Returns:
- true if type can be assinged to supertype
-
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 theModuleElementfor 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.setProjectModuleElementmust be called before this.- Returns:
- the
ModuleElementassociated with the current project
-
getModuleInfoReader
Gets aBufferedReaderfor the project'smodule-info.javasource file.Calling
ModuleElement'sgetDirectives()method has a chance of making compilation fail in certain situations. Therefore, manually parsingmodule-info.javaseems to be the safest way to get module information.- Returns:
- Throws:
IOException- if unable to read the module-info
-