Package io.micronaut.inject.visitor
Interface VisitorContext
- All Superinterfaces:
ClassWriterOutputVisitor
,ConversionServiceProvider
,ConvertibleValues<Object>
,Iterable<Map.Entry<String,
,Object>> MutableConvertibleValues<Object>
,ValueResolver<CharSequence>
- All Known Subinterfaces:
BeanElementVisitorContext
- All Known Implementing Classes:
GroovyVisitorContext
,JavaVisitorContext
Provides a way for
TypeElementVisitor
classes to log messages during compilation and fail compilation.- Since:
- 1.0
- Author:
- James Kleeh, Graeme Rocher
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic enum
The languages that are supported in source code generation. -
Field Summary
Modifier and TypeFieldDescriptionstatic final String
static final String
static final String
static final String
Fields inherited from interface io.micronaut.core.convert.value.ConvertibleValues
EMPTY
-
Method Summary
Modifier and TypeMethodDescriptiondefault void
addGeneratedResource
(String resource) Some TypeElementVisitors generate classpath resources that other visitors might be interested in.void
Allows failing compilation for a given element with the given message.Gets the annotation metadata builder.default Optional<ClassElement>
getClassElement
(Class<?> type) This method will look up another class element by name.default Optional<ClassElement>
getClassElement
(String name) This method will look up another class element by name.default Optional<ClassElement>
getClassElement
(String name, ElementAnnotationMetadataFactory annotationMetadataFactory) This method will look up another class element by name.default @NonNull ClassElement[]
getClassElements
(@NonNull String aPackage, @NonNull String... stereotypes) Find all the classes within the given package and having the given annotation.Provide the Path to the annotation processing classes output directory, i.e.Obtain a set of resources from the user classpath.default @NonNull VisitorConfiguration
Gets the element annotation metadata factory.@NonNull ElementFactory<?,
?, ?, ?> Gets the element factory for this visitor context.default Collection<String>
Provide a collection of generated classpath resources that other TypeElement visitors might want to consume.The annotation processor environment custom options.Obtain the project directory.default ClassElement
getRequiredClassElement
(String name, ElementAnnotationMetadataFactory annotationMetadataFactory) This method will look up another class element by name.void
Allows printing informational messages.void
Allows printing informational messages.visitGeneratedFile
(String path) Visit a file that will be located within the generated source directory.visitMetaInfFile
(String path, Element... originatingElements) Visit a file within the META-INF directory.void
Allows printing a warning for the given message and element.Methods inherited from interface io.micronaut.inject.writer.ClassWriterOutputVisitor
finish, getServiceEntries, visitClass, visitClass, visitClass, visitGeneratedFile, visitGeneratedSourceFile, visitMetaInfFile, visitServiceDescriptor, visitServiceDescriptor, visitServiceDescriptor, visitServiceDescriptor
Methods inherited from interface io.micronaut.core.convert.value.ConvertibleValues
asMap, asMap, asProperties, contains, forEach, getConversionService, getValue, getValueType, isEmpty, iterator, names, subMap, subMap, subMap, values
Methods inherited from interface java.lang.Iterable
forEach, spliterator
Methods inherited from interface io.micronaut.core.convert.value.MutableConvertibleValues
clear, put, putAll, putAll, remove
Methods inherited from interface io.micronaut.core.value.ValueResolver
get, get, get, get
-
Field Details
-
MICRONAUT_BASE_OPTION_NAME
- See Also:
-
MICRONAUT_PROCESSING_PROJECT_DIR
- See Also:
-
MICRONAUT_PROCESSING_GROUP
- See Also:
-
MICRONAUT_PROCESSING_MODULE
- See Also:
-
-
Method Details
-
getLanguage
VisitorContext.Language getLanguage()- Returns:
- The visitor context's language.
- Since:
- 4.2.0
-
getElementFactory
Gets the element factory for this visitor context.- Returns:
- The element factory
- Since:
- 2.3.0
-
getElementAnnotationMetadataFactory
Gets the element annotation metadata factory.- Returns:
- The element annotation metadata factory
- Since:
- 4.0.0
-
getExpressionCompilationContextFactory
- Returns:
- The expression compilation context factory.
- Since:
- 4.0.0
-
getAnnotationMetadataBuilder
Gets the annotation metadata builder.- Returns:
- The annotation metadata builder
- Since:
- 4.0.0
-
info
Allows printing informational messages.- Parameters:
message
- The messageelement
- The element
-
info
Allows printing informational messages.- Parameters:
message
- The message
-
fail
Allows failing compilation for a given element with the given message.- Parameters:
message
- The messageelement
- The element
-
warn
Allows printing a warning for the given message and element.- Parameters:
message
- The messageelement
- The element
-
getConfiguration
- Returns:
- The visitor configuration
-
visitMetaInfFile
Visit a file within the META-INF directory.- Specified by:
visitMetaInfFile
in interfaceClassWriterOutputVisitor
- Parameters:
path
- The path to the fileoriginatingElements
- The originating elements- Returns:
- An optional file it was possible to create it
-
visitGeneratedFile
Visit a file that will be located within the generated source directory.- Specified by:
visitGeneratedFile
in interfaceClassWriterOutputVisitor
- Parameters:
path
- The path to the file- Returns:
- An optional file it was possible to create it
-
getClasspathResources
Obtain a set of resources from the user classpath.- Parameters:
path
- The path- Returns:
- An iterable of resources
-
getProjectDir
Obtain the project directory.- Returns:
- An optional wrapping the project directory
-
getClassesOutputPath
Provide the Path to the annotation processing classes output directory, i.e. the parent of META-INF.This might, for example, be used as a convenience for
TypeElementVisitor
classes to provide relative path strings toaddGeneratedResource(String)
Path resource = ... // absolute path to the resource visitorContext.getClassesOutputPath().ifPresent(path -> visitorContext.addGeneratedResource(path.relativize(resource).toString()));
- Returns:
- Path pointing to the classes output directory
-
getClassElement
This method will look up another class element by name. If it cannot be found an empty optional will be returned.- Parameters:
name
- The name- Returns:
- The class element
-
getClassElement
default Optional<ClassElement> getClassElement(String name, ElementAnnotationMetadataFactory annotationMetadataFactory) This method will look up another class element by name. If it cannot be found an empty optional will be returned.- Parameters:
name
- The nameannotationMetadataFactory
- The element annotation metadata factory- Returns:
- The class element
- Since:
- 4.0.0
-
getRequiredClassElement
default ClassElement getRequiredClassElement(String name, ElementAnnotationMetadataFactory annotationMetadataFactory) This method will look up another class element by name. If it cannot be found an exception thrown.- Parameters:
name
- The nameannotationMetadataFactory
- The element annotation metadata factory- Returns:
- The class element
- Since:
- 4.0.0
-
getClassElement
This method will look up another class element by name. If it cannot be found an empty optional will be returned.- Parameters:
type
- The name- Returns:
- The class element
-
getClassElements
@NonNull default @NonNull ClassElement[] getClassElements(@NonNull @NonNull String aPackage, @NonNull @NonNull String... stereotypes) Find all the classes within the given package and having the given annotation.- Parameters:
aPackage
- The packagestereotypes
- The stereotypes- Returns:
- The class elements
-
getOptions
The annotation processor environment custom options.All options names MUST start with
MICRONAUT_BASE_OPTION_NAME
- Returns:
- A Map with annotation processor runtime options
- See Also:
-
getGeneratedResources
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.- Returns:
- a possibly empty collection of resource paths
-
addGeneratedResource
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- Parameters:
resource
- the relative path to add
-