Class PythonMethodElement
- All Implemented Interfaces:
ElementProvider, AnnotatedElement, AnnotationMetadata, AnnotationMetadataDelegate, AnnotationMetadataProvider, AnnotationSource, Described, Named, MutableAnnotationMetadataDelegate<Element>, Element, MemberElement, MethodElement
- Direct Known Subclasses:
PythonConstructorElement
MethodElement.
This class wraps a FunctionDef node of the Python AST, providing full
MethodElement interface implementation including parameters, return types, and visibility.
- Since:
- 5.2.0
- Author:
- Micronaut Team
- See Also:
-
Field Summary
Fields 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 Element
EMPTY_ELEMENT_ARRAYFields inherited from interface MutableAnnotationMetadataDelegate
EMPTY -
Constructor Summary
ConstructorsConstructorDescriptionPythonMethodElement(FunctionDef functionDef, PythonProcessingEnvironment environment, ClassElement declaringType, ClassElement owningType, ElementAnnotationMetadataFactory metadataFactory) Constructs a newPythonMethodElementfrom the givenFunctionDef. -
Method Summary
Modifier and TypeMethodDescriptionprotected io.micronaut.python.processing.element.AbstractPythonElementcopyThis()protected voidcopyValues(io.micronaut.python.processing.element.AbstractPythonElement element) @Nullable Elementelement()booleanSupplies the metadata.protected MutableAnnotationMetadataDelegate<?> Get annotation metadata to add or remove annotations.List<? extends GenericPlaceholderElement> getDescription(boolean simple) Allows returning a more simple description if requested.getDocumentation(boolean parseContent) The generic return type of the method.Returns the method annotations.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()Returns the nativeFunctionDefobject that backs this element.Get overridden methods by this method.The owning type is the type that owns this element.Unwraps possible delegate or provider.inthashCode()booleanhasStereotype(@Nullable Class<? extends Annotation> annotation) Checks whether this object has the given annotation stereotype on the object itself or inherited from a parentbooleanhasStereotype(@Nullable String annotation) Checks whether this object has the given annotation stereotype on the object itself or inherited from a parentbooleanWhether the method is abstract.booleanisAsync()Returns whether this method was declared withasync def.booleanReturns whether this method is an async generator (async defwith ayield), bridged as aPublisherof its elements.booleanbooleanbooleanbooleanbooleanbooleanbooleanisPublic()booleanReturns whether this member element will require reflection to invoke or retrieve at runtime.booleanisReflectionRequired(ClassElement callingType) Returns whether this member element will require reflection to invoke or retrieve at runtime.booleanisStatic()booleanIf method has varargs parameter.protected final io.micronaut.python.processing.element.AbstractPythonElementmakeCopy()withAnnotationMetadata(AnnotationMetadata annotationMetadata) Copies this element and overrides its annotations.withInheritedSignature(ParameterElement[] newParameters, @Nullable ClassElement newReturnType) Returns a copy of this method that reports the given signature instead of the one derived from the Python type hints.@NonNull MethodElementwithNewOwningType(@NonNull ClassElement owningType) Returns a new method with a new owning type.@NonNull MethodElementwithNewParameters(@NotNull @NonNull ParameterElement... newParameters) Takes this method element and transforms into a new method element with the given parameters appended to the existing parameters.withParameters(ParameterElement... newParameters) Takes this method element and transforms into a new method element with the given parameters.Methods inherited from class AbstractAnnotationElement
annotate, annotate, annotate, annotate, annotate, getElementAnnotationMetadata, getElementAnnotationMetadataFactory, removeAnnotation, removeAnnotation, removeAnnotationIf, removeStereotype, removeStereotypeMethods inherited from class Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods 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, 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, 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 Element
annotate, annotate, annotate, annotate, annotate, getDescription, getDocumentation, getName, getSimpleName, isFinal, isPackagePrivate, isProtected, isSynthetic, removeAnnotation, removeAnnotation, removeAnnotationIf, removeStereotype, removeStereotypeMethods inherited from interface MemberElement
getModifiers, isAccessible, isAccessible, isAccessibleMethods inherited from interface MethodElement
addAssociatedBean, findParameterIndex, getDeclaredMethodAnnotationMetadata, getDeclaredTypeArguments, getParameter, getReceiverType, getSuspendParameters, getThrownTypes, getTypeArguments, hasParameters, hides, hides, isDefault, isSubSignature, isSuspend, overrides
-
Constructor Details
-
PythonMethodElement
public PythonMethodElement(FunctionDef functionDef, PythonProcessingEnvironment environment, ClassElement declaringType, ClassElement owningType, ElementAnnotationMetadataFactory metadataFactory) Constructs a newPythonMethodElementfrom the givenFunctionDef.- Parameters:
functionDef- the function definition node; must not benullenvironment- the Python processing environment; must not benulldeclaringType- the class that declares this method; must not benullowningType- the class that owns this method (may be a subclass); must not benullmetadataFactory- the annotation metadata factory; must not benull- Throws:
NullPointerException- if any parameter isnull
-
-
Method Details
-
getDescription
Description copied from interface:DescribedAllows returning a more simple description if requested.- Specified by:
getDescriptionin interfaceDescribed- Specified by:
getDescriptionin interfaceElement- Specified by:
getDescriptionin interfaceMethodElement- Parameters:
simple- True if a simple description is required- Returns:
- The simple description
-
withNewParameters
public @NonNull MethodElement withNewParameters(@NotNull @NotNull @NonNull ParameterElement... newParameters) Description copied from interface:MethodElementTakes this method element and transforms into a new method element with the given parameters appended to the existing parameters.- Specified by:
withNewParametersin interfaceMethodElement- Parameters:
newParameters- The new parameters- Returns:
- A new method element
-
withNewOwningType
Description copied from interface:MethodElementReturns a new method with a new owning type.- Specified by:
withNewOwningTypein interfaceMethodElement- Parameters:
owningType- The owning type.- Returns:
- A new method element
-
copyValues
protected void copyValues(io.micronaut.python.processing.element.AbstractPythonElement element) - Parameters:
element- the values to be copied to
-
isAbstract
public boolean isAbstract()Whether the method is abstract. A function decorated with@abstractmethod, declared by aProtocol, or declared by anABCwith the...placeholder body is abstract. A placeholder body is also abstract in anintroductiontype (@Client, a repository, an AI service), whose methods are implemented by the introduction advice; in a concrete class it is a method returningNone.- Specified by:
isAbstractin interfaceElement- Returns:
- True if the method is abstract
-
isAsync
public boolean isAsync()Returns whether this method was declared withasync def.- Returns:
- Whether this method was declared with
async def.
-
isAsyncGenerator
public boolean isAsyncGenerator()Returns whether this method is an async generator (async defwith ayield), bridged as aPublisherof its elements.- Returns:
- Whether this method is an async generator
-
getAnnotationMetadataToWrite
Description copied from class:AbstractAnnotationElementGet annotation metadata to add or remove annotations.- Overrides:
getAnnotationMetadataToWritein classAbstractAnnotationElement- Returns:
- The annotation metadata to write
-
getMethodAnnotationMetadata
Description copied from interface:MethodElementReturns the method annotations. The method will only return annotations defined on a method or inherited from the super methods, whileAnnotationMetadataProvider.getAnnotationMetadata()for a method combines the class and the method annotations. NOTE: For a constructorAnnotationMetadataProvider.getAnnotationMetadata()will not combine the class annotations. SeeMethodElement.getDeclaredMethodAnnotationMetadata()for the annotations of this declaration only.Implementations that support adding or removing annotations at compilation time are expected to override this method and return a delegate backed by the method's own mutable annotation metadata, typically built with
MethodElementAnnotationsHelper. Overriding it is a separate obligation from implementingElement.annotate(String, java.util.function.Consumer): an element that supports the latter and not this one still cannot be annotated through this surface. The default returned here cannot separate the method annotations from the class annotations, so it approximates the read side withAnnotationMetadataProvider.getAnnotationMetadata()and rejects the write side with an exception that names this element.- Specified by:
getMethodAnnotationMetadatain interfaceMethodElement- Returns:
- The method annotation metadata
-
getAnnotationMetadata
Description copied from interface:AnnotationMetadataProviderSupplies the metadata. Defaults toAnnotationMetadata.EMPTY_METADATA.- Specified by:
getAnnotationMetadatain interfaceAnnotationMetadataProvider- Overrides:
getAnnotationMetadatain classAbstractAnnotationElement- Returns:
- The
AnnotationMetadata
-
hasStereotype
Description copied from interface:AnnotationMetadataChecks whether this object has the given annotation stereotype on the object itself or inherited from a parent
.An annotation stereotype is a meta annotation potentially applied to another annotation
- Specified by:
hasStereotypein interfaceAnnotationMetadata- Specified by:
hasStereotypein interfaceAnnotationMetadataDelegate- Parameters:
annotation- The annotation- Returns:
- True if the annotation is present
-
hasStereotype
Description copied from interface:AnnotationMetadataChecks whether this object has the given annotation stereotype on the object itself or inherited from a parent
.An annotation stereotype is a meta annotation potentially applied to another annotation
- Specified by:
hasStereotypein interfaceAnnotationMetadata- Specified by:
hasStereotypein interfaceAnnotationMetadataDelegate- Parameters:
annotation- The annotation- Returns:
- True if the annotation is present
-
getTargetAnnotationMetadata
Description copied from interface:AnnotationSourceUnwraps possible delegate or provider.- Specified by:
getTargetAnnotationMetadatain interfaceAnnotationMetadata- Specified by:
getTargetAnnotationMetadatain interfaceAnnotationMetadataDelegate- Specified by:
getTargetAnnotationMetadatain interfaceAnnotationMetadataProvider- Specified by:
getTargetAnnotationMetadatain interfaceAnnotationSource- Returns:
- unwrapped
- See Also:
-
isReflectionRequired
public boolean isReflectionRequired()Description copied from interface:MemberElementReturns whether this member element will require reflection to invoke or retrieve at runtime.This method uses
MemberElement.getOwningType()as the calling type for this method.- Specified by:
isReflectionRequiredin interfaceMemberElement- Returns:
- Will return
trueif reflection is required.
-
isReflectionRequired
Description copied from interface:MemberElementReturns whether this member element will require reflection to invoke or retrieve at runtime.- Specified by:
isReflectionRequiredin interfaceMemberElement- Parameters:
callingType- The calling type- Returns:
- Will return
trueif reflection is required.
-
isStatic
-
getNativeType
Returns the nativeFunctionDefobject that backs this element.- Specified by:
getNativeTypein interfaceElement- Returns:
- the underlying
FunctionDefnode
-
getReturnType
- Specified by:
getReturnTypein interfaceMethodElement- Returns:
- The return type of the method
-
isDeclaredNullable
public boolean isDeclaredNullable()- Specified by:
isDeclaredNullablein interfaceAnnotatedElement- Returns:
- Whether the element is nullable.
-
isNullable
public boolean isNullable()- Specified by:
isNullablein interfaceAnnotatedElement- Returns:
- Whether the element is nullable.
-
isNonNull
public boolean isNonNull()- Specified by:
isNonNullin interfaceAnnotatedElement- Returns:
- Whether the element is declared as not being null
-
isDeclaredNonNull
public boolean isDeclaredNonNull()- Specified by:
isDeclaredNonNullin interfaceAnnotatedElement- Returns:
- Whether the element is declared as not being null
-
getParameters
- Specified by:
getParametersin interfaceMethodElement- Returns:
- The method parameters
-
withParameters
Description copied from interface:MethodElementTakes this method element and transforms into a new method element with the given parameters.- Specified by:
withParametersin interfaceMethodElement- Parameters:
newParameters- The new parameters- Returns:
- A new method element
-
withInheritedSignature
public MethodElement withInheritedSignature(ParameterElement[] newParameters, @Nullable @Nullable ClassElement newReturnType) Returns a copy of this method that reports the given signature instead of the one derived from the Python type hints. A Python method that overrides a Java method adopts the Java signature this way: the hints are lossy (intfor a boxedIntegerid,list[T]forIterable<T>) while the generated stub implements the Java signature, and the bean definition has to dispatch to that one.A class may reach the same inherited method through more than one interface -- a repository implementing both
CrudRepositoryandPageableRepositoryadoptsfindByIdtwice. The second pass compares the inherited return type against the one already adopted, finds them equal and asks for no change, sonullmust leave the adopted type alone rather than reset the method to its Python return type.- Parameters:
newParameters- The parametersnewReturnType- The return type, ornullto keep the one already in effect- Returns:
- The copy
-
isPublic
-
isPrivate
-
getDeclaringType
- Specified by:
getDeclaringTypein interfaceMemberElement- Returns:
- The declaring type of the element.
-
getOwningType
Description copied from interface:MemberElementThe owning type is the type that owns this element. This can differ fromMemberElement.getDeclaringType()in the case of inheritance since this method will return the subclass that owners the inherited member, whilstMemberElement.getDeclaringType()will return the super class that declares the type.- Specified by:
getOwningTypein interfaceMemberElement- Returns:
- The owning type.
-
getOverriddenMethods
Description copied from interface:MethodElementGet overridden methods by this method.- Specified by:
getOverriddenMethodsin interfaceMethodElement- Returns:
- The overridden method by this method.
-
getGenericReturnType
Description copied from interface:MethodElementThe generic return type of the method.- Specified by:
getGenericReturnTypein interfaceMethodElement- Returns:
- The return type of the method
-
isVarArgs
public boolean isVarArgs()Description copied from interface:MethodElementIf method has varargs parameter.- Specified by:
isVarArgsin interfaceMethodElement- Returns:
- True if it does
-
getDocumentation
- Specified by:
getDocumentationin interfaceElement- Parameters:
parseContent- True if the content should be parsed to extract documentation- Returns:
- The documentation, if any.
-
equals
-
hashCode
public int hashCode() -
copyThis
protected io.micronaut.python.processing.element.AbstractPythonElement copyThis()- Returns:
- copy of this element
-
withAnnotationMetadata
Description copied from interface:ElementCopies this element and overrides its annotations.- Specified by:
withAnnotationMetadatain interfaceElement- Specified by:
withAnnotationMetadatain interfaceMemberElement- Specified by:
withAnnotationMetadatain interfaceMethodElement- Parameters:
annotationMetadata- The annotation metadata- Returns:
- A new element
-
getDeclaredTypeVariables
- Specified by:
getDeclaredTypeVariablesin interfaceMethodElement- Returns:
- The type arguments declared on this method.
-
element
- Specified by:
elementin interfaceElementProvider- Returns:
- The native element.
-
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.
-
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
-