Class TypeTarget

    • Method Detail

      • setTarget

        void setTarget​(Type target)
      • enclosingTarget

        public AnnotationTarget enclosingTarget()
        Returns the enclosing target that contains the type referred to by the target() method.
        Returns:
        the enclosing target
      • target

        public Type target()
        Returns the type which contains the respective annotation. In some cases this may be null (e.g. in the case of a bridge method, which erases type information so there is no target to map to)
        Returns:
        the type containing the respective annotation
      • usage

        public abstract TypeTarget.Usage usage()
        Returns the kind of usage of this type target. This allows a caller to use a switch statement as opposed to getClass() comparisons.
        Returns:
        the kind of usage of this type target
      • asClassExtends

        public ClassExtendsTypeTarget asClassExtends()
        Casts and returns this type target as a ClassExtendsTypeTarget. If this type target is not a ClassExtendsTypeTarget, then an exception will be thrown.
        Returns:
        an instance of ClassExtendsTypeTarget
        Throws:
        java.lang.IllegalArgumentException - if this is not a ClassExtendsTypeTarget
      • asMethodParameterType

        public MethodParameterTypeTarget asMethodParameterType()
        Casts and returns this type target as a MethodParameterTypeTarget. If this type target is not a MethodParameterTypeTarget, then an exception will be thrown.
        Returns:
        an instance of MethodParameterTypeTarget
        Throws:
        java.lang.IllegalArgumentException - if this is not a MethodParameterTypeTarget
      • asTypeParameter

        public TypeParameterTypeTarget asTypeParameter()
        Casts and returns this type target as a TypeParameterTypeTarget. If this type target is not a TypeParameterTypeTarget, then an exception will be thrown.
        Returns:
        an instance of TypeParameterTypeTarget
        Throws:
        java.lang.IllegalArgumentException - if this is not a TypeParameterTypeTarget
      • asTypeParameterBound

        public TypeParameterBoundTypeTarget asTypeParameterBound()
        Casts and returns this type target as a TypeParameterBoundTypeTarget. If this type target is not a TypeParameterBoundTypeTarget, then an exception will be thrown.
        Returns:
        an instance of TypeParameterBoundTypeTarget
        Throws:
        java.lang.IllegalArgumentException - if this is not a TypeParameterBoundTypeTarget
      • asThrows

        public ThrowsTypeTarget asThrows()
        Casts and returns this type target as a ThrowsTypeTarget. If this type target is not a ThrowsTypeTarget, then an exception will be thrown.
        Returns:
        an instance of ThrowsTypeTarget
        Throws:
        java.lang.IllegalArgumentException - if this is not a TypeParameterBoundTypeTarget
      • 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
      • 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
      • hasAnnotation

        public boolean hasAnnotation​(DotName name)
        Returns whether an annotation instance with given name is declared on this type usage.

        Note that unlike other AnnotationTargets, this method doesn't inspect nested annotation targets, even though array types, parameterized types, type variables and wildcard types may contain other types inside them. In other words, this method is equivalent to hasDeclaredAnnotation(DotName).

        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(DotName)
      • annotation

        public AnnotationInstance annotation​(DotName name)
        Returns the annotation instance with given name declared on this type usage.

        Note that unlike other AnnotationTargets, this method doesn't inspect nested annotation targets, even though array types, parameterized types, type variables and wildcard types may contain other types inside them. In other words, this method is equivalent to declaredAnnotation(DotName).

        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(DotName)
      • annotationsWithRepeatable

        public java.util.List<AnnotationInstance> annotationsWithRepeatable​(DotName name,
                                                                            IndexView index)
        Returns the annotation instances with given name declared on this type usage.

        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.

        Note that unlike other AnnotationTargets, this method doesn't inspect nested annotation targets, even though array types, parameterized types, type variables and wildcard types may contain other types inside them. In other words, this method is equivalent to declaredAnnotationsWithRepeatable(DotName, IndexView).

        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:
        java.lang.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(DotName), annotations()
      • annotations

        public java.util.List<AnnotationInstance> annotations()
        Returns the annotation instances declared on this type usage.

        Note that unlike other AnnotationTargets, this method doesn't inspect nested annotation targets, even though array types, parameterized types, type variables and wildcard types may contain other types inside them. In other words, this method is equivalent to declaredAnnotations().

        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 type usage.
        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:
        hasAnnotation(DotName)
      • declaredAnnotation

        public AnnotationInstance declaredAnnotation​(DotName name)
        Returns the annotation instance with given name declared on this type usage.
        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:
        annotation(DotName)
      • declaredAnnotationsWithRepeatable

        public java.util.List<AnnotationInstance> declaredAnnotationsWithRepeatable​(DotName name,
                                                                                    IndexView index)
        Returns the annotation instances with given name declared on this type usage.

        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:
        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:
        java.lang.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:
        annotationsWithRepeatable(DotName, IndexView)