Package org.jboss.jandex
Class MethodInfo
- java.lang.Object
-
- org.jboss.jandex.MethodInfo
-
- All Implemented Interfaces:
AnnotationTarget
public final class MethodInfo extends java.lang.Object implements AnnotationTarget
Represents a Java method, constructor, or static initializer.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
Fields Modifier and Type Field Description private ClassInfoclazz(package private) static java.lang.String[]EMPTY_PARAMETER_NAMESprivate MethodInternalmethodInternal
-
Constructor Summary
Constructors Constructor Description MethodInfo()MethodInfo(ClassInfo clazz, byte[] name, byte[][] parameterNames, Type[] parameters, Type returnType, short flags)MethodInfo(ClassInfo clazz, byte[] name, byte[][] parameterNames, Type[] parameters, Type returnType, short flags, Type[] typeParameters, Type[] exceptions)MethodInfo(ClassInfo clazz, MethodInternal methodInternal)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description AnnotationInstanceannotation(DotName name)Retrieves an annotation instance declared on this method, it parameters, or any type within the signature of the method, by the name of the annotation.java.util.List<AnnotationInstance>annotations()Returns the annotation instances declared on this method.java.util.List<AnnotationInstance>annotations(DotName name)Retrieves annotations declared on this method, by the name of the annotation.java.util.List<AnnotationInstance>annotationsWithRepeatable(DotName name, IndexView index)Retrieves annotations declared on this method, by the name of the annotation.Type[]args()Deprecated.ClassInfoasClass()Casts and returns this target as aClassInfoif it is of kindCLASSFieldInfoasField()Casts and returns this target as aFieldInfoif it is of kindFIELDMethodInfoasMethod()Casts and returns this target as aMethodInfoif it is of kindMETHODMethodParameterInfoasMethodParameter()Casts and returns this target as aMethodParameterInfoif it is of kindMETHOD_PARAMETERRecordComponentInfoasRecordComponent()Casts and returns this target as aRecordComponentInfoif it is of kindRECORD_COMPONENTTypeTargetasType()Casts and returns this target as aTypeTargetif it is of kindTYPE(package private) Type[]copyExceptions()(package private) Type[]copyParameters()static MethodInfocreate(ClassInfo clazz, java.lang.String name, java.lang.String[] parameterNames, Type[] args, Type returnType, short flags, TypeVariable[] typeParameters, Type[] exceptions)Construct a new mock Method instance.static MethodInfocreate(ClassInfo clazz, java.lang.String name, Type[] args, Type returnType, short flags)Construct a new mock Method instance.static MethodInfocreate(ClassInfo clazz, java.lang.String name, Type[] args, Type returnType, short flags, TypeVariable[] typeParameters, Type[] exceptions)Construct a new mock Method instance.ClassInfodeclaringClass()Returns the class that declared this methodAnnotationValuedefaultValue()Returns the default annotation value if this method represents an annotation member with a default value.booleanequals(java.lang.Object o)java.util.List<Type>exceptions()Returns the list of throwable classes declared to be thrown by this method.shortflags()Returns the access fields of this method.booleanhasAnnotation(DotName name)Returns whether or not the annotation instance with the given name occurs on this method, its parameters or its signatureinthashCode()booleanisSynthetic()AnnotationTarget.Kindkind()Returns the kind of object this target represents.(package private) MethodInternalmethodInternal()java.lang.Stringname()Returns the name of this methodjava.lang.StringparameterName(int i)Returns the name of the given parameter.java.util.List<Type>parameters()Returns a list containing the types of all parameters declared on this method, in parameter order.TypereceiverType()Returns the receiver type of this method (a declaration of the "this" reference), if specified.TypereturnType()Returns this method's return parameter type.(package private) voidsetAnnotations(java.util.List<AnnotationInstance> annotations)(package private) voidsetClassInfo(ClassInfo clazz)(package private) voidsetDefaultValue(AnnotationValue defaultValue)(package private) voidsetExceptions(Type[] exceptions)(package private) voidsetMethodInternal(MethodInternal methodInternal)(package private) voidsetParameters(Type[] parameters)(package private) voidsetReceiverType(Type receiverType)(package private) voidsetReturnType(Type returnType)(package private) voidsetTypeParameters(Type[] typeParameters)java.lang.StringtoString()Returns a string representation describing this field.(package private) Type[]typeParameterArray()java.util.List<TypeVariable>typeParameters()Returns the generic type parameters defined by this method.
-
-
-
Field Detail
-
EMPTY_PARAMETER_NAMES
static final java.lang.String[] EMPTY_PARAMETER_NAMES
-
methodInternal
private MethodInternal methodInternal
-
clazz
private ClassInfo clazz
-
-
Constructor Detail
-
MethodInfo
MethodInfo()
-
MethodInfo
MethodInfo(ClassInfo clazz, MethodInternal methodInternal)
-
MethodInfo
MethodInfo(ClassInfo clazz, byte[] name, byte[][] parameterNames, Type[] parameters, Type returnType, short flags)
-
-
Method Detail
-
create
public static MethodInfo create(ClassInfo clazz, java.lang.String name, Type[] args, Type returnType, short flags)
Construct a new mock Method instance.- Parameters:
clazz- the class declaring the fieldname- the name of the fieldargs- 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, java.lang.String name, Type[] args, 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 fieldargs- 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, java.lang.String name, java.lang.String[] parameterNames, Type[] args, 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 parameterargs- 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
public final java.lang.String name()
Returns the name of this method- Returns:
- the name of the method
-
parameterName
public final java.lang.String parameterName(int i)
Returns the name of the given parameter.- Parameters:
i- the parameter index- Returns:
- the name of the given parameter, or null.
-
kind
public final AnnotationTarget.Kind kind()
Description copied from interface:AnnotationTargetReturns the kind of object this target represents.- Specified by:
kindin interfaceAnnotationTarget- Returns:
- the target kind.
-
declaringClass
public final ClassInfo declaringClass()
Returns the class that declared this method- Returns:
- the declaring class
-
args
@Deprecated public final Type[] args()
Deprecated.Returns an array containing parameter types in parameter order. This method performs a defensive array copy per call, and should be avoided. Instead theparameters()method should be used.- Returns:
- an array copy contain parameter types
-
copyParameters
final Type[] copyParameters()
-
parameters
public final java.util.List<Type> parameters()
Returns a list containing the types of all parameters declared on this method, in parameter order. This method may return an empty list, but never null.- Returns:
- all parameter types on this method
-
returnType
public final Type 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
public final Type 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
public final java.util.List<Type> 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:
- the list of throwable classes thrown by this method
-
copyExceptions
final Type[] copyExceptions()
-
typeParameters
public final java.util.List<TypeVariable> 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:
- the list of generic type parameters for this method, or an empty list if none
-
annotations
public final java.util.List<AnnotationInstance> annotations()
Returns the annotation instances declared on this method. This includes annotations which are defined against method parameters, as well as type annotations declared on any usage within the method signature. Thetarget()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> list) {...} public <@AnotherTypeAnnotation T> void foo(T t) {...}- Returns:
- the annotation instances declared on this method or its parameters, or an empty list if none
-
annotation
public final AnnotationInstance annotation(DotName name)
Retrieves an annotation instance declared on this method, it parameters, or any type within the signature of the method, by the name of the annotation. If an annotation by that name is not present, null will be returned.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> list) {...} public <@AnotherTypeAnnotation T> void foo(T t) {...}- Parameters:
name- the name of the annotation to locate within the method- Returns:
- the annotation if found, otherwise, null
-
annotationsWithRepeatable
public final java.util.List<AnnotationInstance> annotationsWithRepeatable(DotName name, IndexView index)
Retrieves annotations declared on this method, by the name of the annotation. This includes annotations which are defined against method parameters, as well as type annotations declared on any usage within the method signature. Thetarget()of the returned annotation instances may be used to determine the exact location of the respective annotation instance. If the specified annotation is repeatable (JLS 9.6), the result also contains all values from the container annotation instances. In this case, theAnnotationInstance.target()returns the target of the container annotation instance.- Parameters:
name- the name of the annotationindex- the index used to obtain the annotation class- Returns:
- the annotation instances declared on this method or its parameters, or an empty list if none
- Throws:
java.lang.IllegalArgumentException- If the index does not contain the annotation definition or if it does not represent an annotation type
-
annotations
public final java.util.List<AnnotationInstance> annotations(DotName name)
Retrieves annotations declared on this method, by the name of the annotation. This includes annotations which are defined against method parameters, as well as type annotations declared on any usage within the method signature. Thetarget()of the returned annotation instances may be used to determine the exact location of the respective annotation instance.- Parameters:
name-- Returns:
- the annotation instances declared on this method or its parameters, or an empty list if none
-
hasAnnotation
public final boolean hasAnnotation(DotName name)
Returns whether or not the annotation instance with the given name occurs on this method, its parameters or its signature- Parameters:
name- the name of the annotation to look for- Returns:
- true if the annotation is present, false otherwise
- See Also:
annotations(),annotation(DotName)
-
defaultValue
public AnnotationValue 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 final boolean isSynthetic()
- Returns:
trueif this method is a synthetic method
-
toString
public java.lang.String toString()
Returns a string representation describing this field. It is similar although not necessarily equivalent to a Java source code expression representing this field.- Overrides:
toStringin classjava.lang.Object- Returns:
- a string representation for this field
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
asClass
public final ClassInfo 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
public final FieldInfo 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
public final MethodInfo 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
public final MethodParameterInfo 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
public final TypeTarget 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
public RecordComponentInfo 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
-
methodInternal
final MethodInternal methodInternal()
-
setMethodInternal
final void setMethodInternal(MethodInternal methodInternal)
-
setClassInfo
final void setClassInfo(ClassInfo clazz)
-
typeParameterArray
final Type[] typeParameterArray()
-
setTypeParameters
void setTypeParameters(Type[] typeParameters)
-
setParameters
void setParameters(Type[] parameters)
-
setReturnType
void setReturnType(Type returnType)
-
setExceptions
void setExceptions(Type[] exceptions)
-
setReceiverType
void setReceiverType(Type receiverType)
-
setAnnotations
void setAnnotations(java.util.List<AnnotationInstance> annotations)
-
setDefaultValue
void setDefaultValue(AnnotationValue defaultValue)
-
-