Class PythonMethodElement
java.lang.Object
io.micronaut.inject.ast.annotation.AbstractAnnotationElement
io.micronaut.python.processing.visitor.PythonMethodElement
- All Implemented Interfaces:
ElementProvider, AnnotatedElement, AnnotationMetadata, AnnotationMetadataDelegate, AnnotationMetadataProvider, AnnotationSource, Described, Named, MutableAnnotationMetadataDelegate<Element>, Element, MemberElement, MethodElement
- Direct Known Subclasses:
PythonConstructorElement
public non-sealed class PythonMethodElement
extends AbstractAnnotationElement
implements MethodElement, ElementProvider
Represents a Python method/function as a Micronaut
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.visitor.AbstractPythonElementcopyThis()protected voidcopyValues(io.micronaut.python.processing.visitor.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.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 parentbooleanbooleanisAsync()Returns whether this method was declared withasync def.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()protected final io.micronaut.python.processing.visitor.AbstractPythonElementmakeCopy()withAnnotationMetadata(AnnotationMetadata annotationMetadata) Copies this element and overrides its annotations.@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, getDeclaredTypeArguments, getParameter, getReceiverType, getSuspendParameters, getThrownTypes, getTypeArguments, hasParameters, hides, hides, isDefault, isSubSignature, isSuspend, isVarArgs, 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
-
isAbstract
public boolean isAbstract()- Specified by:
isAbstractin interfaceElement- Returns:
- True if the element is abstract.
-
isAsync
public boolean isAsync()Returns whether this method was declared withasync def.- Returns:
- Whether this method was declared with
async def.
-
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.- 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
-
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
-
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.visitor.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.
-
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
-
isProtected
public boolean isProtected()- Specified by:
isProtectedin interfaceElement- Returns:
- True if the element is protected.
-