public final class MethodInfo extends Object implements AnnotationTarget
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.
Thread-Safety
This class is immutable and can be shared between threads without safe publication.AnnotationTarget.Kind| Modifier and Type | Method and Description |
|---|---|
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.
|
List<AnnotationInstance> |
annotations()
Returns the annotation instances declared on this method, any of its parameters or any type
within its signature.
|
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.
|
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.
|
Type[] |
args()
Deprecated.
use
parameterTypes() |
ClassInfo |
asClass()
Casts and returns this target as a
ClassInfo if it is of kind CLASS |
FieldInfo |
asField()
Casts and returns this target as a
FieldInfo if it is of kind FIELD |
MethodInfo |
asMethod()
Casts and returns this target as a
MethodInfo if it is of kind METHOD |
MethodParameterInfo |
asMethodParameter()
Casts and returns this target as a
MethodParameterInfo if it is of kind METHOD_PARAMETER |
RecordComponentInfo |
asRecordComponent()
Casts and returns this target as a
RecordComponentInfo if it is of kind RECORD_COMPONENT |
TypeTarget |
asType()
Casts and returns this target as a
TypeTarget if it is of kind 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 |
create(ClassInfo clazz,
String name,
Type[] parameterTypes,
Type returnType,
short flags)
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.
|
AnnotationInstance |
declaredAnnotation(DotName name)
Returns the annotation instance with given name declared on this method.
|
List<AnnotationInstance> |
declaredAnnotations()
Returns the annotation instances declared on this method.
|
List<AnnotationInstance> |
declaredAnnotationsWithRepeatable(DotName name,
IndexView index)
Returns the annotation instances with given name declared on this method.
|
ClassInfo |
declaringClass()
Returns the class that declared this method
|
AnnotationValue |
defaultValue()
Returns the default annotation value if this method represents an annotation member with a default value.
|
int |
descriptorParametersCount()
Returns the number of all parameters present on this method, based on the method descriptor.
|
List<Type> |
descriptorParameterTypes()
Returns a list of types of all parameters present on this method, based on the method descriptor.
|
boolean |
equals(Object o) |
List<Type> |
exceptions()
Returns the list of throwable classes declared to be thrown by this method.
|
short |
flags()
Returns the access fields of this method.
|
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 |
isSynthetic() |
AnnotationTarget.Kind |
kind()
Returns the kind of object this target represents.
|
String |
name()
Returns the name of this method
|
String |
parameterName(int i)
Returns the name of the given parameter.
|
List<MethodParameterInfo> |
parameters()
Returns a list of parameters declared on this method, in declaration order.
|
int |
parametersCount()
Returns the number of parameters this method declares.
|
Type |
parameterType(int i)
Returns the type of the given parameter.
|
List<Type> |
parameterTypes()
Returns a list of types of parameters declared on this method, in declaration order.
|
Type |
receiverType()
Returns the receiver type of this method (a declaration of the "this" reference), if specified.
|
Type |
returnType()
Returns this method's return parameter type.
|
String |
toString()
Returns a string representation describing this field.
|
List<TypeVariable> |
typeParameters()
Returns the generic type parameters defined by this method.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, waitannotation, annotation, annotations, annotations, annotationsWithRepeatable, annotationsWithRepeatable, declaredAnnotation, declaredAnnotation, declaredAnnotationsWithRepeatable, declaredAnnotationsWithRepeatable, hasAnnotation, hasAnnotation, hasDeclaredAnnotation, hasDeclaredAnnotationpublic static MethodInfo create(ClassInfo clazz, String name, Type[] parameterTypes, Type returnType, short flags)
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 attributespublic static MethodInfo create(ClassInfo clazz, String name, Type[] parameterTypes, Type returnType, short flags, TypeVariable[] typeParameters, Type[] exceptions)
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 methodpublic static MethodInfo create(ClassInfo clazz, String name, String[] parameterNames, Type[] parameterTypes, Type returnType, short flags, TypeVariable[] typeParameters, Type[] exceptions)
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 methodpublic final String name()
public final String parameterName(int i)
i - the parameter index, zero-basednull if not knownpublic final Type parameterType(int i)
i - the parameter index, zero-basedpublic final AnnotationTarget.Kind kind()
AnnotationTargetkind in interface AnnotationTargetpublic final ClassInfo declaringClass()
@Deprecated public final Type[] args()
parameterTypes()
This method performs a defensive array copy per call, and should be avoided.
Instead, the parameterTypes() method should be used.
public final int parametersCount()
public final List<Type> parameterTypes()
parameterName(int)
or look for annotations.nullpublic final List<MethodParameterInfo> parameters()
nullpublic final int descriptorParametersCount()
public final List<Type> descriptorParameterTypes()
parameterName(int) or look for annotations.public final Type returnType()
public final Type receiverType()
public final List<Type> exceptions()
public final List<TypeVariable> typeParameters()
public final boolean hasAnnotation(DotName name)
hasAnnotation in interface AnnotationTargetname - name of the annotation type to look for, must not be nulltrue if the annotation is present, false otherwiseannotation(DotName)public final AnnotationInstance annotation(DotName name)
target() 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.
annotation in interface AnnotationTargetname - name of the annotation type to look for, must not be nullnull if not foundannotations(DotName)public final List<AnnotationInstance> annotations(DotName name)
target() 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) {...}
annotations in interface AnnotationTargetname - name of the annotation type, must not be nullnullannotationsWithRepeatable(DotName, IndexView),
annotations()public final List<AnnotationInstance> annotationsWithRepeatable(DotName name, IndexView index)
target() 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.
annotationsWithRepeatable in interface AnnotationTargetname - name of the annotation type, must not be nullindex - index used to obtain the annotation type, must not be nullnullIllegalArgumentException - if the index is null, if the index does not contain the annotation type
or if name does not identify an annotation typeannotations(DotName),
annotations()public final List<AnnotationInstance> annotations()
target() 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) {...}
annotations in interface AnnotationTargetnullpublic boolean hasDeclaredAnnotation(DotName name)
Unlike hasAnnotation(DotName), this method ignores annotations declared on the method parameters
and types within the method signature.
hasDeclaredAnnotation in interface AnnotationTargetname - name of the annotation type to look for, must not be nulltrue if the annotation is present, false otherwisehasAnnotation(DotName)public AnnotationInstance declaredAnnotation(DotName name)
Unlike annotation(DotName), this method doesn't return annotations declared on the method parameters
and types within the method signature.
declaredAnnotation in interface AnnotationTargetname - name of the annotation type to look for, must not be nullnull if not foundannotation(DotName)public List<AnnotationInstance> declaredAnnotationsWithRepeatable(DotName name, IndexView index)
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.
declaredAnnotationsWithRepeatable in interface AnnotationTargetname - name of the annotation type, must not be nullindex - index used to obtain the annotation type, must not be nullnullIllegalArgumentException - if the index is null, if the index does not contain the annotation type
or if name does not identify an annotation typeannotationsWithRepeatable(DotName, IndexView)public List<AnnotationInstance> declaredAnnotations()
Unlike annotations(), this method doesn't return annotations declared on the method parameters
and types within the method signature.
declaredAnnotations in interface AnnotationTargetnullannotations()public AnnotationValue defaultValue()
public final short flags()
Modifier can be used on this value.public final boolean isSynthetic()
true if this method is a synthetic methodpublic String toString()
public final ClassInfo asClass()
AnnotationTargetClassInfo if it is of kind CLASSasClass in interface AnnotationTargetpublic final FieldInfo asField()
AnnotationTargetFieldInfo if it is of kind FIELDasField in interface AnnotationTargetpublic final MethodInfo asMethod()
AnnotationTargetMethodInfo if it is of kind METHODasMethod in interface AnnotationTargetpublic final MethodParameterInfo asMethodParameter()
AnnotationTargetMethodParameterInfo if it is of kind METHOD_PARAMETERasMethodParameter in interface AnnotationTargetpublic final TypeTarget asType()
AnnotationTargetTypeTarget if it is of kind TYPEasType in interface AnnotationTargetpublic final RecordComponentInfo asRecordComponent()
AnnotationTargetRecordComponentInfo if it is of kind RECORD_COMPONENTasRecordComponent in interface AnnotationTargetCopyright © 2018–2022. All rights reserved.