Class PythonParameterElement

java.lang.Object
io.micronaut.inject.ast.annotation.AbstractAnnotationElement
io.micronaut.python.processing.element.PythonParameterElement
All Implemented Interfaces:
AnnotatedElement, AnnotationMetadata, AnnotationMetadataDelegate, AnnotationMetadataProvider, AnnotationSource, Described, Named, MutableAnnotationMetadataDelegate<Element>, Element, ParameterElement, TypedElement

public final class PythonParameterElement extends AbstractAnnotationElement implements ParameterElement
A parameter element representing a Python function parameter.

This class wraps parameter information from a Python function argument, providing type resolution and metadata for Micronaut's parameter processing.

Since:
5.2.0
Author:
Micronaut Team
  • Constructor Details

  • Method Details

    • getElementAnnotationMetadata

      protected ElementAnnotationMetadata getElementAnnotationMetadata()
      The annotation metadata read from this parameter: the annotations declared on the Python parameter, seen through those inherited from the overridden Java parameter, as for the parameters of an overriding Java method (the inherited ones are visible to hasAnnotation but not to hasDeclaredAnnotation).
      Overrides:
      getElementAnnotationMetadata in class AbstractAnnotationElement
      Returns:
      The element's annotation metadata
    • getAnnotationMetadataToWrite

      protected MutableAnnotationMetadataDelegate<?> getAnnotationMetadataToWrite()
      Annotations added by a visitor go to the metadata of the Python parameter itself, which is cached for the parameter: every view of the parameter (each query of the enclosed methods answers a new copy) sees them, the inherited metadata being a read-only view over it.
      Overrides:
      getAnnotationMetadataToWrite in class AbstractAnnotationElement
      Returns:
      The annotation metadata to write
    • getNativeType

      public ArgumentDef getNativeType()
      Description copied from interface: Element
      Returns the native underlying type. This API is extended by all inject language implementations. The object returned by this method will be the language native type the information is being retrieved from.
      Specified by:
      getNativeType in interface Element
      Returns:
      The native type
    • hasDefault

      public boolean hasDefault()
      Description copied from interface: ParameterElement
      Whether the parameter declares a default value in the source language, and is therefore optional at the call site.

      This reports only that a default exists. How the value is obtained is language specific and is deliberately not part of this contract:

      • some languages evaluate the default in the caller, in which case the language module may contribute an io.micronaut.inject.writer.ParameterDefaultValueProvider to supply it;
      • others evaluate it in the callee and require a dedicated calling convention, as KotlinParameterElement does.
      Specified by:
      hasDefault in interface ParameterElement
      Returns:
      True if the parameter has a default value
    • getType

      public ClassElement getType()
      Specified by:
      getType in interface ParameterElement
      Specified by:
      getType in interface TypedElement
      Returns:
      The type of the parameter
    • getGenericType

      public ClassElement getGenericType()
      Description copied from interface: TypedElement
      Returns the generic type of the element. This differs from TypedElement.getType() as it returns the actual type without erasure. Whilst TypedElement.getType() is often needed to produce the correct byte code when generating code via ASM, the getGenericType() method is more useful for documentation and other types of code generation.
      Specified by:
      getGenericType in interface TypedElement
      Returns:
      The generic type
    • isVariadic

      public boolean isVariadic()
      Returns:
      Whether this is the variadic (*args) parameter of its function
    • getMethodElement

      public PythonMethodElement getMethodElement()
      Description copied from interface: ParameterElement
      Return method associated with this parameter.
      Specified by:
      getMethodElement in interface ParameterElement
      Returns:
      The method element
    • getDocumentation

      public Optional<String> getDocumentation(boolean parseContent)
      Specified by:
      getDocumentation in interface Element
      Parameters:
      parseContent - True if the content should be parsed to extract documentation
      Returns:
      The documentation, if any.
    • withInheritedType

      public PythonParameterElement withInheritedType(ClassElement type)
      Returns a copy of this parameter that reports the given type, the type of the corresponding parameter of the Java method the Python method overrides, in place of the one resolved from the Python hint. The copy remains a parameter of the Python method: it keeps the Python name, the method element and the annotation metadata.
      Parameters:
      type - The type of the overridden Java parameter
      Returns:
      The copy
    • withInheritedAnnotationMetadata

      public PythonParameterElement withInheritedAnnotationMetadata(AnnotationMetadata annotationMetadata)
      Returns a copy of this parameter that inherits the given annotation metadata, the annotations of the corresponding parameter of a method the Python method overrides (the constraints of a Java interface method). They are read through this parameter as inherited annotations, in addition to any inherited earlier, while annotations added to the copy go to the parameter's own metadata, so a visitor that annotates the parameter while inheriting annotations itself (the validation visitor) works on it.
      Parameters:
      annotationMetadata - The annotation metadata of the overridden parameter
      Returns:
      The copy
    • copyThis

      protected io.micronaut.python.processing.element.AbstractPythonElement copyThis()
      Returns:
      copy of this element
    • withAnnotationMetadata

      public ParameterElement withAnnotationMetadata(AnnotationMetadata annotationMetadata)
      Description copied from interface: Element
      Copies this element and overrides its annotations.
      Specified by:
      withAnnotationMetadata in interface Element
      Specified by:
      withAnnotationMetadata in interface ParameterElement
      Parameters:
      annotationMetadata - The annotation metadata
      Returns:
      A new element
    • copyValues

      protected void copyValues(io.micronaut.python.processing.element.AbstractPythonElement element)
      Parameters:
      element - the values to be copied to
    • makeCopy

      protected final io.micronaut.python.processing.element.AbstractPythonElement makeCopy()
    • getName

      public String getName()
      Specified by:
      getName in interface Element
      Specified by:
      getName in interface Named
      Returns:
      The name of the element. For a type this represents the binary name.
    • isProtected

      public boolean isProtected()
      Specified by:
      isProtected in interface Element
      Returns:
      True if the element is protected.
    • isPublic

      public boolean isPublic()
      Specified by:
      isPublic in interface Element
      Returns:
      True if the element is public.
    • getModifiers

      public Set<ElementModifier> getModifiers()
      Python has no access modifiers, so the modifiers are derived from the visibility, static, abstract and final predicates of the element: an element is public unless its name marks it private, which keeps the modifier set consistent with Element.isPublic(), Element.isStatic(), Element.isAbstract() and Element.isFinal() for the callers that filter on modifiers, such as ElementQuery.modifiers(...) and BeanElementBuilder.produceBeans(...).
      Specified by:
      getModifiers in interface Element
      Returns:
      The modifiers
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object