Class MethodParameterInfo

java.lang.Object
org.jboss.jandex.MethodParameterInfo
All Implemented Interfaces:
AnnotationTarget, Declaration

public final class MethodParameterInfo extends Object implements Declaration
Represents an individual Java method parameter that was annotated.

Thread-Safety

This class is immutable and can be shared between threads without safe publication.
  • Field Details

    • method

      private final MethodInfo method
    • position

      private final short position
  • Constructor Details

    • MethodParameterInfo

      MethodParameterInfo(MethodInfo method, short position)
  • Method Details

    • create

      public static MethodParameterInfo create(MethodInfo method, short parameter)
      Constructs a new mock method parameter info
      Parameters:
      method - the method containing this parameter.
      parameter - the zero based index of this parameter
      Returns:
      the new mock parameter info
    • method

      public final MethodInfo method()
      Returns the method this parameter belongs to.
      Returns:
      the declaring Java method
    • position

      public final short position()
      Returns the 0 based position of this parameter.
      Returns:
      the position of this parameter
    • name

      public final String name()
      Returns the name of this parameter, or null if not known.
      Returns:
      the name of this parameter, or null if not known
    • type

      public final Type type()
      Returns the type of this parameter.
      Returns:
      the type of this parameter
      Since:
      3.0
    • targetsThis

      private boolean targetsThis(AnnotationInstance annotation)
    • targetsThisOrNested

      private boolean targetsThisOrNested(AnnotationInstance annotation)
    • hasAnnotation

      public boolean hasAnnotation(DotName name)
      Returns whether an annotation instance with given name is declared on this method parameter or any type within its signature.
      Specified by:
      hasAnnotation in interface AnnotationTarget
      Parameters:
      name - name of the annotation type to look for, must not be null
      Returns:
      true if the annotation is present, false otherwise
      Since:
      3.0
      See Also:
    • annotation

      public AnnotationInstance annotation(DotName name)
      Returns the annotation instance with given name declared on this method parameter or any type within its signature. The target() method of the returned annotation instance may be used to determine the exact location of the annotation instance.

      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 interface AnnotationTarget
      Parameters:
      name - name of the annotation type to look for, must not be null
      Returns:
      the annotation instance, or null if not found
      Since:
      3.0
      See Also:
    • annotations

      public List<AnnotationInstance> annotations(DotName name)
      Returns the annotation instances with given name declared on this method parameter or any type within its signature. The target() method of the returned annotation instances may be used to determine the exact location of the respective annotation instance.
      Specified by:
      annotations in interface AnnotationTarget
      Parameters:
      name - name of the annotation type, must not be null
      Returns:
      immutable list of annotation instances, never null
      Since:
      3.0
      See Also:
    • annotationsWithRepeatable

      public List<AnnotationInstance> annotationsWithRepeatable(DotName name, IndexView index)
      Returns the annotation instances with given name declared on this method parameter or any type within its signature. The 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.

      Specified by:
      annotationsWithRepeatable in interface AnnotationTarget
      Parameters:
      name - name of the annotation type, must not be null
      index - index used to obtain the annotation type, must not be null
      Returns:
      immutable list of annotation instances, never null
      Throws:
      IllegalArgumentException - if the index is null, if the index does not contain the annotation type or if name does not identify an annotation type
      Since:
      3.0
      See Also:
    • annotations

      public List<AnnotationInstance> annotations()
      Returns the annotation instances declared on this method parameter or any type within its signature. The target() method of the returned annotation instances may be used to determine the exact location of the respective annotation instance.
      Specified by:
      annotations in interface AnnotationTarget
      Returns:
      immutable list of annotation instances, never null
      Since:
      3.0
    • hasDeclaredAnnotation

      public boolean hasDeclaredAnnotation(DotName name)
      Returns whether an annotation instance with given name is declared on this method parameter.

      Unlike hasAnnotation(DotName), this method ignores annotations declared on types within the methor parameter signature.

      Specified by:
      hasDeclaredAnnotation in interface AnnotationTarget
      Parameters:
      name - name of the annotation type to look for, must not be null
      Returns:
      true if the annotation is present, false otherwise
      Since:
      3.0
      See Also:
    • declaredAnnotation

      public AnnotationInstance declaredAnnotation(DotName name)
      Returns the annotation instance with given name declared on this method parameter.

      Unlike annotation(DotName), this method doesn't return annotations declared on types within the methor parameter signature.

      Specified by:
      declaredAnnotation in interface AnnotationTarget
      Parameters:
      name - name of the annotation type to look for, must not be null
      Returns:
      the annotation instance, or null if not found
      Since:
      3.0
      See Also:
    • declaredAnnotationsWithRepeatable

      public List<AnnotationInstance> declaredAnnotationsWithRepeatable(DotName name, IndexView index)
      Returns the annotation instances with given name declared on this method parameter.

      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 types within the methor parameter signature.

      Specified by:
      declaredAnnotationsWithRepeatable in interface AnnotationTarget
      Parameters:
      name - name of the annotation type, must not be null
      index - index used to obtain the annotation type, must not be null
      Returns:
      immutable list of annotation instances, never null
      Throws:
      IllegalArgumentException - if the index is null, if the index does not contain the annotation type or if name does not identify an annotation type
      Since:
      3.0
      See Also:
    • declaredAnnotations

      public List<AnnotationInstance> declaredAnnotations()
      Returns the annotation instances declared on this method parameter.

      Unlike annotations(), this method doesn't return annotations declared on types within the methor parameter signature.

      Specified by:
      declaredAnnotations in interface AnnotationTarget
      Returns:
      immutable list of annotation instances, never null
      Since:
      3.0
      See Also:
    • toString

      public String toString()
      Returns a string representation describing this method parameter. It is similar although not necessarily identical to a Java source code declaration of this method parameter.
      Overrides:
      toString in class Object
      Returns:
      a string representation of this method parameter
    • asClass

      public final ClassInfo asClass()
      Description copied from interface: AnnotationTarget
      Casts and returns this target as a ClassInfo if it is of kind CLASS
      Specified by:
      asClass in interface AnnotationTarget
      Returns:
      this instance cast to a class
    • asField

      public final FieldInfo asField()
      Description copied from interface: AnnotationTarget
      Casts and returns this target as a FieldInfo if it is of kind FIELD
      Specified by:
      asField in interface AnnotationTarget
      Returns:
      this instance cast to a field
    • asMethod

      public final MethodInfo asMethod()
      Description copied from interface: AnnotationTarget
      Casts and returns this target as a MethodInfo if it is of kind METHOD
      Specified by:
      asMethod in interface AnnotationTarget
      Returns:
      this instance cast to a method
    • asMethodParameter

      public final MethodParameterInfo asMethodParameter()
      Description copied from interface: AnnotationTarget
      Casts and returns this target as a MethodParameterInfo if it is of kind METHOD_PARAMETER
      Specified by:
      asMethodParameter in interface AnnotationTarget
      Returns:
      this instance cast to a method parameter
    • asType

      public final TypeTarget asType()
      Description copied from interface: AnnotationTarget
      Casts and returns this target as a TypeTarget if it is of kind TYPE
      Specified by:
      asType in interface AnnotationTarget
      Returns:
      this instance cast to a type target
    • asRecordComponent

      public final RecordComponentInfo asRecordComponent()
      Description copied from interface: AnnotationTarget
      Casts and returns this target as a RecordComponentInfo if it is of kind RECORD_COMPONENT
      Specified by:
      asRecordComponent in interface AnnotationTarget
      Returns:
      this instance cast to a record component
    • kind

      public AnnotationTarget.Kind kind()
      Description copied from interface: AnnotationTarget
      Returns the kind of object this target represents.
      Specified by:
      kind in interface AnnotationTarget
      Returns:
      the target kind.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object