Class Index<A extends java.lang.annotation.Annotation,​I>

  • All Implemented Interfaces:
    java.lang.Iterable<IndexItem<A,​I>>

    public final class Index<A extends java.lang.annotation.Annotation,​I>
    extends java.lang.Object
    implements java.lang.Iterable<IndexItem<A,​I>>
    Represents an index of a single annotation. Indices are not automatically cached (but reading them should be pretty cheap anyway).
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.Iterator<IndexItem<A,​I>> iterator()
      Find all items in the index.
      static <A extends java.lang.annotation.Annotation,​I>
      Index<A,​I>
      load​(java.lang.Class<A> annotation, java.lang.Class<I> instanceType)
      Load an index for a given annotation type.
      static <A extends java.lang.annotation.Annotation,​I>
      Index<A,​I>
      load​(java.lang.Class<A> annotation, java.lang.Class<I> instanceType, java.lang.ClassLoader loader)
      Load an index for a given annotation type.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
    • Method Detail

      • load

        public static <A extends java.lang.annotation.Annotation,​I> Index<A,​I> load​(java.lang.Class<A> annotation,
                                                                                                java.lang.Class<I> instanceType)
                                                                                         throws java.lang.IllegalArgumentException
        Load an index for a given annotation type. Uses the thread's context class loader to find the index and load annotated classes.
        Parameters:
        annotation - the type of annotation to find
        instanceType - the type of instance to be created (use Void if all instances will be null)
        Returns:
        an index of all elements known to be annotated with it
        Throws:
        java.lang.IllegalArgumentException - if the annotation type is not marked with Indexable or the instance type is not equal to or a supertype of the annotation's actual Indexable.type()
      • load

        public static <A extends java.lang.annotation.Annotation,​I> Index<A,​I> load​(java.lang.Class<A> annotation,
                                                                                                java.lang.Class<I> instanceType,
                                                                                                java.lang.ClassLoader loader)
                                                                                         throws java.lang.IllegalArgumentException
        Load an index for a given annotation type.
        Parameters:
        annotation - the type of annotation to find
        instanceType - the type of instance to be created (use Void if all instances will be null)
        loader - a class loader in which to find the index and any annotated classes
        Returns:
        an index of all elements known to be annotated with it
        Throws:
        java.lang.IllegalArgumentException - if the annotation type is not marked with Indexable or the instance type is not equal to or a supertype of the annotation's actual Indexable.type()
      • iterator

        public java.util.Iterator<IndexItem<A,​I>> iterator()
        Find all items in the index. Calls to iterator methods may fail with IndexError as the index is parsed lazily.
        Specified by:
        iterator in interface java.lang.Iterable<A extends java.lang.annotation.Annotation>
        Returns:
        an iterator over items in the index