Package net.bytebuddy.description.method
Interface MethodDescription
-
- All Superinterfaces:
AnnotationSource
,ByteCodeElement
,ByteCodeElement.TypeDependant<MethodDescription.InDefinedShape,MethodDescription.Token>
,DeclaredByType
,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.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
public interface MethodDescription extends TypeVariableSource, ModifierReviewable.ForMethodDescription, NamedElement.WithGenericName, ByteCodeElement, ByteCodeElement.TypeDependant<MethodDescription.InDefinedShape,MethodDescription.Token>
Implementations of this interface describe a Java method, i.e. a method or a constructor. Implementations of this interface must provide meaningfulequal(Object)
andhashCode()
implementations.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
MethodDescription.AbstractBase
An abstract base implementation of a method description.static class
MethodDescription.ForLoadedConstructor
An implementation of a method description for a loaded constructor.static class
MethodDescription.ForLoadedMethod
An implementation of a method description for a loaded method.static interface
MethodDescription.InDefinedShape
Represents a method in its defined shape, i.e.static interface
MethodDescription.InGenericShape
Represents a method description in its generic shape, i.e.static class
MethodDescription.Latent
A latent method description describes a method that is not attached to a declaringTypeDescription
.static class
MethodDescription.SignatureToken
A token representing a method's name and raw return and parameter types.static class
MethodDescription.Token
A token representing a method's properties detached from a type.static class
MethodDescription.TypeSubstituting
A method description that represents a given method but with substituted method types.static class
MethodDescription.TypeToken
A token representing a method's erased return and parameter types.-
Nested classes/interfaces inherited from interface net.bytebuddy.description.annotation.AnnotationSource
AnnotationSource.Empty, AnnotationSource.Explicit
-
Nested classes/interfaces inherited from interface net.bytebuddy.description.ByteCodeElement
ByteCodeElement.TypeDependant<T extends ByteCodeElement.TypeDependant<?,S>,S extends ByteCodeElement.Token<S>>
-
Nested classes/interfaces inherited from interface net.bytebuddy.description.ModifierReviewable
ModifierReviewable.ForFieldDescription, ModifierReviewable.ForMethodDescription, ModifierReviewable.ForParameterDescription, ModifierReviewable.ForTypeDefinition, ModifierReviewable.OfAbstraction, ModifierReviewable.OfByteCodeElement, ModifierReviewable.OfEnumeration
-
Nested classes/interfaces inherited from interface net.bytebuddy.description.NamedElement
NamedElement.WithDescriptor, NamedElement.WithGenericName, NamedElement.WithOptionalName, NamedElement.WithRuntimeName
-
Nested classes/interfaces inherited from interface net.bytebuddy.description.TypeVariableSource
TypeVariableSource.Visitor<T>
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
CONSTRUCTOR_INTERNAL_NAME
The internal name of a Java constructor.static java.lang.String
TYPE_INITIALIZER_INTERNAL_NAME
The internal name of a Java static initializer.static int
TYPE_INITIALIZER_MODIFIER
The type initializer of any representation of a type initializer.static MethodDescription.InDefinedShape
UNDEFINED
Represents any undefined property of a type description that is instead represented asnull
in order to resemble the Java reflection API which returnsnull
and is intuitive to many Java developers.-
Fields inherited from interface net.bytebuddy.description.ModifierReviewable
EMPTY_MASK
-
Fields inherited from interface net.bytebuddy.description.NamedElement
EMPTY_NAME, NO_NAME
-
Fields inherited from interface net.bytebuddy.description.NamedElement.WithDescriptor
NON_GENERIC_SIGNATURE
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description MethodDescription.SignatureToken
asSignatureToken()
Returns a signature token representing this method.MethodDescription.TypeToken
asTypeToken()
Returns a type token that represents this method's raw return and parameter types.int
getActualModifiers()
Returns this method's actual modifiers as it is present in a class file, i.e.int
getActualModifiers(boolean manifest)
Returns this method's actual modifiers as it is present in a class file, i.e.int
getActualModifiers(boolean manifest, Visibility visibility)
Returns this method's actual modifiers as it is present in a class file, i.e.AnnotationValue<?,?>
getDefaultValue()
Returns the method's default annotation value ornull
if no default value is defined for this method.<T> T
getDefaultValue(java.lang.Class<T> type)
Returns the default value but casts it to the given type.TypeList.Generic
getExceptionTypes()
Returns the exception types of the described method.ParameterList<?>
getParameters()
Returns a list of this method's parameters.TypeDescription.Generic
getReceiverType()
Returns this methods receiver type.TypeDescription.Generic
getReturnType()
Returns the return type of the described method.int
getStackSize()
Returns the size of the local variable array that is required for this method, i.e.boolean
isBridgeCompatible(MethodDescription.TypeToken typeToken)
Validates that the supplied type token can implement a bridge method to this method.boolean
isConstantBootstrap()
Checks if this method is a valid bootstrap method for an constantdynamic call.boolean
isConstantBootstrap(java.util.List<? extends TypeDefinition> arguments)
Checks if this method is a valid bootstrap method for an constantdynamic call.boolean
isConstructor()
Checks if this method description represents a constructor.boolean
isDefaultMethod()
Checks if this method represents a default (defender) method.boolean
isDefaultValue()
Checks if this method is capable of defining a default annotation value.boolean
isDefaultValue(AnnotationValue<?,?> annotationValue)
Checks if the given value can describe a default annotation value for this method.boolean
isInvokableOn(TypeDescription typeDescription)
Asserts if this method is invokable on an instance of the given type, i.e.boolean
isInvokeBootstrap()
Checks if this method is a valid bootstrap method for an invokedynamic call.boolean
isInvokeBootstrap(java.util.List<? extends TypeDefinition> arguments)
Checks if this method is a valid bootstrap method for an invokedynamic call.boolean
isMethod()
Checks if this method description represents a method, i.e.boolean
isSpecializableFor(TypeDescription typeDescription)
Checks if this method can be called using theINVOKESPECIAL
for a given type.boolean
isTypeInitializer()
Checks if this method is a type initializer.boolean
isVirtual()
Verifies if this method describes a virtual method, i.e.boolean
represents(java.lang.reflect.Constructor<?> constructor)
Verifies if a method description represents a given loaded constructor.boolean
represents(java.lang.reflect.Method method)
Verifies if a method description represents a given loaded method.-
Methods inherited from interface net.bytebuddy.description.annotation.AnnotationSource
getDeclaredAnnotations
-
Methods inherited from interface net.bytebuddy.description.ByteCodeElement
isAccessibleTo, isVisibleTo
-
Methods inherited from interface net.bytebuddy.description.ByteCodeElement.TypeDependant
asDefined, asToken
-
Methods inherited from interface net.bytebuddy.description.DeclaredByType
getDeclaringType
-
Methods inherited from interface net.bytebuddy.description.ModifierReviewable
getModifiers, getSyntheticState, isFinal, isSynthetic
-
Methods inherited from interface net.bytebuddy.description.ModifierReviewable.ForMethodDescription
getMethodManifestation, getMethodStrictness, getSynchronizationState, isBridge, isNative, isStrict, isSynchronized, isVarArgs
-
Methods inherited from interface net.bytebuddy.description.ModifierReviewable.OfAbstraction
isAbstract
-
Methods inherited from interface net.bytebuddy.description.ModifierReviewable.OfByteCodeElement
getOwnership, getVisibility, isDeprecated, isPackagePrivate, isPrivate, isProtected, isPublic, isStatic
-
Methods inherited from interface net.bytebuddy.description.NamedElement
getActualName
-
Methods inherited from interface net.bytebuddy.description.NamedElement.WithDescriptor
getDescriptor, getGenericSignature
-
Methods inherited from interface net.bytebuddy.description.NamedElement.WithGenericName
toGenericString
-
Methods inherited from interface net.bytebuddy.description.NamedElement.WithRuntimeName
getInternalName, getName
-
Methods inherited from interface net.bytebuddy.description.TypeVariableSource
accept, findVariable, getEnclosingSource, getTypeVariables, isGenerified, isInferrable
-
-
-
-
Field Detail
-
CONSTRUCTOR_INTERNAL_NAME
static final java.lang.String CONSTRUCTOR_INTERNAL_NAME
The internal name of a Java constructor.- See Also:
- Constant Field Values
-
TYPE_INITIALIZER_INTERNAL_NAME
static final java.lang.String TYPE_INITIALIZER_INTERNAL_NAME
The internal name of a Java static initializer.- See Also:
- Constant Field Values
-
TYPE_INITIALIZER_MODIFIER
static final int TYPE_INITIALIZER_MODIFIER
The type initializer of any representation of a type initializer.- See Also:
- Constant Field Values
-
UNDEFINED
static final MethodDescription.InDefinedShape UNDEFINED
Represents any undefined property of a type description that is instead represented asnull
in order to resemble the Java reflection API which returnsnull
and is intuitive to many Java developers.
-
-
Method Detail
-
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 markedDeprecated
.- 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 markedDeprecated
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 markedDeprecated
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(java.lang.reflect.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(java.lang.reflect.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 tothis
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 theINVOKESPECIAL
for a given type.- Parameters:
typeDescription
- The type o- Returns:
true
if this method can be called using theINVOKESPECIAL
instruction using the given type.
-
getDefaultValue
AnnotationValue<?,?> getDefaultValue()
Returns the method's default annotation value ornull
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
<T> T getDefaultValue(java.lang.Class<T> type)
Returns the default value but casts it to the given type. If the type differs from the value, aClassCastException
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(java.util.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(java.util.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
TypeDescription.Generic getReceiverType()
Returns this methods receiver type. A receiver type is undefined forstatic
methods wherenull
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
MethodDescription.SignatureToken asSignatureToken()
Returns a signature token representing this method.- Returns:
- A signature token representing this method.
-
asTypeToken
MethodDescription.TypeToken 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.
-
-