Package io.micronaut.inject.visitor
Interface VisitorContext
-
- All Superinterfaces:
ClassWriterOutputVisitor
,io.micronaut.core.convert.value.ConvertibleValues<java.lang.Object>
,java.lang.Iterable<java.util.Map.Entry<java.lang.String,java.lang.Object>>
,io.micronaut.core.convert.value.MutableConvertibleValues<java.lang.Object>
,io.micronaut.core.value.ValueResolver<java.lang.CharSequence>
- All Known Subinterfaces:
BeanElementVisitorContext
public interface VisitorContext extends io.micronaut.core.convert.value.MutableConvertibleValues<java.lang.Object>, ClassWriterOutputVisitor
Provides a way forTypeElementVisitor
classes to log messages during compilation and fail compilation.- Since:
- 1.0
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
MICRONAUT_BASE_OPTION_NAME
static java.lang.String
MICRONAUT_PROCESSING_GROUP
static java.lang.String
MICRONAUT_PROCESSING_MODULE
static java.lang.String
MICRONAUT_PROCESSING_PROJECT_DIR
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description default void
addGeneratedResource(java.lang.String resource)
Some TypeElementVisitors generate classpath resources that other visitors might be interested in.void
fail(java.lang.String message, Element element)
Allows failing compilation for a given element with the given message.default java.util.Optional<ClassElement>
getClassElement(java.lang.Class<?> type)
This method will lookup another class element by name.default java.util.Optional<ClassElement>
getClassElement(java.lang.String name)
This method will lookup another class element by name.default ClassElement[]
getClassElements(java.lang.String aPackage, java.lang.String... stereotypes)
Find all the classes within the given package and having the given annotation.default java.util.Optional<java.nio.file.Path>
getClassesOutputPath()
Provide the Path to the annotation processing classes output directory, i.e.default java.lang.Iterable<java.net.URL>
getClasspathResources(java.lang.String path)
Obtain a set of resources from the user classpath.default VisitorConfiguration
getConfiguration()
ElementFactory<?,?,?,?>
getElementFactory()
Gets the element factory for this visitor context.default java.util.Collection<java.lang.String>
getGeneratedResources()
Provide a collection of generated classpath resources that other TypeElement visitors might want to consume.default java.util.Map<java.lang.String,java.lang.String>
getOptions()
The annotation processor environment custom options.default java.util.Optional<java.nio.file.Path>
getProjectDir()
Obtain the project directory.void
info(java.lang.String message)
Allows printing informational messages.void
info(java.lang.String message, Element element)
Allows printing informational messages.java.util.Optional<GeneratedFile>
visitGeneratedFile(java.lang.String path)
Visit a file that will be located within the generated source directory.default java.util.Optional<GeneratedFile>
visitMetaInfFile(java.lang.String path)
Deprecated.Visiting a file should supply the originating elements.java.util.Optional<GeneratedFile>
visitMetaInfFile(java.lang.String path, Element... originatingElements)
Visit a file within the META-INF directory.void
warn(java.lang.String message, Element element)
Allows printing a warning for the given message and element.-
Methods inherited from interface io.micronaut.inject.writer.ClassWriterOutputVisitor
finish, getServiceEntries, visitClass, visitClass, visitClass, visitServiceDescriptor, visitServiceDescriptor, visitServiceDescriptor, visitServiceDescriptor
-
Methods inherited from interface io.micronaut.core.convert.value.ConvertibleValues
asMap, asMap, asProperties, contains, forEach, getValue, getValueType, isEmpty, iterator, names, subMap, subMap, subMap, values
-
-
-
-
Field Detail
-
MICRONAUT_BASE_OPTION_NAME
static final java.lang.String MICRONAUT_BASE_OPTION_NAME
- See Also:
- Constant Field Values
-
MICRONAUT_PROCESSING_PROJECT_DIR
static final java.lang.String MICRONAUT_PROCESSING_PROJECT_DIR
- See Also:
- Constant Field Values
-
MICRONAUT_PROCESSING_GROUP
static final java.lang.String MICRONAUT_PROCESSING_GROUP
- See Also:
- Constant Field Values
-
MICRONAUT_PROCESSING_MODULE
static final java.lang.String MICRONAUT_PROCESSING_MODULE
- See Also:
- Constant Field Values
-
-
Method Detail
-
getElementFactory
@NonNull ElementFactory<?,?,?,?> getElementFactory()
Gets the element factory for this visitor context.- Returns:
- The element factory
- Since:
- 2.3.0
-
info
void info(java.lang.String message, @Nullable Element element)
Allows printing informational messages.- Parameters:
message
- The messageelement
- The element
-
info
void info(java.lang.String message)
Allows printing informational messages.- Parameters:
message
- The message
-
fail
void fail(java.lang.String message, @Nullable Element element)
Allows failing compilation for a given element with the given message.- Parameters:
message
- The messageelement
- The element
-
warn
void warn(java.lang.String message, @Nullable Element element)
Allows printing a warning for the given message and element.- Parameters:
message
- The messageelement
- The element
-
getConfiguration
@NonNull default VisitorConfiguration getConfiguration()
- Returns:
- The visitor configuration
-
visitMetaInfFile
@Deprecated default java.util.Optional<GeneratedFile> visitMetaInfFile(java.lang.String path)
Deprecated.Visiting a file should supply the originating elements. UsevisitMetaInfFile(String, Element...)
insteadVisit a file within the META-INF directory.- Specified by:
visitMetaInfFile
in interfaceClassWriterOutputVisitor
- Parameters:
path
- The path to the file- Returns:
- An optional file it was possible to create it
-
visitMetaInfFile
java.util.Optional<GeneratedFile> visitMetaInfFile(java.lang.String path, Element... originatingElements)
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
java.util.Optional<GeneratedFile> visitGeneratedFile(java.lang.String path)
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
@NonNull default java.lang.Iterable<java.net.URL> getClasspathResources(@NonNull java.lang.String path)
Obtain a set of resources from the user classpath.- Parameters:
path
- The path- Returns:
- An iterable of resources
-
getProjectDir
default java.util.Optional<java.nio.file.Path> getProjectDir()
Obtain the project directory.- Returns:
- An optional wrapping the project directory
-
getClassesOutputPath
default java.util.Optional<java.nio.file.Path> 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
default java.util.Optional<ClassElement> getClassElement(java.lang.String name)
This method will lookup 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 java.util.Optional<ClassElement> getClassElement(java.lang.Class<?> type)
This method will lookup 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 ClassElement[] getClassElements(@NonNull java.lang.String aPackage, @NonNull java.lang.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
default java.util.Map<java.lang.String,java.lang.String> 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:
ProcessingEnvironment.getOptions()
-
getGeneratedResources
default java.util.Collection<java.lang.String> 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
default void addGeneratedResource(java.lang.String resource)
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
-
-