public class GroovyVisitorContext extends Object implements VisitorContext
MICRONAUT_BASE_OPTION_NAME, MICRONAUT_PROCESSING_GROUP, MICRONAUT_PROCESSING_MODULE, MICRONAUT_PROCESSING_PROJECT_DIR
EMPTY
Constructor and Description |
---|
GroovyVisitorContext(org.codehaus.groovy.control.SourceUnit sourceUnit,
org.codehaus.groovy.control.CompilationUnit compilationUnit) |
GroovyVisitorContext(org.codehaus.groovy.control.SourceUnit sourceUnit,
org.codehaus.groovy.control.CompilationUnit compilationUnit,
ClassWriterOutputVisitor outputVisitor) |
Modifier and Type | Method and Description |
---|---|
void |
addGeneratedResource(String resource)
Some TypeElementVisitors generate classpath resources that other visitors might be interested in.
|
MutableConvertibleValues<Object> |
clear()
Clear all values.
|
void |
fail(String message,
Element element)
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.
|
List<AbstractBeanDefinitionBuilder> |
getBeanElementBuilders() |
Optional<ClassElement> |
getClassElement(Class<?> type)
This method will lookup another class element by name.
|
Optional<ClassElement> |
getClassElement(String name)
This method will lookup another class element by name.
|
ClassElement[] |
getClassElements(String aPackage,
String... stereotypes)
Find all the classes within the given package and having the given annotation.
|
Iterable<URL> |
getClasspathResources(String path)
Obtain a set of resources from the user classpath.
|
org.codehaus.groovy.control.CompilationUnit |
getCompilationUnit() |
GroovyElementFactory |
getElementFactory()
Gets the element factory for this visitor context.
|
Collection<String> |
getGeneratedResources()
Provide a collection of generated classpath resources that other TypeElement visitors might want to consume.
|
Map<String,String> |
getOptions()
Groovy options source are
System.getProperties() based. |
void |
info(String message)
Allows printing informational messages.
|
void |
info(String message,
Element element)
Allows printing informational messages.
|
Set<String> |
names() |
MutableConvertibleValues<Object> |
put(CharSequence key,
Object value)
Insert a value for the given key and value.
|
MutableConvertibleValues<Object> |
remove(CharSequence key)
Remove a value for the given key.
|
Collection<Object> |
values() |
OutputStream |
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.
|
OutputStream |
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.
|
Optional<GeneratedFile> |
visitGeneratedFile(String path)
Visit a file that will be located within the generated source directory.
|
Optional<GeneratedFile> |
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 the
META-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 the
META-INF/services file under the given type and class
name. |
void |
warn(String message,
Element element)
Allows printing a warning for the given message and element.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getClassesOutputPath, getConfiguration, getProjectDir, visitMetaInfFile
of, putAll, putAll
asMap, asMap, asProperties, contains, empty, forEach, getValue, getValueType, isEmpty, iterator, subMap, subMap, subMap
get, get, get
forEach, spliterator
getServiceEntries, visitClass, visitServiceDescriptor, visitServiceDescriptor
public GroovyVisitorContext(org.codehaus.groovy.control.SourceUnit sourceUnit, @Nullable org.codehaus.groovy.control.CompilationUnit compilationUnit)
sourceUnit
- The source unitcompilationUnit
- The compilation unitpublic GroovyVisitorContext(org.codehaus.groovy.control.SourceUnit sourceUnit, @Nullable org.codehaus.groovy.control.CompilationUnit compilationUnit, ClassWriterOutputVisitor outputVisitor)
sourceUnit
- The source unitcompilationUnit
- The compilation unitoutputVisitor
- The class writer output visitor@NonNull public Iterable<URL> getClasspathResources(@NonNull String path)
VisitorContext
getClasspathResources
in interface VisitorContext
path
- The pathpublic Optional<ClassElement> getClassElement(String name)
VisitorContext
getClassElement
in interface VisitorContext
name
- The namepublic Optional<ClassElement> getClassElement(Class<?> type)
VisitorContext
getClassElement
in interface VisitorContext
type
- The name@NonNull public ClassElement[] getClassElements(@NonNull String aPackage, @NonNull String... stereotypes)
VisitorContext
getClassElements
in interface VisitorContext
aPackage
- The packagestereotypes
- The stereotypes@NonNull public GroovyElementFactory getElementFactory()
VisitorContext
getElementFactory
in interface VisitorContext
public void info(String message, @Nullable Element element)
VisitorContext
info
in interface VisitorContext
message
- The messageelement
- The elementpublic void info(String message)
VisitorContext
info
in interface VisitorContext
message
- The messagepublic void fail(String message, @Nullable Element element)
VisitorContext
fail
in interface VisitorContext
message
- The messageelement
- The elementpublic void warn(String message, @Nullable Element element)
VisitorContext
warn
in interface VisitorContext
message
- The messageelement
- The elementpublic OutputStream visitClass(String classname, @Nullable Element originatingElement) throws IOException
ClassWriterOutputVisitor
visitClass
in interface ClassWriterOutputVisitor
classname
- the fully qualified classnameoriginatingElement
- The originating elementIOException
- if an error occurs creating the output streampublic OutputStream visitClass(String classname, Element... originatingElements) throws IOException
ClassWriterOutputVisitor
Note that this method should only be called from a TypeElementVisitor.VisitorKind.AGGREGATING
visitor from within the TypeElementVisitor.finish(io.micronaut.inject.visitor.VisitorContext)
method. If the file
visitClass
in interface ClassWriterOutputVisitor
classname
- the fully qualified classnameoriginatingElements
- The originating elementsIOException
- if an error occurs creating the output streampublic void visitServiceDescriptor(String type, String classname)
ClassWriterOutputVisitor
META-INF/services
file under the given type and class
name.visitServiceDescriptor
in interface ClassWriterOutputVisitor
type
- the fully qualified service nameclassname
- the fully qualified classnamepublic void visitServiceDescriptor(String type, String classname, Element originatingElement)
ClassWriterOutputVisitor
META-INF/services
file under the given type and class
name.visitServiceDescriptor
in interface ClassWriterOutputVisitor
type
- the fully qualified service nameclassname
- the fully qualified classnameoriginatingElement
- The originating elementpublic Optional<GeneratedFile> visitMetaInfFile(String path, Element... originatingElements)
VisitorContext
visitMetaInfFile
in interface VisitorContext
visitMetaInfFile
in interface ClassWriterOutputVisitor
path
- The path to the fileoriginatingElements
- The originating elementspublic Optional<GeneratedFile> visitGeneratedFile(String path)
VisitorContext
visitGeneratedFile
in interface VisitorContext
visitGeneratedFile
in interface ClassWriterOutputVisitor
path
- The path to the filepublic void finish()
ClassWriterOutputVisitor
finish
in interface ClassWriterOutputVisitor
@Internal public org.codehaus.groovy.control.CompilationUnit getCompilationUnit()
public Map<String,String> getOptions()
System.getProperties()
based.
All properties MUST start with VisitorContext.MICRONAUT_BASE_OPTION_NAME
getOptions
in interface VisitorContext
Map
ProcessingEnvironment.getOptions()
public MutableConvertibleValues<Object> put(CharSequence key, @Nullable Object value)
MutableConvertibleValues
put
in interface MutableConvertibleValues<Object>
key
- The keyvalue
- The valuepublic MutableConvertibleValues<Object> remove(CharSequence key)
MutableConvertibleValues
remove
in interface MutableConvertibleValues<Object>
key
- The keypublic MutableConvertibleValues<Object> clear()
MutableConvertibleValues
clear
in interface MutableConvertibleValues<Object>
public Set<String> names()
names
in interface ConvertibleValues<Object>
public Collection<Object> values()
values
in interface ConvertibleValues<Object>
public <T> Optional<T> get(CharSequence name, ArgumentConversionContext<T> conversionContext)
ValueResolver
get
in interface ValueResolver<CharSequence>
T
- The concrete typename
- The nameconversionContext
- The conversion contextpublic Collection<String> getGeneratedResources()
VisitorContext
getGeneratedResources
in interface VisitorContext
public void addGeneratedResource(@NonNull String resource)
VisitorContext
addGeneratedResource
in interface VisitorContext
resource
- the relative path to add@Internal public List<AbstractBeanDefinitionBuilder> getBeanElementBuilders()