Interface MethodDescription

All Superinterfaces:
AnnotationSource, ByteCodeElement, ByteCodeElement.TypeDependant<MethodDescription.InDefinedShape,MethodDescription.Token>, DeclaredByType, DeclaredByType.WithMandatoryDeclaration, ModifierReviewable, ModifierReviewable.ForMethodDescription, ModifierReviewable.OfAbstraction, ModifierReviewable.OfByteCodeElement, NamedElement, NamedElement.WithDescriptor, NamedElement.WithGenericName, NamedElement.WithRuntimeName, TypeVariableSource
All Known Subinterfaces:
MethodDescription.InDefinedShape, MethodDescription.InGenericShape
All Known Implementing Classes:
Implementation.Context.Default.AbstractPropertyAccessorMethod, Implementation.Context.Default.AccessorMethod, Implementation.Context.Default.FieldGetter, Implementation.Context.Default.FieldSetter, MethodDescription.AbstractBase, MethodDescription.ForLoadedConstructor, MethodDescription.ForLoadedMethod, MethodDescription.InDefinedShape.AbstractBase, MethodDescription.InDefinedShape.AbstractBase.ForLoadedExecutable, MethodDescription.Latent, MethodDescription.Latent.TypeInitializer, MethodDescription.TypeSubstituting, MethodRebaseResolver.Resolution.ForRebasedConstructor.RebasedConstructor, MethodRebaseResolver.Resolution.ForRebasedMethod.RebasedMethod, Transformer.ForMethod.TransformedMethod, TypePool.Default.LazyTypeDescription.LazyMethodDescription, TypeWriter.MethodPool.Record.AccessBridgeWrapper.AccessorBridge, TypeWriter.MethodPool.Record.AccessBridgeWrapper.BridgeTarget, TypeWriter.MethodPool.Record.ForDefinedMethod.OfVisibilityBridge.VisibilityBridge

