Class MethodInfo
- All Implemented Interfaces:
AnnotationTarget
,Declaration
,Descriptor
,GenericSignature
Jandex makes reasonable attempts to not include implicitly declared (aka mandated)
and synthetic parameters in parameters()
, parameterTypes()
,
parameterName(int)
, parameterType(int)
and parametersCount()
.
However, descriptorParameterTypes()
and descriptorParametersCount()
may be used to obtain information about all parameters, including mandated and synthetic.
As an exception to the rule above, implicitly declared parameters are always included in case of methods that don't have an explicit parameter list. These are:
- the implicitly declared
valueOf()
method in enums; - the compact constructor in records.
Thread-Safety
This class is immutable and can be shared between threads without safe publication.-
Nested Class Summary
Nested classes/interfaces inherited from interface org.jboss.jandex.AnnotationTarget
AnnotationTarget.Kind
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ClassInfo
(package private) static final String[]
private MethodInternal
Fields inherited from interface org.jboss.jandex.Descriptor
NO_SUBSTITUTION
Fields inherited from interface org.jboss.jandex.GenericSignature
NO_SUBSTITUTION
-
Constructor Summary
ConstructorsConstructorDescriptionMethodInfo
(ClassInfo clazz, byte[] name, byte[][] parameterNames, Type[] parameterTypes, Type returnType, short flags) MethodInfo
(ClassInfo clazz, byte[] name, byte[][] parameterNames, Type[] parameterTypes, Type returnType, short flags, Type[] typeParameters, Type[] exceptions) MethodInfo
(ClassInfo clazz, MethodInternal methodInternal) -
Method Summary
Modifier and TypeMethodDescriptionfinal AnnotationInstance
annotation
(DotName name) Returns the annotation instance with given name declared on this method, any of its parameters or any type within its signature.final List
<AnnotationInstance> Returns the annotation instances declared on this method, any of its parameters or any type within its signature.final List
<AnnotationInstance> annotations
(DotName name) Returns the annotation instances with given name declared on this method, any of its parameters or any type within its signature.final List
<AnnotationInstance> annotationsWithRepeatable
(DotName name, IndexView index) Returns the annotation instances with given name declared on this method, any of its parameters or any type within its signature.final Type[]
args()
Deprecated.final ClassInfo
asClass()
Casts and returns this target as aClassInfo
if it is of kindCLASS
final FieldInfo
asField()
Casts and returns this target as aFieldInfo
if it is of kindFIELD
final MethodInfo
asMethod()
Casts and returns this target as aMethodInfo
if it is of kindMETHOD
final MethodParameterInfo
Casts and returns this target as aMethodParameterInfo
if it is of kindMETHOD_PARAMETER
final RecordComponentInfo
Casts and returns this target as aRecordComponentInfo
if it is of kindRECORD_COMPONENT
final TypeTarget
asType()
Casts and returns this target as aTypeTarget
if it is of kindTYPE
(package private) final Type[]
(package private) final Type[]
static MethodInfo
create
(ClassInfo clazz, String name, String[] parameterNames, Type[] parameterTypes, Type returnType, short flags, TypeVariable[] typeParameters, Type[] exceptions) Construct a new mock Method instance.static MethodInfo
Construct a new mock Method instance.static MethodInfo
create
(ClassInfo clazz, String name, Type[] parameterTypes, Type returnType, short flags, TypeVariable[] typeParameters, Type[] exceptions) Construct a new mock Method instance.declaredAnnotation
(DotName name) Returns the annotation instance with given name declared on this method.Returns the annotation instances declared on this method.declaredAnnotationsWithRepeatable
(DotName name, IndexView index) Returns the annotation instances with given name declared on this method.final ClassInfo
Returns the class that declared this methodReturns the default annotation value if this method represents an annotation member with a default value.descriptor
(Function<String, Type> typeVariableSubstitution) Returns a bytecode descriptor of this method.final int
Returns the number of all parameters present on this method, based on the method descriptor.Returns a list of types of all parameters present on this method, based on the method descriptor.boolean
Returns the list of throwable classes declared to be thrown by this method.final short
flags()
Returns the access fields of this method.genericSignature
(Function<String, Type> typeVariableSubstitution) Returns a generic signature of this method, possibly without any generic-related information.final boolean
hasAnnotation
(DotName name) Returns whether an annotation instance with given name is declared on this method, its parameters or any type within its signature.boolean
hasDeclaredAnnotation
(DotName name) Returns whether an annotation instance with given name is declared on this method.int
hashCode()
boolean
isBridge()
boolean
boolean
A default method is a public non-abstract non-static method declared in an interface.boolean
boolean
final AnnotationTarget.Kind
kind()
Returns the kind of object this target represents.(package private) final MethodInternal
final String
name()
Returns the name of this methodfinal String
parameterName
(int i) Returns the name of the given parameter.final List
<MethodParameterInfo> Returns a list of parameters declared on this method, in declaration order.final int
Returns the number of parameters this method declares.final Type
parameterType
(int i) Returns the type of the given parameter.Returns a list of types of parameters declared on this method, in declaration order.final Type
Returns the receiver type of this method (a declaration of the "this" reference), if specified.boolean
Returns whether this method must have a generic signature.final Type
Returns this method's return parameter type.(package private) void
setAnnotations
(List<AnnotationInstance> annotations) (package private) final void
setClassInfo
(ClassInfo clazz) (package private) void
setDefaultValue
(AnnotationValue defaultValue) (package private) void
setExceptions
(Type[] exceptions) (package private) final void
setMethodInternal
(MethodInternal methodInternal) (package private) void
setParameters
(Type[] parameters) (package private) void
setReceiverType
(Type receiverType) (package private) void
setReturnType
(Type returnType) (package private) void
setTypeParameters
(Type[] typeParameters) toString()
Returns a string representation describing this method.(package private) final Type[]
final List
<TypeVariable> Returns the generic type parameters defined by this method.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.jboss.jandex.AnnotationTarget
annotation, annotation, annotations, annotations, annotationsWithRepeatable, annotationsWithRepeatable, declaredAnnotation, declaredAnnotation, declaredAnnotationsWithRepeatable, declaredAnnotationsWithRepeatable, hasAnnotation, hasAnnotation, hasDeclaredAnnotation, hasDeclaredAnnotation
Methods inherited from interface org.jboss.jandex.Declaration
asDeclaration, isDeclaration
Methods inherited from interface org.jboss.jandex.Descriptor
descriptor
Methods inherited from interface org.jboss.jandex.GenericSignature
genericSignature, genericSignatureIfRequired, genericSignatureIfRequired
-
Field Details
-
EMPTY_PARAMETER_NAMES
-
methodInternal
-
clazz
-
-
Constructor Details
-
MethodInfo
MethodInfo() -
MethodInfo
MethodInfo(ClassInfo clazz, MethodInternal methodInternal) -
MethodInfo
-
MethodInfo
-
-
Method Details
-
create
public static MethodInfo create(ClassInfo clazz, String name, Type[] parameterTypes, Type returnType, short flags) Construct a new mock Method instance.- Parameters:
clazz
- the class declaring the fieldname
- the name of the fieldparameterTypes
- a read only array containing the types of each parameter in parameter orderreturnType
- the return value typeflags
- the method attributes- Returns:
- a mock method
-
create
public static MethodInfo create(ClassInfo clazz, String name, Type[] parameterTypes, Type returnType, short flags, TypeVariable[] typeParameters, Type[] exceptions) Construct a new mock Method instance.- Parameters:
clazz
- the class declaring the fieldname
- the name of the fieldparameterTypes
- a read only array containing the types of each parameter in parameter orderreturnType
- the return value typeflags
- the method attributestypeParameters
- the generic type parameters for this methodexceptions
- the exceptions declared as thrown by this method- Returns:
- a mock method
- Since:
- 2.1
-
create
public static MethodInfo create(ClassInfo clazz, String name, String[] parameterNames, Type[] parameterTypes, Type returnType, short flags, TypeVariable[] typeParameters, Type[] exceptions) Construct a new mock Method instance.- Parameters:
clazz
- the class declaring the fieldname
- the name of the fieldparameterNames
- the names of the method parameterparameterTypes
- a read only array containing the types of each parameter in parameter orderreturnType
- the return value typeflags
- the method attributestypeParameters
- the generic type parameters for this methodexceptions
- the exceptions declared as thrown by this method- Returns:
- a mock method
- Since:
- 2.2
-
name
Returns the name of this method- Returns:
- the name of the method
-
parameterName
Returns the name of the given parameter.- Parameters:
i
- the parameter index, zero-based- Returns:
- the name of the given parameter, or
null
if not known
-
parameterType
Returns the type of the given parameter.- Parameters:
i
- the parameter index, zero-based- Returns:
- the type of the given parameter
-
kind
Description copied from interface:AnnotationTarget
Returns the kind of object this target represents.- Specified by:
kind
in interfaceAnnotationTarget
- Returns:
- the target kind.
-
declaringClass
Returns the class that declared this method- Returns:
- the declaring class
-
args
Deprecated.useparameterTypes()
Returns an array of parameter types in declaration order. Jandex makes reasonable attempts to not include implicitly declared (aka mandated) and synthetic parameters.This method performs a defensive array copy per call, and should be avoided. Instead, the
parameterTypes()
method should be used.- Returns:
- an array copy contain parameter types
-
copyParameters
-
parametersCount
public final int parametersCount()Returns the number of parameters this method declares. Jandex makes reasonable attempts to not count implicitly declared (aka mandated) and synthetic parameters.- Returns:
- the number of parameters this method declares
-
parameterTypes
Returns a list of types of parameters declared on this method, in declaration order. Jandex makes reasonable attempts to not include implicitly declared (aka mandated) and synthetic parameters. Positions of types in this list may be used to retrieve a name usingparameterName(int)
or look for annotations.- Returns:
- immutable list of parameter types of this method, never
null
-
parameters
Returns a list of parameters declared on this method, in declaration order. Jandex makes reasonable attempts to not include implicitly declared (aka mandated) and synthetic parameters.- Returns:
- immutable list of parameter types of this method, never
null
-
descriptorParametersCount
public final int descriptorParametersCount()Returns the number of all parameters present on this method, based on the method descriptor. This always includes implicitly declared (aka mandated) and synthetic parameters.- Returns:
- the number of all parameters present on this method
-
descriptorParameterTypes
Returns a list of types of all parameters present on this method, based on the method descriptor. This always includes implicitly declared (aka mandated) and synthetic parameters. These types are never annotated and their position in the list cannot be used to retrieve a name usingparameterName(int)
or look for annotations. -
returnType
Returns this method's return parameter type. If this method has a void return, a special void type is returned. This method will never return null.- Returns:
- the type of this method's return value
-
receiverType
Returns the receiver type of this method (a declaration of the "this" reference), if specified. This is used to convey annotations on the "this" instance.- Returns:
- the receiver type of this method
-
exceptions
Returns the list of throwable classes declared to be thrown by this method. This method may return an empty list, but never null.- Returns:
- immutable list of throwable classes thrown by this method
-
copyExceptions
-
typeParameters
Returns the generic type parameters defined by this method. This list will contain resolved type variables which may reference other type parameters, including those declared by the enclosing class of this method.- Returns:
- immutable list of generic type parameters for this method, or an empty list if none
-
hasAnnotation
Returns whether an annotation instance with given name is declared on this method, its parameters or any type within its signature.- Specified by:
hasAnnotation
in interfaceAnnotationTarget
- Parameters:
name
- name of the annotation type to look for, must not benull
- Returns:
true
if the annotation is present,false
otherwise- See Also:
-
annotation
Returns the annotation instance with given name declared on this method, any of its parameters or any type within its signature. Thetarget()
method of the returned annotation instance may be used to determine the exact location of the annotation instance.The following is a non-exhaustive list of examples of annotations returned by this method:
@MyMethodAnnotation public void foo() {...} public void foo(@MyParamAnnotation int param) {...} public void foo(List<@MyTypeAnnotation String> list) {...} public <@MyTypeAnnotation T> void foo(T t) {...}
In case an annotation with given name occurs more than once, the result of this method is not deterministic. For such situations,
annotations(DotName)
is preferable.- Specified by:
annotation
in interfaceAnnotationTarget
- Parameters:
name
- name of the annotation type to look for, must not benull
- Returns:
- the annotation instance, or
null
if not found - Since:
- 3.0
- See Also:
-
annotations
Returns the annotation instances with given name declared on this method, any of its parameters or any type within its signature. Thetarget()
method of the returned annotation instances may be used to determine the exact location of the respective annotation instance.The following is a non-exhaustive list of examples of annotations returned by this method:
@MyMethodAnnotation public void foo() {...} public void foo(@MyParamAnnotation int param) {...} public void foo(List<@MyTypeAnnotation String> list) {...} public <@MyTypeAnnotation T> void foo(T t) {...}
- Specified by:
annotations
in interfaceAnnotationTarget
- Parameters:
name
- name of the annotation type, must not benull
- Returns:
- immutable list of annotation instances, never
null
- See Also:
-
annotationsWithRepeatable
Returns the annotation instances with given name declared on this method, any of its parameters or any type within its signature. Thetarget()
method of the returned annotation instances may be used to determine the exact location of the respective annotation instance.If the specified annotation is repeatable, the result also contains all values from the container annotation instance. In this case, the
AnnotationInstance.target()
returns the target of the container annotation instance.- Specified by:
annotationsWithRepeatable
in interfaceAnnotationTarget
- Parameters:
name
- name of the annotation type, must not benull
index
- index used to obtain the annotation type, must not benull
- Returns:
- immutable list of annotation instances, never
null
- Throws:
IllegalArgumentException
- if the index isnull
, if the index does not contain the annotation type or ifname
does not identify an annotation type- See Also:
-
annotations
Returns the annotation instances declared on this method, any of its parameters or any type within its signature. Thetarget()
method of the returned annotation instances may be used to determine the exact location of the respective annotation instance.The following is a non-exhaustive list of examples of annotations returned by this method:
@MyMethodAnnotation public void foo() {...} public void foo(@MyParamAnnotation int param) {...} public void foo(List<@MyTypeAnnotation String> list) {...} public <@AnotherTypeAnnotation T> void foo(T t) {...}
- Specified by:
annotations
in interfaceAnnotationTarget
- Returns:
- immutable list of annotation instances, never
null
-
hasDeclaredAnnotation
Returns whether an annotation instance with given name is declared on this method.Unlike
hasAnnotation(DotName)
, this method ignores annotations declared on the method parameters and types within the method signature.- Specified by:
hasDeclaredAnnotation
in interfaceAnnotationTarget
- Parameters:
name
- name of the annotation type to look for, must not benull
- Returns:
true
if the annotation is present,false
otherwise- Since:
- 3.0
- See Also:
-
declaredAnnotation
Returns the annotation instance with given name declared on this method.Unlike
annotation(DotName)
, this method doesn't return annotations declared on the method parameters and types within the method signature.- Specified by:
declaredAnnotation
in interfaceAnnotationTarget
- Parameters:
name
- name of the annotation type to look for, must not benull
- Returns:
- the annotation instance, or
null
if not found - Since:
- 3.0
- See Also:
-
declaredAnnotationsWithRepeatable
Returns the annotation instances with given name declared on this method.If the specified annotation is repeatable, the result also contains all values from the container annotation instance. In this case, the
AnnotationInstance.target()
returns the target of the container annotation instance.Unlike
annotationsWithRepeatable(DotName, IndexView)
, this method doesn't return annotations declared on the method parameters and types within the method signature.- Specified by:
declaredAnnotationsWithRepeatable
in interfaceAnnotationTarget
- Parameters:
name
- name of the annotation type, must not benull
index
- index used to obtain the annotation type, must not benull
- Returns:
- immutable list of annotation instances, never
null
- Throws:
IllegalArgumentException
- if the index isnull
, if the index does not contain the annotation type or ifname
does not identify an annotation type- Since:
- 3.0
- See Also:
-
declaredAnnotations
Returns the annotation instances declared on this method.Unlike
annotations()
, this method doesn't return annotations declared on the method parameters and types within the method signature.- Specified by:
declaredAnnotations
in interfaceAnnotationTarget
- Returns:
- immutable list of annotation instances, never
null
- Since:
- 3.0
- See Also:
-
defaultValue
Returns the default annotation value if this method represents an annotation member with a default value. Otherwise null is returned- Returns:
- default annotation value if available, otherwise null
- Since:
- 2.1
-
flags
public final short flags()Returns the access fields of this method.Modifier
can be used on this value.- Returns:
- the access flags of this method
-
isSynthetic
public boolean isSynthetic()- Returns:
true
if this method is a synthetic method
-
isBridge
public boolean isBridge()- Returns:
true
if this method is a bridge method as defined by the JLS,false
otherwise
-
isConstructor
public boolean isConstructor()- Returns:
true
if this method is a constructor
-
isStaticInitializer
public boolean isStaticInitializer()- Returns:
true
if this method is a static initializer
-
isDefault
public boolean isDefault()A default method is a public non-abstract non-static method declared in an interface.- Returns:
true
if this method is a default interface method,false
otherwise
-
requiresGenericSignature
public boolean requiresGenericSignature()Returns whether this method must have a generic signature. That is, whether the Java compiler when compiling this method had to emit theSignature
bytecode attribute.- Specified by:
requiresGenericSignature
in interfaceGenericSignature
- Returns:
- whether this method must have a generic signature
-
genericSignature
Returns a generic signature of this method, possibly without any generic-related information. That is, produces a correct generic signature even if this method is not generic and does not use any type variables.Signatures of type variables are substituted for signatures of types provided by the substitution function
typeVariableSubstitution
. If the substitution function returnsnull
for some type variable identifier, no substitution happens and the type variable signature is used unmodified.Note that the return value does not come directly from bytecode. Jandex does not store the signature strings. Instead, the return value is reconstructed from the Jandex object model.
- Specified by:
genericSignature
in interfaceGenericSignature
- Parameters:
typeVariableSubstitution
- a substitution function from type variable identifiers to types- Returns:
- a generic signature of this method with type variables substituted, never
null
-
descriptor
Returns a bytecode descriptor of this method.Descriptors of type variables are substituted for descriptors of types provided by the substitution function
typeVariableSubstitution
. If the substitution function returnsnull
for some type variable identifier, or if it returns the type variable itself, no substitution happens and the type variable descriptor is used unmodified.Note that the return value does not come directly from bytecode. Jandex does not store the descriptor strings. Instead, the return value is reconstructed from the Jandex object model.
- Specified by:
descriptor
in interfaceDescriptor
- Parameters:
typeVariableSubstitution
- a substitution function from type variable identifiers to types- Returns:
- the bytecode descriptor of this method
-
toString
Returns a string representation describing this method. It is similar although not necessarily identical to a Java source code declaration of this method. -
equals
-
hashCode
public int hashCode() -
asClass
Description copied from interface:AnnotationTarget
Casts and returns this target as aClassInfo
if it is of kindCLASS
- Specified by:
asClass
in interfaceAnnotationTarget
- Returns:
- this instance cast to a class
-
asField
Description copied from interface:AnnotationTarget
Casts and returns this target as aFieldInfo
if it is of kindFIELD
- Specified by:
asField
in interfaceAnnotationTarget
- Returns:
- this instance cast to a field
-
asMethod
Description copied from interface:AnnotationTarget
Casts and returns this target as aMethodInfo
if it is of kindMETHOD
- Specified by:
asMethod
in interfaceAnnotationTarget
- Returns:
- this instance cast to a method
-
asMethodParameter
Description copied from interface:AnnotationTarget
Casts and returns this target as aMethodParameterInfo
if it is of kindMETHOD_PARAMETER
- Specified by:
asMethodParameter
in interfaceAnnotationTarget
- Returns:
- this instance cast to a method parameter
-
asType
Description copied from interface:AnnotationTarget
Casts and returns this target as aTypeTarget
if it is of kindTYPE
- Specified by:
asType
in interfaceAnnotationTarget
- Returns:
- this instance cast to a type target
-
asRecordComponent
Description copied from interface:AnnotationTarget
Casts and returns this target as aRecordComponentInfo
if it is of kindRECORD_COMPONENT
- Specified by:
asRecordComponent
in interfaceAnnotationTarget
- Returns:
- this instance cast to a record component
-
methodInternal
-
setMethodInternal
-
setClassInfo
-
typeParameterArray
-
setTypeParameters
-
setParameters
-
setReturnType
-
setExceptions
-
setReceiverType
-
setAnnotations
-
setDefaultValue
-
parameterTypes()