Class JavaVisitorContext
java.lang.Object
io.micronaut.annotation.processing.visitor.JavaVisitorContext
- All Implemented Interfaces:
ConversionServiceProvider,ConvertibleValues<Object>,MutableConvertibleValues<Object>,ValueResolver<CharSequence>,BeanElementVisitorContext,VisitorContext,ClassWriterOutputVisitor,Iterable<Map.Entry<String,Object>>
@Internal
public final class JavaVisitorContext
extends Object
implements VisitorContext, BeanElementVisitorContext
The visitor context when visiting Java code.
- Since:
- 1.0
- Author:
- James Kleeh
-
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
ConstructorsConstructorDescriptionJavaVisitorContext(ProcessingEnvironment processingEnv, Messager messager, Elements elements, AnnotationUtils annotationUtils, Types types, ModelUtils modelUtils, GenericUtils genericUtils, Filer filer, MutableConvertibleValues<Object> visitorAttributes, TypeElementVisitor.VisitorKind visitorKind) Deprecated, for removal: This API element is subject to removal in a future version.No longer neededJavaVisitorContext(ProcessingEnvironment processingEnv, Messager messager, Elements elements, Types types, ModelUtils modelUtils, Filer filer, MutableConvertibleValues<Object> visitorAttributes, TypeElementVisitor.VisitorKind visitorKind) Deprecated, for removal: This API element is subject to removal in a future version.No longer neededJavaVisitorContext(ProcessingEnvironment processingEnv, Messager messager, Elements elements, Types types, ModelUtils modelUtils, Filer filer, MutableConvertibleValues<Object> visitorAttributes, TypeElementVisitor.VisitorKind visitorKind, Set<String> postponedTypes) The default constructor. -
Method Summary
Modifier and TypeMethodDescriptionaddAssociatedBean(Element originatingElement, ClassElement type) voidaddGeneratedResource(@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.voidfinish()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.Deprecated, for removal: This API element is subject to removal in a future version.No longer usedgetClassElement(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.Gets the element annotation metadata factory.Gets the element factory for this visitor context.The elements.Provide a collection of generated classpath resources that other TypeElement visitors might want to consume.Deprecated, for removal: This API element is subject to removal in a future version.No longer usedThe messager.The model utils.Java visitor context options fromjavacarguments andSystem.getProperties()getTypes()The types.voidAllows printing informational messages.voidAllows printing informational messages.booleannames()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.voidsetVisitUnresolvedInterfaces(boolean visitUnresolvedInterfaces) values()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.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.voidPrint warning message.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
getClassElement, getClassesOutputPath, getConfiguration, getProjectDir, getRequiredClassElement
-
Constructor Details
-
JavaVisitorContext
@Deprecated(forRemoval=true, since="4.3.0") public JavaVisitorContext(ProcessingEnvironment processingEnv, Messager messager, Elements elements, AnnotationUtils annotationUtils, Types types, ModelUtils modelUtils, GenericUtils genericUtils, Filer filer, MutableConvertibleValues<Object> visitorAttributes, TypeElementVisitor.VisitorKind visitorKind) Deprecated, for removal: This API element is subject to removal in a future version.No longer neededThe default constructor.- Parameters:
processingEnv- The processing environmentmessager- The messagerelements- The elementsannotationUtils- The annotation utilstypes- Type typesmodelUtils- The model utilsgenericUtils- The generic type utilsfiler- The filervisitorAttributes- The attributesvisitorKind- The visitor kind
-
JavaVisitorContext
@Deprecated(forRemoval=true, since="4.7.0") public JavaVisitorContext(ProcessingEnvironment processingEnv, Messager messager, Elements elements, Types types, ModelUtils modelUtils, Filer filer, MutableConvertibleValues<Object> visitorAttributes, TypeElementVisitor.VisitorKind visitorKind) Deprecated, for removal: This API element is subject to removal in a future version.No longer neededThe default constructor.- Parameters:
processingEnv- The processing environmentmessager- The messagerelements- The elementstypes- Type typesmodelUtils- The model utilsfiler- The filervisitorAttributes- The attributesvisitorKind- The visitor kind
-
JavaVisitorContext
public JavaVisitorContext(ProcessingEnvironment processingEnv, Messager messager, Elements elements, Types types, ModelUtils modelUtils, Filer filer, MutableConvertibleValues<Object> visitorAttributes, TypeElementVisitor.VisitorKind visitorKind, Set<String> postponedTypes) The default constructor.- Parameters:
processingEnv- The processing environmentmessager- The messagerelements- The elementstypes- Type typesmodelUtils- The model utilsfiler- The filervisitorAttributes- The attributesvisitorKind- The visitor kindpostponedTypes- The postponed types
-
-
Method Details
-
getLanguage
- Specified by:
getLanguagein interfaceVisitorContext- Returns:
- The visitor context's language.
-
getVisitorKind
- Returns:
- The visitor kind
-
getProcessingEnv
- Returns:
- The processing environment
-
isVisitUnresolvedInterfaces
public boolean isVisitUnresolvedInterfaces()- Returns:
- True if the unresolved interfaces should be visited
- Since:
- 4.9
-
setVisitUnresolvedInterfaces
public void setVisitUnresolvedInterfaces(boolean visitUnresolvedInterfaces) - Parameters:
visitUnresolvedInterfaces- True to visit unresolved interfaces- Since:
- 4.9
-
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
-
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
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
-
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
-
warn
Print warning message.- Parameters:
message- The messageelement- The element- Since:
- 4.0.0
-
visitClass
public OutputStream visitClass(String classname, @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
-
getMessager
The messager.- Returns:
- The messager
-
getModelUtils
The model utils.- Returns:
- The model utils
-
getElements
The elements.- Returns:
- The elements
-
getAnnotationUtils
Deprecated, for removal: This API element is subject to removal in a future version.No longer usedThe annotation utils.- Returns:
- The annotation utils
-
getTypes
The types.- Returns:
- The types
-
getGenericUtils
Deprecated, for removal: This API element is subject to removal in a future version.No longer usedThe generic utils object.- Returns:
- The generic utils
-
getNativeElementsHelper
- Returns:
- The elements helper
-
getOptions
Java visitor context options fromjavacarguments andSystem.getProperties()System properties has priority over arguments.
- Specified by:
getOptionsin interfaceVisitorContext- Returns:
- Java visitor context options for all visitors
- 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.
-
addAssociatedBean
- Specified by:
addAssociatedBeanin interfaceBeanElementVisitorContext
-