Package 

Class AnnotationList

  • All Implemented Interfaces:
    kotlin.collections.Collection , kotlin.collections.Iterable , kotlin.collections.List

    
    public abstract class AnnotationList
     implements List<Annotation>
                        

    A list of annotations and methods to access them. This is used similarly to AnnotatedElement, but exists to allow multiple semantically distinct sets of annotations on a single object.

    Unlike AnnotatedElement, which has methods for both "present" and "declared" annotations, AnnotationList models that dichotomy using multiple AnnotationList objects. Though the documentation in this class uses the term "present", it is not referring to the definition of "present" as laid out in AnnotatedElement, it is simply used for brevity.

    This is an abstract class instead of an interface so it can have Kotlin inline methods that use reified types.

    Note: when used as a List, this object is immutable.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private final Integer size
    • Constructor Summary

      Constructors 
      Constructor Description
      AnnotationList()
    • Method Summary

      Modifier and Type Method Description
      abstract Integer getSize()
      abstract Boolean isPresent(Class<out Annotation> annotationClass) Returns true if an annotation for the specified type is present on this element, else false.
      abstract <T extends Annotation> T get(Class<T> annotationClass) Returns this element's annotation for the specified type if such an annotation is present, else null.
      abstract <T extends Annotation> Array<T> getAllByType(Class<T> annotationClass) Returns annotations that are associated with this element.
      abstract String toJavaString(String joiner, String trailing) If this list is empty, an empty string will be returned, otherwise returns the Java-like string representation of this annotation list with annotations separated by joiner and trailing appended to the end.
      abstract String toKotlinString(String joiner, String trailing) If this list is empty, an empty string will be returned, otherwise returns the Kotlin-like string representation of this annotation list with annotations separated by joiner and trailing appended to the end.
      String toString()
      • Methods inherited from class dev.thecodewarrior.mirror.util.AnnotationList

        contains, containsAll, get, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, spliterator, subList
      • Methods inherited from class kotlin.collections.Collection

        forEach
      • Methods inherited from class kotlin.collections.List

        parallelStream, stream
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AnnotationList

        AnnotationList()
    • Method Detail

      • isPresent

         abstract Boolean isPresent(Class<out Annotation> annotationClass)

        Returns true if an annotation for the specified type is present on this element, else false. This method is designed primarily for convenient access to marker annotations.

      • get

         abstract <T extends Annotation> T get(Class<T> annotationClass)

        Returns this element's annotation for the specified type if such an annotation is present, else null.

      • getAllByType

         abstract <T extends Annotation> Array<T> getAllByType(Class<T> annotationClass)

        Returns annotations that are associated with this element.

        If there are no annotations associated with this element, the return value is an array of length 0.

        The difference between this method and get is that this method detects if its argument is a repeatable annotation type (JLS 9.6), and if so, attempts to find one or more annotations of that type by "looking through" a container annotation.

        The caller of this method is free to modify the returned array; it will have no effect on the arrays returned to other callers.

      • toJavaString

         abstract String toJavaString(String joiner, String trailing)

        If this list is empty, an empty string will be returned, otherwise returns the Java-like string representation of this annotation list with annotations separated by joiner and trailing appended to the end.

      • toKotlinString

         abstract String toKotlinString(String joiner, String trailing)

        If this list is empty, an empty string will be returned, otherwise returns the Kotlin-like string representation of this annotation list with annotations separated by joiner and trailing appended to the end.