Package io.micronaut.ast.groovy.visitor
Class GroovyVisitorContext
java.lang.Object
io.micronaut.ast.groovy.visitor.GroovyVisitorContext
- All Implemented Interfaces:
ConversionServiceProvider
,ConvertibleValues<Object>
,MutableConvertibleValues<Object>
,ValueResolver<CharSequence>
,VisitorContext
,ClassWriterOutputVisitor
,Iterable<Map.Entry<String,
Object>>
The visitor context when visiting Groovy code.
- Since:
- 1.0
- Author:
- James Kleeh, Graeme Rocher
-
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
ConstructorDescriptionGroovyVisitorContext
(org.codehaus.groovy.control.SourceUnit sourceUnit, @Nullable org.codehaus.groovy.control.CompilationUnit compilationUnit) GroovyVisitorContext
(org.codehaus.groovy.control.SourceUnit sourceUnit, @Nullable org.codehaus.groovy.control.CompilationUnit compilationUnit, ClassWriterOutputVisitor outputVisitor) -
Method Summary
Modifier and TypeMethodDescriptionvoid
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.final void
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.getClassElement
(Class<?> type) This method will lookup another class element by name.getClassElement
(String name) This method will lookup another class element by name.getClassElement
(String name, ElementAnnotationMetadataFactory annotationMetadataFactory) This method will lookup 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.org.codehaus.groovy.control.CompilationUnit
Gets the element annotation metadata factory.Gets the element factory for this visitor context.Provide a collection of generated classpath resources that other TypeElement visitors might want to consume.Groovy options source areSystem.getProperties()
based.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, @Nullable 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.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
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
getClassesOutputPath, getConfiguration, getProjectDir, getRequiredClassElement
-
Constructor Details
-
GroovyVisitorContext
public GroovyVisitorContext(org.codehaus.groovy.control.SourceUnit sourceUnit, @Nullable @Nullable org.codehaus.groovy.control.CompilationUnit compilationUnit) - Parameters:
sourceUnit
- The source unitcompilationUnit
- The compilation unit
-
GroovyVisitorContext
public GroovyVisitorContext(org.codehaus.groovy.control.SourceUnit sourceUnit, @Nullable @Nullable org.codehaus.groovy.control.CompilationUnit compilationUnit, ClassWriterOutputVisitor outputVisitor) - Parameters:
sourceUnit
- The source unitcompilationUnit
- The compilation unitoutputVisitor
- The class writer output visitor
-
-
Method Details
-
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 lookup 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 lookup 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
-
getClassElement
Description copied from interface:VisitorContext
This method will lookup another class element by name. If it cannot be found an empty optional will be returned.- Specified by:
getClassElement
in interfaceVisitorContext
- Parameters:
type
- The name- 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
@NonNull public @NonNull GroovyElementAnnotationMetadataFactory 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
-
fail
-
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
-
visitClass
public OutputStream visitClass(String classname, @Nullable @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
-
finish
public void finish()Description copied from interface:ClassWriterOutputVisitor
Finish writing and flush any service entries to disk.- Specified by:
finish
in interfaceClassWriterOutputVisitor
-
getCompilationUnit
- Returns:
- The compilation unit
-
getOptions
Groovy options source areSystem.getProperties()
based.All properties MUST start with
VisitorContext.MICRONAUT_BASE_OPTION_NAME
- Specified by:
getOptions
in interfaceVisitorContext
- Returns:
- options
Map
- 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.
-