Class PythonClassElement
- All Implemented Interfaces:
ElementProvider, AnnotatedElement, AnnotationMetadata, AnnotationMetadataDelegate, AnnotationMetadataProvider, AnnotationSource, Described, Named, MutableAnnotationMetadataDelegate<Element>, ArrayableClassElement, ClassElement, Element, TypedElement
- Direct Known Subclasses:
PythonAnnotationElement
-
Field Summary
Fields inherited from class AbstractPythonClassElement
arrayDimensions, environment, PYTHON_DEFAULT_PACKAGE, typeAnnotationsKeyFields inherited from class AbstractAnnotationElement
elementAnnotationMetadataFactory, presetAnnotationMetadataFields inherited from interface AnnotationMetadata
CLASS_NAME_SUFFIX, EMPTY_METADATA, VALUE_MEMBERFields inherited from interface AnnotationSource
EMPTYFields inherited from interface ClassElement
ZERO_CLASS_ELEMENTSFields inherited from interface Element
EMPTY_ELEMENT_ARRAYFields inherited from interface MutableAnnotationMetadataDelegate
EMPTY -
Constructor Summary
ConstructorsConstructorDescriptionPythonClassElement(ClassDef classDef, PythonProcessingEnvironment environment) PythonClassElement(ClassDef classDef, PythonProcessingEnvironment environment, int arrayDimensions) -
Method Summary
Modifier and TypeMethodDescriptionThis method adds an associated bean using this class element as the originating element.protected PythonClassElementcopyThis()protected voidcopyValues(io.micronaut.python.processing.element.AbstractPythonElement element) protected ClassElementcreateWithArrayDimensions(int arrayDimensions) booleanMap<String, Map<String, ClassElement>> Builds a map of all the type parameters for a class, its super classes and interfaces.This method will return the name of the underlying type automatically unwrapping in the case of an optional or wrapped representation of the type.@NonNull List<? extends GenericPlaceholderElement> The type arguments declared on the raw class.Find and return a single default constructor.Returns the enclosing type ifClassElement.isInner()returntrue.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 withElement.isPublic(),Element.isStatic(),Element.isAbstract()andElement.isFinal()for the callers that filter on modifiers, such asElementQuery.modifiers(...)andBeanElementBuilder.produceBeans(...).getName()Find and return a single primary constructor.Returns the super type of this element or empty if the element has no super type.@NonNull ClassElementgetType()inthashCode()voidDerives the class level metadata that depends on the annotations of the class definition: the introspection excludes, the bean stereotype of a class with property injection points and the interfaces introduced by an introduction advice.booleanisAssignable(String type) Tests whether one type is assignable to another.static booleanisCallableWithoutArguments(MethodElement constructor) Whether the given__init__takes parameters that all have a default value, so the Python class can be instantiated without arguments.booleanWhether this class is decorated with@dataclass.booleanisInner()Is this type an inner class.booleanWhether the class compiles to a Java interface.booleanWhether this class is an interface implemented by an introduction proxy: it is decorated with anIntroductionstereotype andcompiles to a Java interface.booleanisIntroductionInterface(ClassElement anInterface) Whether the interface is implemented through an@Introductionof the class rather than declared as a base of the Python class.booleanWhether the Java class generated for this class is a member type of the Java class generated for the enclosing Python class.booleanbooleanisPublic()final booleanbooleanisStatic()protected final io.micronaut.python.processing.element.AbstractPythonElementmakeCopy()static PythonClassElementregistered(ClassDef classDef, PythonProcessingEnvironment environment) Creates the element of a Python class for the class registry of the processing environment without deriving its class level metadata yet:initializeClassMetadata()runs annotation mappers, which may look other Python classes up through the visitor context, so it is applied once every class of the environment is registered.toString()withTypeArguments(Map<String, ClassElement> typeArguments) Copies this element and overrides its type arguments.Methods inherited from class AbstractPythonClassElement
element, excludeIntrospectedProperties, findPythonClass, getAnnotationMetadata, getAnnotationMetadataToWrite, getArrayDimensions, getBeanProperties, getBeanProperties, getDocumentation, getEnclosedElements, getFields, getNativeType, getPackageName, getSyntheticBeanProperties, getTypeAnnotationMetadata, getTypeAnnotationsKey, isAbstract, isArray, withAnnotationMetadata, withArrayDimensionsMethods inherited from class AbstractAnnotationElement
annotate, annotate, annotate, annotate, annotate, getElementAnnotationMetadata, getElementAnnotationMetadataFactory, removeAnnotation, removeAnnotation, removeAnnotationIf, removeStereotype, removeStereotypeMethods inherited from interface AnnotatedElement
isDeclaredNonNull, isDeclaredNullable, isNonNull, isNullableMethods inherited from interface AnnotationMetadata
enumValuesSet, enumValuesSet, getValues, hasDeclaredStereotype, hasStereotypeNonRepeating, isAnnotationPresent, isDeclaredAnnotationPresentMethods inherited from interface AnnotationMetadataDelegate
booleanValue, booleanValue, booleanValue, booleanValue, classValue, classValue, classValue, classValue, classValues, classValues, classValues, classValues, copyAnnotationMetadata, doubleValue, doubleValue, doubleValue, enumValue, enumValue, enumValue, enumValue, enumValues, enumValues, enumValues, enumValues, findAnnotation, findAnnotation, findDeclaredAnnotation, findDeclaredAnnotation, findRepeatableAnnotation, findRepeatableAnnotation, getAnnotation, getAnnotation, getAnnotationNameByStereotype, getAnnotationNameByStereotype, getAnnotationNames, getAnnotationNamesByStereotype, getAnnotationNamesByStereotype, getAnnotationType, getAnnotationType, getAnnotationTypeByStereotype, getAnnotationTypeByStereotype, getAnnotationTypesByStereotype, getAnnotationTypesByStereotype, getAnnotationTypesByStereotype, getAnnotationValuesByName, getAnnotationValuesByStereotype, getAnnotationValuesByType, getDeclaredAnnotation, getDeclaredAnnotation, getDeclaredAnnotationNameByStereotype, getDeclaredAnnotationNames, getDeclaredAnnotationNamesByStereotype, getDeclaredAnnotationTypeByStereotype, getDeclaredAnnotationTypeByStereotype, getDeclaredAnnotationValuesByName, getDeclaredAnnotationValuesByType, getDeclaredMetadata, getDeclaredStereotypeAnnotationNames, getDefaultValue, getDefaultValue, getDefaultValue, getDefaultValue, getDefaultValues, getStereotypeAnnotationNames, getTargetAnnotationMetadata, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValues, getValues, hasAnnotation, hasAnnotation, hasDeclaredAnnotation, hasDeclaredAnnotation, hasDeclaredStereotype, hasDeclaredStereotype, hasDeclaredStereotype, hasEvaluatedExpressions, hasPropertyExpressions, hasSimpleAnnotation, hasSimpleDeclaredAnnotation, hasStereotype, hasStereotype, hasStereotype, hasStereotype, intValue, intValue, intValue, isAnnotationPresent, isDeclaredAnnotationPresent, isEmpty, isFalse, isFalse, isPresent, isPresent, isRepeatableAnnotation, isRepeatableAnnotation, isTrue, isTrue, longValue, longValue, stringValue, stringValue, stringValue, stringValue, stringValues, stringValues, stringValues, stringValues, synthesize, synthesize, synthesizeAll, synthesizeAnnotationsByType, synthesizeDeclared, synthesizeDeclared, synthesizeDeclared, synthesizeDeclaredAnnotationsByTypeMethods inherited from interface ArrayableClassElement
fromArray, toArrayMethods inherited from interface ClassElement
findDefaultStaticCreator, findField, findMethod, findStaticCreator, foldBoundGenericTypes, getAccessibleConstructors, getAccessibleStaticCreators, getBoundGenericTypes, getEnclosedElement, getFirstTypeArgument, getMethods, getOptionalValueType, getPackage, getPermittedSubclasses, getRawClassElement, getSimpleName, getTypeArguments, getTypeArguments, hasUnresolvedTypes, isAssignable, isAssignable, isContainerType, isEnum, isGenericPlaceholder, isIterable, isOptional, isProxy, isRawType, isRecord, isSealed, isTypeVariable, isWildcard, withBoundGenericTypes, withTypeArgumentsMethods inherited from interface Element
annotate, annotate, annotate, annotate, annotate, getDescription, getDescription, getDocumentation, getModifiers, getName, isFinal, isPackagePrivate, isPrivate, isProtected, isPublic, isSynthetic, removeAnnotation, removeAnnotation, removeAnnotationIf, removeStereotype, removeStereotypeMethods inherited from interface TypedElement
getGenericType, isPrimitive, isVoid
-
Constructor Details
-
PythonClassElement
-
PythonClassElement
public PythonClassElement(ClassDef classDef, PythonProcessingEnvironment environment, int arrayDimensions)
-
-
Method Details
-
registered
@Internal public static PythonClassElement registered(ClassDef classDef, PythonProcessingEnvironment environment) Creates the element of a Python class for the class registry of the processing environment without deriving its class level metadata yet:initializeClassMetadata()runs annotation mappers, which may look other Python classes up through the visitor context, so it is applied once every class of the environment is registered.- Parameters:
classDef- The class definitionenvironment- The processing environment- Returns:
- The element
-
initializeClassMetadata
Derives the class level metadata that depends on the annotations of the class definition: the introspection excludes, the bean stereotype of a class with property injection points and the interfaces introduced by an introduction advice. Building that metadata runs the annotation mappers of the class annotations. -
getType
- Returns:
- The type of the element
-
copyThis
- Specified by:
copyThisin classAbstractPythonClassElement- Returns:
- copy of this element
-
copyValues
protected void copyValues(io.micronaut.python.processing.element.AbstractPythonElement element) - Overrides:
copyValuesin classAbstractPythonClassElement- Parameters:
element- the values to be copied to
-
isPythonSource
public final boolean isPythonSource() -
addAssociatedBean
Description copied from interface:ClassElementThis method adds an associated bean using this class element as the originating element.Note that this method can only be called on classes being directly compiled by Micronaut. If the ClassElement is loaded from pre-compiled code an
UnsupportedOperationExceptionwill be thrown.- Parameters:
type- The type of the bean- Returns:
- A bean builder
-
isInner
public boolean isInner()Description copied from interface:ClassElementIs this type an inner class.- Returns:
- True if it is an inner class
-
isStatic
public boolean isStatic()- Returns:
- True if the element is static.
-
getEnclosingType
Description copied from interface:ClassElementReturns the enclosing type ifClassElement.isInner()returntrue.- Returns:
- The enclosing type if any
-
isMemberOfEnclosingType
public boolean isMemberOfEnclosingType()Whether the Java class generated for this class is a member type of the Java class generated for the enclosing Python class.A class nested in a Python class compiles to a member type of the generated class of its enclosing class (binary name
Outer$Inner, as before), so that Java sees the nesting: JUnit runs a@Nestedtest class with the context of the enclosing@MicronautTest. Enums, interfaces and pooled classes are generated as top-level types namedOuter$Inner, whether they are nested or enclose other classes.- Returns:
truewhen the generated class is a member type of the enclosing generated class
-
getCanonicalName
Description copied from interface:ClassElementThis method will return the name of the underlying type automatically unwrapping in the case of an optional or wrapped representation of the type.- Returns:
- Returns the canonical name of the type.
-
createWithArrayDimensions
- Specified by:
createWithArrayDimensionsin classAbstractPythonClassElement
-
toString
-
getDefaultConstructor
Description copied from interface:ClassElementFind and return a single default constructor. A default constructor is one without arguments that is accessible.- Returns:
- The default constructor if one is present
-
isCallableWithoutArguments
Whether the given__init__takes parameters that all have a default value, so the Python class can be instantiated without arguments.- Parameters:
constructor- The constructor- Returns:
- True if it is a constructor whose parameters all have defaults
-
getPrimaryConstructor
Description copied from interface:ClassElementFind and return a single primary constructor. If more than constructor candidate exists, then return empty unless a constructor is found that is annotated with eitherCreatororAnnotationUtil.INJECT.- Returns:
- The primary constructor if one is present
-
isDataclass
public boolean isDataclass()Whether this class is decorated with@dataclass.- Returns:
truefor a Python dataclass
-
isAssignable
Description copied from interface:ClassElementTests whether one type is assignable to another.- Parameters:
type- The type to check- Returns:
trueif and only if this type is assignable to the second
-
isIntroductionInterface
Whether the interface is implemented through an@Introductionof the class rather than declared as a base of the Python class. The proxy of the class implements its methods.- Parameters:
anInterface- The interface- Returns:
- Whether it is an introduction interface
-
getInterfaces
- Specified by:
getInterfacesin interfaceClassElement- Overrides:
getInterfacesin classAbstractPythonClassElement- Returns:
- The interfaces implemented by this class element
-
isInterface
public boolean isInterface()Whether the class compiles to a Java interface. A class is an interface when it has no state (no constructor, attributes or properties) and only declares abstract methods, in one of two shapes:- a plain abstract class or
Protocolwithout a bean or interceptor stereotype, the Python spelling of a Java interface; - an
introduction interface: a class decorated with anIntroductionstereotype (@Client, an AI service, ...) that has no class base and whose instance methods are all abstract, none of which declares a*argsparameter. Micronaut implements such a type with an introduction proxy, and frameworks that build the implementation reflectively need the Java interface, not a class wrapping a Python object.
- Returns:
- True if the class compiles to an interface
- a plain abstract class or
-
isIntroductionInterface
public boolean isIntroductionInterface()Whether this class is an interface implemented by an introduction proxy: it is decorated with anIntroductionstereotype andcompiles to a Java interface.- Returns:
- True if the class is an introduction interface
-
getSuperType
Description copied from interface:ClassElementReturns the super type of this element or empty if the element has no super type.- Returns:
- An optional of the super type
-
getTypeArguments
- Returns:
- The type arguments for this class element
-
getAllTypeArguments
Description copied from interface:ClassElementBuilds a map of all the type parameters for a class, its super classes and interfaces. The resulting map contains the name of the class to the map of the resolved generic types.The arguments of every super type are expressed in the type arguments of this class: a
Reversedthat extendsHashMapwith its own two variables swapped answers with those two variables, in that swapped order, forHashMapand forMapalike.- Returns:
- The type arguments for this class element
-
withTypeArguments
Description copied from interface:ClassElementCopies this element and overrides its type arguments.- Parameters:
typeArguments- The type arguments- Returns:
- A new element
-
getDeclaredGenericPlaceholders
Description copied from interface:ClassElementThe type arguments declared on the raw class. Independent of the actualbound type arguments.This method will resolve the generic placeholders defined of the declaring class, if any.
For example
List<String>will result a single placeholder calledEof typeObject.- Returns:
- The type arguments declared on this class.
-
makeCopy
protected final io.micronaut.python.processing.element.AbstractPythonElement makeCopy() -
getName
-
isProtected
public boolean isProtected()- Specified by:
isProtectedin interfaceElement- Returns:
- True if the element is protected.
-
isPublic
-
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 withElement.isPublic(),Element.isStatic(),Element.isAbstract()andElement.isFinal()for the callers that filter on modifiers, such asElementQuery.modifiers(...)andBeanElementBuilder.produceBeans(...).- Specified by:
getModifiersin interfaceElement- Returns:
- The modifiers
-
equals
-
hashCode
-