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
-
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
EMPTYFields inherited from interface io.micronaut.inject.visitor.VisitorContext
MICRONAUT_BASE_OPTION_NAME, MICRONAUT_PROCESSING_GROUP, MICRONAUT_PROCESSING_MODULE, MICRONAUT_PROCESSING_PROJECT_DIR -
Constructor Summary
ConstructorsConstructorDescriptionGroovyVisitorContext(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 TypeMethodDescriptionvoidaddGeneratedResource(@NonNull String resource) Some TypeElementVisitors generate classpath resources that other visitors might be interested in.clear()Clear all values.voidAllows failing compilation for a given element with the given message.final voidvoidfinish()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 look up another class element by name.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.org.codehaus.groovy.control.CompilationUnitGets 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.voidAllows printing informational messages.voidAllows 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.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.voidvisitServiceDescriptor(String type, String classname) Allows adding a class that will be written to theMETA-INF/servicesfile under the given type and class name.voidvisitServiceDescriptor(String type, String classname, Element originatingElement) Allows adding a class that will be written to theMETA-INF/servicesfile under the given type and class name.voidAllows 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, waitMethods inherited from interface io.micronaut.inject.writer.ClassWriterOutputVisitor
getServiceEntries, visitClass, visitMetaInfFile, visitServiceDescriptor, visitServiceDescriptorMethods inherited from interface io.micronaut.core.convert.value.ConvertibleValues
asMap, asMap, asProperties, contains, forEach, getConversionService, getValue, getValueType, isEmpty, iterator, subMap, subMap, subMapMethods inherited from interface java.lang.Iterable
forEach, spliteratorMethods inherited from interface io.micronaut.core.convert.value.MutableConvertibleValues
putAll, putAllMethods inherited from interface io.micronaut.core.value.ValueResolver
get, get, getMethods 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
-
getLanguage
- Specified by:
getLanguagein interfaceVisitorContext- Returns:
- The visitor context's language.
-
getClasspathResources
Description copied from interface:VisitorContextObtain a set of resources from the user classpath.- Specified by:
getClasspathResourcesin interfaceVisitorContext- Parameters:
path- The path- Returns:
- An iterable of resources
-
getClassElement
Description copied from interface:VisitorContextThis method will look up another class element by name. If it cannot be found an empty optional will be returned.- Specified by:
getClassElementin interfaceVisitorContext- Parameters:
name- The name- Returns:
- The class element
-
getClassElement
public Optional<ClassElement> getClassElement(String name, ElementAnnotationMetadataFactory annotationMetadataFactory) Description copied from interface:VisitorContextThis method will look up another class element by name. If it cannot be found an empty optional will be returned.- Specified by:
getClassElementin interfaceVisitorContext- Parameters:
name- The nameannotationMetadataFactory- The element annotation metadata factory- Returns:
- The class element
-
getClassElement
Description copied from interface:VisitorContextThis method will look up another class element by name. If it cannot be found an empty optional will be returned.- Specified by:
getClassElementin 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:VisitorContextFind all the classes within the given package and having the given annotation.- Specified by:
getClassElementsin interfaceVisitorContext- Parameters:
aPackage- The packagestereotypes- The stereotypes- Returns:
- The class elements
-
getElementFactory
Description copied from interface:VisitorContextGets the element factory for this visitor context.- Specified by:
getElementFactoryin interfaceVisitorContext- Returns:
- The element factory
-
getElementAnnotationMetadataFactory
@NonNull public @NonNull GroovyElementAnnotationMetadataFactory getElementAnnotationMetadataFactory()Description copied from interface:VisitorContextGets the element annotation metadata factory.- Specified by:
getElementAnnotationMetadataFactoryin interfaceVisitorContext- Returns:
- The element annotation metadata factory
-
getExpressionCompilationContextFactory
@NonNull public @NonNull ExpressionCompilationContextFactory getExpressionCompilationContextFactory()- Specified by:
getExpressionCompilationContextFactoryin interfaceVisitorContext- Returns:
- The expression compilation context factory.
-
getAnnotationMetadataBuilder
Description copied from interface:VisitorContextGets the annotation metadata builder.- Specified by:
getAnnotationMetadataBuilderin interfaceVisitorContext- Returns:
- The annotation metadata builder
-
info
Description copied from interface:VisitorContextAllows printing informational messages.- Specified by:
infoin interfaceVisitorContext- Parameters:
message- The messageelement- The element
-
info
Description copied from interface:VisitorContextAllows printing informational messages.- Specified by:
infoin interfaceVisitorContext- Parameters:
message- The message
-
fail
Description copied from interface:VisitorContextAllows failing compilation for a given element with the given message.- Specified by:
failin interfaceVisitorContext- Parameters:
message- The messageelement- The element
-
fail
-
warn
Description copied from interface:VisitorContextAllows printing a warning for the given message and element.- Specified by:
warnin interfaceVisitorContext- Parameters:
message- The messageelement- The element
-
visitClass
public OutputStream visitClass(String classname, @Nullable @Nullable Element originatingElement) throws IOException Description copied from interface:ClassWriterOutputVisitorVisits a new class and returns the output stream with which should be written the bytes of the class to be generated.- Specified by:
visitClassin 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:ClassWriterOutputVisitorVisits 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.AGGREGATINGvisitor from within theTypeElementVisitor.finish(io.micronaut.inject.visitor.VisitorContext)method. If the file- Specified by:
visitClassin 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:ClassWriterOutputVisitorAllows adding a class that will be written to theMETA-INF/servicesfile under the given type and class name.- Specified by:
visitServiceDescriptorin interfaceClassWriterOutputVisitor- Parameters:
type- the fully qualified service nameclassname- the fully qualified classname
-
visitServiceDescriptor
Description copied from interface:ClassWriterOutputVisitorAllows adding a class that will be written to theMETA-INF/servicesfile under the given type and class name.- Specified by:
visitServiceDescriptorin interfaceClassWriterOutputVisitor- Parameters:
type- the fully qualified service nameclassname- the fully qualified classnameoriginatingElement- The originating element
-
visitMetaInfFile
Description copied from interface:VisitorContextVisit a file within the META-INF directory.- Specified by:
visitMetaInfFilein interfaceClassWriterOutputVisitor- Specified by:
visitMetaInfFilein 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:VisitorContextVisit a file that will be located within the generated source directory.- Specified by:
visitGeneratedFilein interfaceClassWriterOutputVisitor- Specified by:
visitGeneratedFilein interfaceVisitorContext- Parameters:
path- The path to the file- Returns:
- An optional file it was possible to create it
-
visitGeneratedFile
Description copied from interface:ClassWriterOutputVisitorVisit a file that will be generated within the generated 'sources' directory.- Specified by:
visitGeneratedFilein 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:ClassWriterOutputVisitorVisit a source file that will be generated within the generated 'sources' directory.- Specified by:
visitGeneratedSourceFilein 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:ClassWriterOutputVisitorFinish writing and flush any service entries to disk.- Specified by:
finishin interfaceClassWriterOutputVisitor
-
getCompilationUnit
- Returns:
- The compilation unit
-
getNativeElementHelper
- Returns:
- The native element helper
-
getOptions
Groovy options source areSystem.getProperties()based.All properties MUST start with
VisitorContext.MICRONAUT_BASE_OPTION_NAME- Specified by:
getOptionsin interfaceVisitorContext- Returns:
- options
Map - See Also:
-
put
Description copied from interface:MutableConvertibleValuesInsert a value for the given key and value.- Specified by:
putin interfaceMutableConvertibleValues<Object>- Parameters:
key- The keyvalue- The value- Returns:
- This values instance
-
remove
Description copied from interface:MutableConvertibleValuesRemove a value for the given key.- Specified by:
removein interfaceMutableConvertibleValues<Object>- Parameters:
key- The key- Returns:
- This values instance
-
clear
Description copied from interface:MutableConvertibleValuesClear all values.- Specified by:
clearin interfaceMutableConvertibleValues<Object>- Returns:
- This values instance
-
names
- Specified by:
namesin interfaceConvertibleValues<Object>- Returns:
- The names of the values
-
values
- Specified by:
valuesin interfaceConvertibleValues<Object>- Returns:
- The values
-
get
Description copied from interface:ValueResolverResolve the given property for the given name.- Specified by:
getin 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:VisitorContextProvide 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:
getGeneratedResourcesin interfaceVisitorContext- Returns:
- a possibly empty collection of resource paths
-
addGeneratedResource
Description copied from interface:VisitorContextSome 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:
addGeneratedResourcein interfaceVisitorContext- Parameters:
resource- the relative path to add
-
getBeanElementBuilders
- Returns:
- Gets the produced bean definition builders.
-