Implementations of this interface describe a Java method, i.e. a method or a constructor. Implementations of this interface must provide meaningful equal(Object) and hashCode() implementations.
  • Field Details

    • CONSTRUCTOR_INTERNAL_NAME

      static final String CONSTRUCTOR_INTERNAL_NAME
      The internal name of a Java constructor.
      See Also:
    • TYPE_INITIALIZER_INTERNAL_NAME

      static final String TYPE_INITIALIZER_INTERNAL_NAME
      The internal name of a Java static initializer.
      See Also:
    • TYPE_INITIALIZER_MODIFIER

      static final int TYPE_INITIALIZER_MODIFIER
      The type initializer of any representation of a type initializer.
      See Also:
    • UNDEFINED

      Represents any undefined property of a type description that is instead represented as null in order to resemble the Java reflection API which returns null and is intuitive to many Java developers.
  • Method Details

    • getReturnType

      TypeDescription.Generic getReturnType()
      Returns the return type of the described method.
      Returns:
      The return type of the described method.
    • getParameters

      ParameterList<?> getParameters()
      Returns a list of this method's parameters.
      Returns:
      A list of this method's parameters.
    • getExceptionTypes

      TypeList.Generic getExceptionTypes()
      Returns the exception types of the described method.
      Returns:
      The exception types of the described method.
    • getActualModifiers

      int getActualModifiers()
      Returns this method's actual modifiers as it is present in a class file, i.e. includes a flag if this method is marked Deprecated.
      Returns:
      The method's actual modifiers.
    • getActualModifiers

      int getActualModifiers(boolean manifest)
      Returns this method's actual modifiers as it is present in a class file, i.e. includes a flag if this method is marked Deprecated and adjusts the modifiers for being abstract or not.
      Parameters:
      manifest - true if the method should be treated as non-abstract.
      Returns:
      The method's actual modifiers.
    • getActualModifiers

      int getActualModifiers(boolean manifest, Visibility visibility)
      Returns this method's actual modifiers as it is present in a class file, i.e. includes a flag if this method is marked Deprecated and adjusts the modifiers for being abstract or not. Additionally, this method resolves a required minimal visibility.
      Parameters:
      manifest - true if the method should be treated as non-abstract.
      visibility - The minimal visibility to enforce for this method.
      Returns:
      The method's actual modifiers.
    • isConstructor

      boolean isConstructor()
      Checks if this method description represents a constructor.
      Returns:
      true if this method description represents a constructor.
    • isMethod

      boolean isMethod()
      Checks if this method description represents a method, i.e. not a constructor or a type initializer.
      Returns:
      true if this method description represents a Java method.
    • isTypeInitializer

      boolean isTypeInitializer()
      Checks if this method is a type initializer.
      Returns:
      true if this method description represents a type initializer.
    • represents

      boolean represents(Method method)
      Verifies if a method description represents a given loaded method.
      Parameters:
      method - The method to be checked.
      Returns:
      true if this method description represents the given loaded method.
    • represents

      boolean represents(Constructor<?> constructor)
      Verifies if a method description represents a given loaded constructor.
      Parameters:
      constructor - The constructor to be checked.
      Returns:
      true if this method description represents the given loaded constructor.
    • isVirtual

      boolean isVirtual()
      Verifies if this method describes a virtual method, i.e. a method that is inherited by a sub type of this type.
      Returns:
      true if this method is virtual.
    • getStackSize

      int getStackSize()
      Returns the size of the local variable array that is required for this method, i.e. the size of all parameters if they were loaded on the stack including a reference to this if this method represented a non-static method.
      Returns:
      The size of this method on the operand stack.
    • isDefaultMethod

      boolean isDefaultMethod()
      Checks if this method represents a default (defender) method.
      Returns:
      true if this method is a default method.
    • isSpecializableFor

      boolean isSpecializableFor(TypeDescription typeDescription)
      Checks if this method can be called using the INVOKESPECIAL for a given type.
      Parameters:
      typeDescription - The type o
      Returns:
      true if this method can be called using the INVOKESPECIAL instruction using the given type.
    • getDefaultValue

      @MaybeNull AnnotationValue<?,?> getDefaultValue()
      Returns the method's default annotation value or null if no default value is defined for this method.
      Returns:
      The method's default annotation value or null if no default value is defined for this method.
    • getDefaultValue

      @MaybeNull <T> T getDefaultValue(Class<T> type)
      Returns the default value but casts it to the given type. If the type differs from the value, a ClassCastException is thrown.
      Type Parameters:
      T - The type to cast the default value to.
      Parameters:
      type - The type to cast the default value to.
      Returns:
      The casted default value.
    • isInvokableOn

      boolean isInvokableOn(TypeDescription typeDescription)
      Asserts if this method is invokable on an instance of the given type, i.e. the method is an instance method or a constructor and the method is visible to the type and can be invoked on the given instance.
      Parameters:
      typeDescription - The type to check.
      Returns:
      true if this method is invokable on an instance of the given type.
    • isInvokeBootstrap

      boolean isInvokeBootstrap()
      Checks if this method is a valid bootstrap method for an invokedynamic call.
      Returns:
      true if this method is a valid bootstrap method for an invokedynamic call.
    • isInvokeBootstrap

      boolean isInvokeBootstrap(List<? extends TypeDefinition> arguments)
      Checks if this method is a valid bootstrap method for an invokedynamic call.
      Parameters:
      arguments - The types of the explicit arguments that are supplied to the bootstrap method.
      Returns:
      true if this method is a valid bootstrap method for an invokedynamic call.
    • isConstantBootstrap

      boolean isConstantBootstrap()
      Checks if this method is a valid bootstrap method for an constantdynamic call.
      Returns:
      true if this method is a valid bootstrap method for an constantdynamic call.
    • isConstantBootstrap

      boolean isConstantBootstrap(List<? extends TypeDefinition> arguments)
      Checks if this method is a valid bootstrap method for an constantdynamic call.
      Parameters:
      arguments - The types of the explicit arguments that are supplied to the bootstrap method.
      Returns:
      true if this method is a valid bootstrap method for an constantdynamic call.
    • isDefaultValue

      boolean isDefaultValue()
      Checks if this method is capable of defining a default annotation value.
      Returns:
      true if it is possible to define a default annotation value for this method.
    • isDefaultValue

      boolean isDefaultValue(AnnotationValue<?,?> annotationValue)
      Checks if the given value can describe a default annotation value for this method.
      Parameters:
      annotationValue - The value that describes the default annotation value for this method.
      Returns:
      true if the given value can describe a default annotation value for this method.
    • getReceiverType

      Returns this methods receiver type. A receiver type is undefined for static methods where null is returned. Other than a receiver type that is provided by the Java reflection API, Byte Buddy is capable of extracting annotations on type parameters of receiver types when directly accessing a class file. Therefore, a receiver type might be parameterized.
      Returns:
      This method's (annotated) receiver type.
    • asSignatureToken

      Returns a signature token representing this method.
      Returns:
      A signature token representing this method.
    • asTypeToken

      Returns a type token that represents this method's raw return and parameter types.
      Returns:
      A type token that represents this method's raw return and parameter types.
    • isBridgeCompatible

      boolean isBridgeCompatible(MethodDescription.TypeToken typeToken)
      Validates that the supplied type token can implement a bridge method to this method.
      Parameters:
      typeToken - A type token representing a potential bridge method to this method.
      Returns:
      true if the supplied type token can represent a bridge method to this method.