- java.lang.Object
-
- io.avaje.inject.generator.APContext
-
@Generated("avaje-prism-generator") public final class APContext extends Object
Utiliy Class that stores theProcessingEnvironmentand provides various helper methods
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classAPContext.Ctx
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static TypeElementasTypeElement(TypeMirror t)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 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 theProcessingEnvironmentstatic Set<? extends Element>elementsAnnotatedWith(RoundEnvironment round, String annotationFQN)Returns the elements annotated with the given annotation interface.static Filerfiler()Get currentFilerfrom theProcessingEnvironmentstatic BufferedReadergetModuleInfoReader()Gets aBufferedReaderfor the project'smodule-info.javasource file.static ModuleElementgetProjectModuleElement()Retrieve 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 intjdkVersion()Returns the source version that any generated source and class files should conform tostatic voidlogError(String msg, Object... args)Prints an error.static voidlogError(Element e, String msg, Object... args)Prints an error at the location of the element.static voidlogNote(String msg, Object... args)Prints a note at the location of the element.static voidlogNote(Element e, String msg, Object... args)Prints a note.static voidlogWarn(String msg, Object... args)Prints a warning.static voidlogWarn(Element e, String msg, Object... args)Prints an warning at the location of the element.static Messagermessager()Get currentMessagerfrom theProcessingEnvironmentstatic booleanpreviewEnabled()Returns whether--preview-enabledhas been added to compiler flags.static ProcessingEnvironmentprocessingEnv()Get 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 Detail
-
init
public static void init(ProcessingEnvironment processingEnv)
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
public static void init(APContext.Ctx context, int jdkVersion, boolean preview)
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
public static void logError(Element e, String msg, Object... args)
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
public static void logError(String msg, Object... args)
Prints an error.- Parameters:
msg- the message, or an empty string if noneargs-String#formatarguments
-
logWarn
public static void logWarn(Element e, String msg, Object... args)
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
public static void logWarn(String msg, Object... args)
Prints a warning.- Parameters:
msg- the message, or an empty string if noneargs-String#formatarguments
-
logNote
public static void logNote(Element e, String msg, Object... args)
Prints a note.- Parameters:
msg- the message, or an empty string if noneargs-String#formatarguments
-
logNote
public static void logNote(String msg, Object... args)
Prints a note 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
-
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
public static TypeElement typeElement(String name)
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
public static TypeElement asTypeElement(TypeMirror t)
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
public static ProcessingEnvironment processingEnv()
Get currentProcessingEnvironment- Returns:
- the enviroment
-
filer
public static Filer filer()
Get currentFilerfrom theProcessingEnvironment- Returns:
- the filer
-
elements
public static Elements elements()
Get currentElementsfrom theProcessingEnvironment- Returns:
- the filer
-
messager
public static Messager messager()
Get currentMessagerfrom theProcessingEnvironment- Returns:
- the messager
-
types
public static Types types()
Get currentTypesfrom theProcessingEnvironment- Returns:
- the types
-
isAssignable
public static boolean isAssignable(String type, String superType)
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
public static boolean isAssignable(TypeElement type, String superType)
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
public static ModuleElement getProjectModuleElement()
Retrieve the project'sModuleElement.setProjectModuleElementmust be called before this.- Returns:
- the
ModuleElementassociated with the current project
-
getModuleInfoReader
public static BufferedReader getModuleInfoReader() throws IOException
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
-
-