Class JavaVisitorContext
java.lang.Object
io.micronaut.annotation.processing.visitor.JavaVisitorContext
- All Implemented Interfaces:
ConversionServiceProvider
,ConvertibleValues<Object>
,MutableConvertibleValues<Object>
,ValueResolver<CharSequence>
,BeanElementVisitorContext
,VisitorContext
,ClassWriterOutputVisitor
,Iterable<Map.Entry<String,
Object>>
@Internal
public final class JavaVisitorContext
extends Object
implements VisitorContext, BeanElementVisitorContext
The visitor context when visiting Java code.
- Since:
- 1.0
- Author:
- James Kleeh
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.micronaut.inject.visitor.VisitorContext
VisitorContext.Language
-
Field Summary
Fields inherited from interface io.micronaut.core.convert.value.ConvertibleValues
EMPTY
Fields inherited from interface io.micronaut.inject.visitor.VisitorContext
MICRONAUT_BASE_OPTION_NAME, MICRONAUT_PROCESSING_GROUP, MICRONAUT_PROCESSING_MODULE, MICRONAUT_PROCESSING_PROJECT_DIR
-
Constructor Summary
ConstructorDescriptionJavaVisitorContext
(ProcessingEnvironment processingEnv, Messager messager, Elements elements, AnnotationUtils annotationUtils, Types types, ModelUtils modelUtils, GenericUtils genericUtils, Filer filer, MutableConvertibleValues<Object> visitorAttributes, TypeElementVisitor.VisitorKind visitorKind) The default constructor. -
Method Summary
Modifier and TypeMethodDescriptionaddAssociatedBean
(Element originatingElement, ClassElement type) void
addGeneratedResource
(@NonNull String resource) Some TypeElementVisitors generate classpath resources that other visitors might be interested in.clear()
Clear all values.void
Allows failing compilation for a given element with the given message.void
finish()
Finish writing and flush any service entries to disk.<T> Optional<T>
get
(CharSequence name, ArgumentConversionContext<T> conversionContext) Resolve the given property for the given name.Gets the annotation metadata builder.The annotation utils.getClassElement
(String name) This method will look up another class element by name.getClassElement
(String name, ElementAnnotationMetadataFactory annotationMetadataFactory) This method will look up another class element by name.getClassElements
(@NonNull String aPackage, @NonNull String... stereotypes) Find all the classes within the given package and having the given annotation.Obtain a set of resources from the user classpath.Gets the element annotation metadata factory.Gets the element factory for this visitor context.The elements.Provide a collection of generated classpath resources that other TypeElement visitors might want to consume.The generic utils object.The messager.The model utils.Java visitor context options fromjavac
arguments andSystem.getProperties()
getTypes()
The types.void
Allows printing informational messages.void
Allows printing informational messages.names()
put
(CharSequence key, @Nullable Object value) Insert a value for the given key and value.remove
(CharSequence key) Remove a value for the given key.values()
visitClass
(String classname, Element originatingElement) Visits a new class and returns the output stream with which should be written the bytes of the class to be generated.visitClass
(String classname, Element... originatingElements) Visits a new class and returns the output stream with which should be written the bytes of the class to be generated.visitGeneratedFile
(String path) Visit a file that will be located within the generated source directory.visitGeneratedFile
(String path, Element... originatingElements) Visit a file that will be generated within the generated 'sources' directory.visitGeneratedSourceFile
(String packageName, String fileNameWithoutExtension, Element... originatingElements) Visit a source file that will be generated within the generated 'sources' directory.visitMetaInfFile
(String path, Element... originatingElements) Visit a file within the META-INF directory.void
visitServiceDescriptor
(String type, String classname) Allows adding a class that will be written to theMETA-INF/services
file under the given type and class name.void
visitServiceDescriptor
(String type, String classname, Element originatingElement) Allows adding a class that will be written to theMETA-INF/services
file under the given type and class name.void
Print warning message.void
Allows printing a warning for the given message and element.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.micronaut.inject.writer.ClassWriterOutputVisitor
getServiceEntries, visitClass, visitMetaInfFile, visitServiceDescriptor, visitServiceDescriptor
Methods inherited from interface io.micronaut.core.convert.value.ConvertibleValues
asMap, asMap, asProperties, contains, forEach, getConversionService, getValue, getValueType, isEmpty, iterator, subMap, subMap, subMap
Methods inherited from interface java.lang.Iterable
forEach, spliterator
Methods inherited from interface io.micronaut.core.convert.value.MutableConvertibleValues
putAll, putAll
Methods inherited from interface io.micronaut.core.value.ValueResolver
get, get, get
Methods inherited from interface io.micronaut.inject.visitor.VisitorContext
getClassElement, getClassesOutputPath, getConfiguration, getProjectDir, getRequiredClassElement
-
Constructor Details
-
JavaVisitorContext
public JavaVisitorContext(ProcessingEnvironment processingEnv, Messager messager, Elements elements, AnnotationUtils annotationUtils, Types types, ModelUtils modelUtils, GenericUtils genericUtils, Filer filer, MutableConvertibleValues<Object> visitorAttributes, TypeElementVisitor.VisitorKind visitorKind) The default constructor.- Parameters:
processingEnv
- The processing environmentmessager
- The messagerelements
- The elementsannotationUtils
- The annotation utilstypes
- Type typesmodelUtils
- The model utilsgenericUtils
- The generic type utilsfiler
- The filervisitorAttributes
- The attributesvisitorKind
- The visitor kind
-
-
Method Details
-
getLanguage
- Specified by:
getLanguage
in interfaceVisitorContext
- Returns:
- The visitor context's language.
-
getVisitorKind
- Returns:
- The visitor kind
-
getProcessingEnv
- Returns:
- The processing environment
-
getClasspathResources
Description copied from interface:VisitorContext
Obtain a set of resources from the user classpath.- Specified by:
getClasspathResources
in interfaceVisitorContext
- Parameters:
path
- The path- Returns:
- An iterable of resources
-
getClassElement
Description copied from interface:VisitorContext
This method will look up another class element by name. If it cannot be found an empty optional will be returned.- Specified by:
getClassElement
in interfaceVisitorContext
- Parameters:
name
- The name- Returns:
- The class element
-
getClassElement
public Optional<ClassElement> getClassElement(String name, ElementAnnotationMetadataFactory annotationMetadataFactory) Description copied from interface:VisitorContext
This method will look up another class element by name. If it cannot be found an empty optional will be returned.- Specified by:
getClassElement
in interfaceVisitorContext
- Parameters:
name
- The nameannotationMetadataFactory
- The element annotation metadata factory- Returns:
- The class element
-
getClassElements
@NonNull public @NonNull ClassElement[] getClassElements(@NonNull @NonNull String aPackage, @NonNull @NonNull String... stereotypes) Description copied from interface:VisitorContext
Find all the classes within the given package and having the given annotation.- Specified by:
getClassElements
in interfaceVisitorContext
- Parameters:
aPackage
- The packagestereotypes
- The stereotypes- Returns:
- The class elements
-
getElementFactory
Description copied from interface:VisitorContext
Gets the element factory for this visitor context.- Specified by:
getElementFactory
in interfaceVisitorContext
- Returns:
- The element factory
-
getElementAnnotationMetadataFactory
Description copied from interface:VisitorContext
Gets the element annotation metadata factory.- Specified by:
getElementAnnotationMetadataFactory
in interfaceVisitorContext
- Returns:
- The element annotation metadata factory
-
getExpressionCompilationContextFactory
- Specified by:
getExpressionCompilationContextFactory
in interfaceVisitorContext
- Returns:
- The expression compilation context factory.
-
getAnnotationMetadataBuilder
Description copied from interface:VisitorContext
Gets the annotation metadata builder.- Specified by:
getAnnotationMetadataBuilder
in interfaceVisitorContext
- Returns:
- The annotation metadata builder
-
info
Description copied from interface:VisitorContext
Allows printing informational messages.- Specified by:
info
in interfaceVisitorContext
- Parameters:
message
- The messageelement
- The element
-
info
Description copied from interface:VisitorContext
Allows printing informational messages.- Specified by:
info
in interfaceVisitorContext
- Parameters:
message
- The message
-
fail
Description copied from interface:VisitorContext
Allows failing compilation for a given element with the given message.- Specified by:
fail
in interfaceVisitorContext
- Parameters:
message
- The messageelement
- The element
-
warn
Description copied from interface:VisitorContext
Allows printing a warning for the given message and element.- Specified by:
warn
in interfaceVisitorContext
- Parameters:
message
- The messageelement
- The element
-
warn
Print warning message.- Parameters:
message
- The messageelement
- The element- Since:
- 4.0.0
-
visitClass
public OutputStream visitClass(String classname, @Nullable Element originatingElement) throws IOException Description copied from interface:ClassWriterOutputVisitor
Visits a new class and returns the output stream with which should be written the bytes of the class to be generated.- Specified by:
visitClass
in interfaceClassWriterOutputVisitor
- Parameters:
classname
- the fully qualified classnameoriginatingElement
- The originating element- Returns:
- the output stream to write to
- Throws:
IOException
- if an error occurs creating the output stream
-
visitClass
Description copied from interface:ClassWriterOutputVisitor
Visits a new class and returns the output stream with which should be written the bytes of the class to be generated.Note that this method should only be called from a
TypeElementVisitor.VisitorKind.AGGREGATING
visitor from within theTypeElementVisitor.finish(io.micronaut.inject.visitor.VisitorContext)
method. If the file- Specified by:
visitClass
in interfaceClassWriterOutputVisitor
- Parameters:
classname
- the fully qualified classnameoriginatingElements
- The originating elements- Returns:
- the output stream to write to
- Throws:
IOException
- if an error occurs creating the output stream
-
visitServiceDescriptor
Description copied from interface:ClassWriterOutputVisitor
Allows adding a class that will be written to theMETA-INF/services
file under the given type and class name.- Specified by:
visitServiceDescriptor
in interfaceClassWriterOutputVisitor
- Parameters:
type
- the fully qualified service nameclassname
- the fully qualified classname
-
visitServiceDescriptor
Description copied from interface:ClassWriterOutputVisitor
Allows adding a class that will be written to theMETA-INF/services
file under the given type and class name.- Specified by:
visitServiceDescriptor
in interfaceClassWriterOutputVisitor
- Parameters:
type
- the fully qualified service nameclassname
- the fully qualified classnameoriginatingElement
- The originating element
-
visitMetaInfFile
Description copied from interface:VisitorContext
Visit a file within the META-INF directory.- Specified by:
visitMetaInfFile
in interfaceClassWriterOutputVisitor
- Specified by:
visitMetaInfFile
in interfaceVisitorContext
- Parameters:
path
- The path to the fileoriginatingElements
- The originating elements- Returns:
- An optional file it was possible to create it
-
visitGeneratedFile
Description copied from interface:VisitorContext
Visit a file that will be located within the generated source directory.- Specified by:
visitGeneratedFile
in interfaceClassWriterOutputVisitor
- Specified by:
visitGeneratedFile
in interfaceVisitorContext
- Parameters:
path
- The path to the file- Returns:
- An optional file it was possible to create it
-
visitGeneratedFile
Description copied from interface:ClassWriterOutputVisitor
Visit a file that will be generated within the generated 'sources' directory.- Specified by:
visitGeneratedFile
in interfaceClassWriterOutputVisitor
- Parameters:
path
- The pathoriginatingElements
- the originating elements- Returns:
- The file if it was possible to create it
-
visitGeneratedSourceFile
public Optional<GeneratedFile> visitGeneratedSourceFile(String packageName, String fileNameWithoutExtension, Element... originatingElements) Description copied from interface:ClassWriterOutputVisitor
Visit a source file that will be generated within the generated 'sources' directory.- Specified by:
visitGeneratedSourceFile
in interfaceClassWriterOutputVisitor
- Parameters:
packageName
- The package for the source filefileNameWithoutExtension
- the name of the source file, without extension (determined automatically)originatingElements
- the originating elements- Returns:
- The file if it was possible to create it
-
finish
public void finish()Description copied from interface:ClassWriterOutputVisitor
Finish writing and flush any service entries to disk.- Specified by:
finish
in interfaceClassWriterOutputVisitor
-
getMessager
The messager.- Returns:
- The messager
-
getModelUtils
The model utils.- Returns:
- The model utils
-
getElements
The elements.- Returns:
- The elements
-
getAnnotationUtils
The annotation utils.- Returns:
- The annotation utils
-
getTypes
The types.- Returns:
- The types
-
getGenericUtils
The generic utils object.- Returns:
- The generic utils
-
getOptions
Java visitor context options fromjavac
arguments andSystem.getProperties()
System properties has priority over arguments.
- Specified by:
getOptions
in interfaceVisitorContext
- Returns:
- Java visitor context options for all visitors
- See Also:
-
put
Description copied from interface:MutableConvertibleValues
Insert a value for the given key and value.- Specified by:
put
in interfaceMutableConvertibleValues<Object>
- Parameters:
key
- The keyvalue
- The value- Returns:
- This values instance
-
remove
Description copied from interface:MutableConvertibleValues
Remove a value for the given key.- Specified by:
remove
in interfaceMutableConvertibleValues<Object>
- Parameters:
key
- The key- Returns:
- This values instance
-
clear
Description copied from interface:MutableConvertibleValues
Clear all values.- Specified by:
clear
in interfaceMutableConvertibleValues<Object>
- Returns:
- This values instance
-
names
- Specified by:
names
in interfaceConvertibleValues<Object>
- Returns:
- The names of the values
-
values
- Specified by:
values
in interfaceConvertibleValues<Object>
- Returns:
- The values
-
get
Description copied from interface:ValueResolver
Resolve the given property for the given name.- Specified by:
get
in interfaceValueResolver<CharSequence>
- Type Parameters:
T
- The concrete type- Parameters:
name
- The nameconversionContext
- The conversion context- Returns:
- An optional containing the property value if it exists and is able to be converted
-
getGeneratedResources
Description copied from interface:VisitorContext
Provide a collection of generated classpath resources that other TypeElement visitors might want to consume. The generated resources are intended to be strings paths relative to the classpath root.- Specified by:
getGeneratedResources
in interfaceVisitorContext
- Returns:
- a possibly empty collection of resource paths
-
addGeneratedResource
Description copied from interface:VisitorContext
Some TypeElementVisitors generate classpath resources that other visitors might be interested in. The generated resources are intended to be strings paths relative to the classpath root- Specified by:
addGeneratedResource
in interfaceVisitorContext
- Parameters:
resource
- the relative path to add
-
getBeanElementBuilders
- Returns:
- Gets the produced bean definition builders.
-
addAssociatedBean
- Specified by:
addAssociatedBean
in interfaceBeanElementVisitorContext
-