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, in case of well known methods where no parameter is declared explicitly, the implicitly declared parameters are included. This currently applies to the implicitly declared parameters of:
- 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.- Author:
- Jason T. Greene
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.jboss.jandex.AnnotationTarget
AnnotationTarget.Kind -
Field Summary
Fields inherited from interface org.jboss.jandex.Descriptor
NO_SUBSTITUTIONFields inherited from interface org.jboss.jandex.GenericSignature
NO_SUBSTITUTION -
Method Summary
Modifier and TypeMethodDescriptionfinal AnnotationInstanceannotation(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 ClassInfoasClass()Casts and returns this target as aClassInfoif it is of kindCLASSfinal FieldInfoasField()Casts and returns this target as aFieldInfoif it is of kindFIELDfinal MethodInfoasMethod()Casts and returns this target as aMethodInfoif it is of kindMETHODfinal MethodParameterInfoCasts and returns this target as aMethodParameterInfoif it is of kindMETHOD_PARAMETERfinal RecordComponentInfoCasts and returns this target as aRecordComponentInfoif it is of kindRECORD_COMPONENTfinal TypeTargetasType()Casts and returns this target as aTypeTargetif it is of kindTYPEstatic MethodInfocreate(ClassInfo clazz, String name, String[] parameterNames, Type[] parameterTypes, Type returnType, short flags, TypeVariable[] typeParameters, Type[] exceptions) Construct a new mock Method instance.static MethodInfoConstruct a new mock Method instance.static MethodInfocreate(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 ClassInfoReturns 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 intReturns 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.booleanReturns the list of throwable classes declared to be thrown by this method.final shortflags()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 booleanhasAnnotation(DotName name) Returns whether an annotation instance with given name is declared on this method, its parameters or any type within its signature.booleanhasDeclaredAnnotation(DotName name) Returns whether an annotation instance with given name is declared on this method.inthashCode()booleanisBridge()booleanbooleanA default method is a public non-abstract non-static method declared in an interface.booleanbooleanfinal AnnotationTarget.Kindkind()Returns the kind of object this target represents.final Stringname()Returns the name of this methodfinal StringparameterName(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 intReturns the number of parameters this method declares.final TypeparameterType(int i) Returns the type of the given parameter.Returns a list of types of parameters declared on this method, in declaration order.final TypeReturns the receiver type of this method (a declaration of the "this" reference), if specified.booleanReturns whether this method must have a generic signature.final TypeReturns this method's return parameter type.toString()Returns a string representation describing this method.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, waitMethods inherited from interface org.jboss.jandex.AnnotationTarget
annotation, annotation, annotations, annotations, annotationsWithRepeatable, annotationsWithRepeatable, declaredAnnotation, declaredAnnotation, declaredAnnotationsWithRepeatable, declaredAnnotationsWithRepeatable, hasAnnotation, hasAnnotation, hasDeclaredAnnotation, hasDeclaredAnnotationMethods inherited from interface org.jboss.jandex.Declaration
asDeclaration, isDeclarationMethods inherited from interface org.jboss.jandex.Descriptor
descriptorMethods inherited from interface org.jboss.jandex.GenericSignature
genericSignature, genericSignatureIfRequired, genericSignatureIfRequired
-
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
nullif 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:AnnotationTargetReturns the kind of object this target represents.- Specified by:
kindin 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
-
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
-
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:
hasAnnotationin interfaceAnnotationTarget- Parameters:
name- name of the annotation type to look for, must not benull- Returns:
trueif the annotation is present,falseotherwise- 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:
annotationin interfaceAnnotationTarget- Parameters:
name- name of the annotation type to look for, must not benull- Returns:
- the annotation instance, or
nullif 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:
annotationsin 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:
annotationsWithRepeatablein interfaceAnnotationTarget- Parameters:
name- name of the annotation type, must not benullindex- 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 ifnamedoes 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:
annotationsin 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:
hasDeclaredAnnotationin interfaceAnnotationTarget- Parameters:
name- name of the annotation type to look for, must not benull- Returns:
trueif the annotation is present,falseotherwise- 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:
declaredAnnotationin interfaceAnnotationTarget- Parameters:
name- name of the annotation type to look for, must not benull- Returns:
- the annotation instance, or
nullif 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:
declaredAnnotationsWithRepeatablein interfaceAnnotationTarget- Parameters:
name- name of the annotation type, must not benullindex- 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 ifnamedoes 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:
declaredAnnotationsin 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.Modifiercan be used on this value.- Returns:
- the access flags of this method
-
isSynthetic
public boolean isSynthetic()- Returns:
trueif this method is a synthetic method
-
isBridge
public boolean isBridge()- Returns:
trueif this method is a bridge method as defined by the JLS,falseotherwise
-
isConstructor
public boolean isConstructor()- Returns:
trueif this method is a constructor
-
isStaticInitializer
public boolean isStaticInitializer()- Returns:
trueif 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:
trueif this method is a default interface method,falseotherwise
-
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 theSignaturebytecode attribute.- Specified by:
requiresGenericSignaturein 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 returnsnullfor 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:
genericSignaturein 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 returnsnullfor 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:
descriptorin 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:AnnotationTargetCasts and returns this target as aClassInfoif it is of kindCLASS- Specified by:
asClassin interfaceAnnotationTarget- Returns:
- this instance cast to a class
-
asField
Description copied from interface:AnnotationTargetCasts and returns this target as aFieldInfoif it is of kindFIELD- Specified by:
asFieldin interfaceAnnotationTarget- Returns:
- this instance cast to a field
-
asMethod
Description copied from interface:AnnotationTargetCasts and returns this target as aMethodInfoif it is of kindMETHOD- Specified by:
asMethodin interfaceAnnotationTarget- Returns:
- this instance cast to a method
-
asMethodParameter
Description copied from interface:AnnotationTargetCasts and returns this target as aMethodParameterInfoif it is of kindMETHOD_PARAMETER- Specified by:
asMethodParameterin interfaceAnnotationTarget- Returns:
- this instance cast to a method parameter
-
asType
Description copied from interface:AnnotationTargetCasts and returns this target as aTypeTargetif it is of kindTYPE- Specified by:
asTypein interfaceAnnotationTarget- Returns:
- this instance cast to a type target
-
asRecordComponent
Description copied from interface:AnnotationTargetCasts and returns this target as aRecordComponentInfoif it is of kindRECORD_COMPONENT- Specified by:
asRecordComponentin interfaceAnnotationTarget- Returns:
- this instance cast to a record component
-
parameterTypes()