Class PythonEnumConstantElement

java.lang.Object
io.micronaut.inject.ast.annotation.AbstractAnnotationElement
io.micronaut.python.processing.visitor.PythonEnumConstantElement
All Implemented Interfaces:
AnnotatedElement, AnnotationMetadata, AnnotationMetadataDelegate, AnnotationMetadataProvider, AnnotationSource, Described, Named, MutableAnnotationMetadataDelegate<Element>, Element, EnumConstantElement, FieldElement, MemberElement, TypedElement

public final class PythonEnumConstantElement extends AbstractAnnotationElement implements EnumConstantElement
Represents a Python enum constant as a Micronaut EnumConstantElement.

This class wraps an AttributeDef node representing an enum constant and provides the EnumConstantElement interface implementation.

Since:
5.2.0
Author:
Micronaut Team
  • Constructor Details

    • PythonEnumConstantElement

      public PythonEnumConstantElement(AttributeDef attributeDef, PythonProcessingEnvironment environment, PythonEnumElement declaringType, PythonEnumElement owningType, ElementAnnotationMetadataFactory metadataFactory)
      Constructs a new PythonEnumConstantElement from the given AttributeDef.
      Parameters:
      attributeDef - the attribute definition representing the enum constant; must not be null
      environment - the Python processing environment; must not be null
      declaringType - the enum class that declares this constant; must not be null
      owningType - the enum class that owns this constant (may be a subclass); must not be null
      metadataFactory - the annotation metadata factory; must not be null
      Throws:
      NullPointerException - if any parameter is null
  • Method Details

    • getNativeType

      public AttributeDef 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
    • getType

      public ClassElement getType()
      Specified by:
      getType in interface TypedElement
      Returns:
      The type of the element
    • 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
    • getConstantValue

      public Object getConstantValue()
      Description copied from interface: FieldElement
      Returns the value of this variable if this is a final field initialized to a compile-time constant. Returns null otherwise. The value will be of a primitive type or a String. If the value is of a primitive type, it is wrapped in the appropriate wrapper class (such as Integer).

      Note that not all final fields will have constant values. In particular, enum constants are not considered to be compile-time constants. To have a constant value, a field's type must be either a primitive type or String.

      Specified by:
      getConstantValue in interface FieldElement
      Returns:
      the value of this variable if this is a final field initialized to a compile-time constant, or null otherwise
    • isStatic

      public boolean isStatic()
      Specified by:
      isStatic in interface Element
      Returns:
      True if the element is static.
    • isFinal

      public boolean isFinal()
      Specified by:
      isFinal in interface Element
      Returns:
      True if the element is final.
    • getDeclaringType

      public ClassElement getDeclaringType()
      Specified by:
      getDeclaringType in interface MemberElement
      Returns:
      The declaring type of the element.
    • getOwningType

      public ClassElement getOwningType()
      Description copied from interface: MemberElement
      The owning type is the type that owns this element. This can differ from MemberElement.getDeclaringType() in the case of inheritance since this method will return the subclass that owners the inherited member, whilst MemberElement.getDeclaringType() will return the super class that declares the type.
      Specified by:
      getOwningType in interface MemberElement
      Returns:
      The owning type.
    • copyThis

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

      public EnumConstantElement 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 FieldElement
      Specified by:
      withAnnotationMetadata in interface MemberElement
      Parameters:
      annotationMetadata - The annotation metadata
      Returns:
      A new element
    • copyValues

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

      protected final io.micronaut.python.processing.visitor.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.
    • equals

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

      public int hashCode()
      Overrides:
      hashCode in class Object