Class PythonElementAnnotationMetadataFactory
java.lang.Object
io.micronaut.inject.ast.annotation.AbstractElementAnnotationMetadataFactory<ElementDef, DecoratorDef>
io.micronaut.python.processing.annotation.PythonElementAnnotationMetadataFactory
- All Implemented Interfaces:
ElementAnnotationMetadataFactory
public class PythonElementAnnotationMetadataFactory
extends AbstractElementAnnotationMetadataFactory<ElementDef, DecoratorDef>
Factory for creating and managing annotation metadata for Python elements.
This class extends AbstractElementAnnotationMetadataFactory and provides
support for reading and building annotation metadata based on Python decorators.
The factory delegates annotation processing logic to PythonAnnotationMetadataBuilder.
The metadata factory may be used in either a read-only or mutable context, depending
on how it is constructed. To enforce immutability, use readOnly() to obtain a read-only factory.
Typical usage:
PythonAnnotationMetadataBuilder builder = ...;
PythonElementAnnotationMetadataFactory factory =
new PythonElementAnnotationMetadataFactory(false, builder);
ElementAnnotationMetadata metadata = factory.build(someElement);
- Since:
- 5.2.0
-
Nested Class Summary
Nested classes/interfaces inherited from class AbstractElementAnnotationMetadataFactory
AbstractElementAnnotationMetadataFactory.AbstractElementAnnotationMetadata, AbstractElementAnnotationMetadataFactory.MutableElementAnnotationMetadata -
Field Summary
Fields inherited from class AbstractElementAnnotationMetadataFactory
isReadOnly, metadataBuilder -
Constructor Summary
ConstructorsConstructorDescriptionPythonElementAnnotationMetadataFactory(boolean isReadOnly, PythonAnnotationMetadataBuilder annotationMetadataBuilder) Constructs a new factory for Python element annotation metadata. -
Method Summary
Modifier and TypeMethodDescriptionbuildTypeUseAnnotations(TypeRef typeNode, ElementDef typeUseElement) The type-use annotation metadata of one type node of a Python source: the decorators of anAnnotated[...]type argument, or the synthetic nullability of a union.lookupForMethod(MethodElement methodElement) Lookup annotation metadata for the method.lookupForParameter(ParameterElement parameterElement) Lookup annotation metadata for the parameter.lookupTypeAnnotationsForClass(ClassElement classElement) Lookup annotation metadata for the class.readOnly()Creates a read-only version of this element annotation metadata factory.Methods inherited from class AbstractElementAnnotationMetadataFactory
build, buildGenericTypeAnnotations, buildMutable, buildTypeAnnotations, getNativeElement, lookupForClass, lookupForField, lookupForField, lookupForPackage, lookupTypeAnnotationsForGenericPlaceholder, lookupTypeAnnotationsForWildcard
-
Constructor Details
-
PythonElementAnnotationMetadataFactory
public PythonElementAnnotationMetadataFactory(boolean isReadOnly, PythonAnnotationMetadataBuilder annotationMetadataBuilder) Constructs a new factory for Python element annotation metadata.- Parameters:
isReadOnly- Whether the factory should operate in read-only mode (no shared cache modifications).annotationMetadataBuilder- The annotation metadata builder used to introspect Python decorators.
-
-
Method Details
-
readOnly
Creates a read-only version of this element annotation metadata factory. No modifications to annotation metadata will be persisted within the shared cache.- Returns:
- a read-only element annotation metadata factory
-
buildTypeUseAnnotations
public ElementAnnotationMetadata buildTypeUseAnnotations(TypeRef typeNode, ElementDef typeUseElement) The type-use annotation metadata of one type node of a Python source: the decorators of anAnnotated[...]type argument, or the synthetic nullability of a union. Every resolution of the same node answers the same mutable metadata, so an annotation a visitor adds to a type argument (the validation visitor marks the constrained element type of a collection parameter) is still there when the argument metadata is written, like the type-use annotations of a Java type argument.- Parameters:
typeNode- The type node the metadata belongs totypeUseElement- The synthetic element carrying the decorators of the node- Returns:
- The metadata
-
lookupTypeAnnotationsForClass
protected AbstractAnnotationMetadataBuilder.CachedAnnotationMetadata lookupTypeAnnotationsForClass(ClassElement classElement) Description copied from class:AbstractElementAnnotationMetadataFactoryLookup annotation metadata for the class.- Overrides:
lookupTypeAnnotationsForClassin classAbstractElementAnnotationMetadataFactory<ElementDef, DecoratorDef>- Parameters:
classElement- The element- Returns:
- The annotation metadata
-
lookupForMethod
protected AbstractAnnotationMetadataBuilder.CachedAnnotationMetadata lookupForMethod(MethodElement methodElement) Description copied from class:AbstractElementAnnotationMetadataFactoryLookup annotation metadata for the method.- Overrides:
lookupForMethodin classAbstractElementAnnotationMetadataFactory<ElementDef, DecoratorDef>- Parameters:
methodElement- The element- Returns:
- The annotation metadata
-
lookupForParameter
protected AbstractAnnotationMetadataBuilder.CachedAnnotationMetadata lookupForParameter(ParameterElement parameterElement) Description copied from class:AbstractElementAnnotationMetadataFactoryLookup annotation metadata for the parameter. The entry is keyed by the declaring type of the method, not by the owning type, so that a parameter of an inherited method shares one entry whichever class it is read through.- Overrides:
lookupForParameterin classAbstractElementAnnotationMetadataFactory<ElementDef, DecoratorDef>- Parameters:
parameterElement- The element- Returns:
- The annotation metadata
-