Interface MethodElement

All Superinterfaces:
AnnotatedElement, AnnotationMetadata, AnnotationMetadataDelegate, AnnotationMetadataProvider, AnnotationSource, Described, Element, MemberElement, MutableAnnotationMetadataDelegate<Element>, Named
All Known Subinterfaces:
BeanConstructorElement, BeanMethodElement, ConstructorElement
All Known Implementing Classes:
GroovyConstructorElement, GroovyMethodElement, JavaMethodElement

public interface MethodElement extends MemberElement
Stores data about an element that references a method.
Since:
1.0
Author:
James Kleeh
  • Method Details

    • getMethodAnnotationMetadata

      Returns the method annotations. The method will only return annotations defined on a method or inherited from the super methods, while AnnotationMetadataProvider.getAnnotationMetadata() for a method combines the class and the method annotations. NOTE: For a constructor AnnotationMetadataProvider.getAnnotationMetadata() will not combine the class annotations.
      Returns:
      The method annotation metadata
      Since:
      4.0.0
    • getReturnType

      @NonNull @NonNull ClassElement getReturnType()
      Returns:
      The return type of the method
    • getDeclaredTypeVariables

      default List<? extends GenericPlaceholderElement> getDeclaredTypeVariables()
      Returns:
      The type arguments declared on this method.
    • getTypeArguments

      @NonNull default @NonNull Map<String,ClassElement> getTypeArguments()
      The type arguments for this method element. The type arguments should include the type arguments added to the method plus the type arguments of the declaring class.
      Returns:
      The type arguments for this method element
      Since:
      4.0.0
    • getDeclaredTypeArguments

      @NonNull default @NonNull Map<String,ClassElement> getDeclaredTypeArguments()
      The declared type arguments for this method element.
      Returns:
      The declared type arguments for this method element
      Since:
      4.0.0
    • getReceiverType

      default Optional<ClassElement> getReceiverType()

      Returns the receiver type of this executable, or empty if the method has no receiver type.

      A MethodElement which is an instance method, or a constructor of an inner class, has a receiver type derived from the declaring type.

      A MethodElement which is a static method, or a constructor of a non-inner class, or an initializer (static or instance), has no receiver type.

      Returns:
      The receiver type for the method if one exists.
      Since:
      3.1.0
    • getThrownTypes

      @NonNull default @NonNull ClassElement[] getThrownTypes()
      Returns the types declared in the throws declaration of a method.
      Returns:
      The throws types, if any. Never null.
      Since:
      3.1.0
    • getParameters

      Returns:
      The method parameters
    • withNewParameters

      @NonNull default @NonNull MethodElement withNewParameters(@NonNull @NonNull ParameterElement... newParameters)
      Takes this method element and transforms into a new method element with the given parameters appended to the existing parameters.
      Parameters:
      newParameters - The new parameters
      Returns:
      A new method element
      Since:
      2.3.0
    • withParameters

      Takes this method element and transforms into a new method element with the given parameters.
      Parameters:
      newParameters - The new parameters
      Returns:
      A new method element
      Since:
      4.0.0
    • withNewOwningType

      @NonNull default @NonNull MethodElement withNewOwningType(@NonNull @NonNull ClassElement owningType)
      Returns a new method with a new owning type.
      Parameters:
      owningType - The owning type.
      Returns:
      A new method element
      Since:
      4.0.0
    • addAssociatedBean

      This method adds an associated bean using this method 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 UnsupportedOperationException will be thrown.

      Parameters:
      type - The type of the bean
      Returns:
      A bean builder
    • getSuspendParameters

      @NonNull default @NonNull ParameterElement[] getSuspendParameters()
      If isSuspend() returns true this method exposes the continuation parameter in addition to the other parameters of the method.
      Returns:
      The suspend parameters
      Since:
      2.3.0
    • hasParameters

      default boolean hasParameters()
      Returns true if the method has parameters.
      Returns:
      True if it does
    • isSuspend

      default boolean isSuspend()
      Is the method a Kotlin suspend function.
      Returns:
      True if it is.
      Since:
      2.3.0
    • isDefault

      default boolean isDefault()
      Is the method a default method on an interfaces.
      Returns:
      True if it is.
      Since:
      2.3.0
    • isVarArgs

      default boolean isVarArgs()
      If method has varargs parameter.
      Returns:
      True if it does
      Since:
      4.0.0
    • getGenericReturnType

      @NonNull default @NonNull ClassElement getGenericReturnType()
      The generic return type of the method.
      Returns:
      The return type of the method
      Since:
      1.1.1
    • getDescription

      @NonNull default @NonNull String getDescription(boolean simple)
      Get the method description.
      Specified by:
      getDescription in interface Described
      Specified by:
      getDescription in interface Element
      Parameters:
      simple - If simple type names are to be used
      Returns:
      The method description
    • overrides

      @NextMajorVersion("Review the package-private methods with broken access, those might need to be excluded completely") default boolean overrides(@NonNull @NonNull MethodElement overridden)
      Checks if this method element overrides another.
      Parameters:
      overridden - Possible overridden method
      Returns:
      true if this overrides passed method element
      Since:
      3.1
    • hides

      default boolean hides(@NonNull @NonNull MemberElement memberElement)
      Description copied from interface: MemberElement
      Checks if this member element hides another.
      Specified by:
      hides in interface MemberElement
      Parameters:
      memberElement - The possibly hidden element
      Returns:
      true if this member element hides passed field element
    • hides

      default boolean hides(@NonNull @NonNull MethodElement hiddenMethod)
      Checks if this member element hides another.
      Parameters:
      hiddenMethod - The possibly hidden method
      Returns:
      true if this member element hides passed field element
      Since:
      4.3.0
    • isSubSignature

      default boolean isSubSignature(MethodElement element)
      Is this method a sub signature of another.
      Parameters:
      element - The other method
      Returns:
      true if a sub signature
      Since:
      4.3.0
    • getOverriddenMethods

      default Collection<MethodElement> getOverriddenMethods()
      Get overridden methods by this method.
      Returns:
      The overridden method by this method.
      Since:
      4.3.0
    • of

      @NonNull static @NonNull MethodElement of(@NonNull @NonNull ClassElement declaredType, @NonNull @NonNull AnnotationMetadata annotationMetadata, @NonNull @NonNull ClassElement returnType, @NonNull @NonNull ClassElement genericReturnType, @NonNull @NonNull String name, ParameterElement... parameterElements)
      Creates a MethodElement for the given parameters.
      Parameters:
      declaredType - The declaring type
      annotationMetadata - The annotation metadata
      returnType - The return type
      genericReturnType - The generic return type
      name - The name
      parameterElements - The parameter elements
      Returns:
      The method element
    • of

      @NonNull static @NonNull MethodElement of(@NonNull @NonNull ClassElement owningType, @NonNull @NonNull ClassElement declaringType, @NonNull @NonNull AnnotationMetadataProvider methodAnnotationMetadataProvider, @NonNull @NonNull AnnotationMetadataProvider annotationMetadataProvider, @NonNull @NonNull AbstractAnnotationMetadataBuilder<?,?> metadataBuilder, @NonNull @NonNull ClassElement returnType, @NonNull @NonNull ClassElement genericReturnType, @NonNull @NonNull String name, boolean isStatic, boolean isFinal, ParameterElement... parameterElements)
      Creates a MethodElement for the given parameters.
      Parameters:
      owningType - The owing type
      declaringType - The declaring type
      methodAnnotationMetadataProvider - The method annotation metadata provider
      annotationMetadataProvider - The annotation metadata provider
      metadataBuilder - The metadata builder
      returnType - The return type
      genericReturnType - The generic return type
      name - The name
      isStatic - Is static
      isFinal - Is final
      parameterElements - The parameter elements
      Returns:
      The method element
      Since:
      4.0.0
    • withAnnotationMetadata

      default MethodElement 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 MemberElement
      Parameters:
      annotationMetadata - The annotation metadata
      Returns:
      A new element