Class ClassIndex

java.lang.Object
org.atteo.classindex.ClassIndex

public class ClassIndex extends Object
Access to the compile-time generated index of classes.

Use @IndexAnnotated and @IndexSubclasses annotations to force the classes to be indexed.

Keep in mind that the class is indexed only when it is compiled with classindex.jar file in classpath.

Also to preserve class-index data when creating shaded jar you should use the following Maven configuration:

 
 <build>
   <plugins>
     <plugin>
       <groupId>org.apache.maven.plugins</groupId>
       <artifactId>maven-shade-plugin</artifactId>
       <version>1.4</version>
       <executions>
         <execution>
           <phase>package</phase>
           <goals>
             <goal>shade</goal>
           </goals>
           <configuration>
             <transformers>
               <transformer implementation="org.atteo.classindex.ClassIndexTransformer"/>
             </transformers>
           </configuration>
         </execution>
       </executions>
       <dependencies>
         <groupId>org.atteo.classindex</groupId>
         <artifactId>classindex-transformer</artifactId>
       </dependencies>
     </plugin>
   </plugins>
 </build>
 
 

  • Field Details

  • Constructor Details

    • ClassIndex

      private ClassIndex()
  • Method Details

    • getSubclasses

      public static <T> Iterable<Class<? extends T>> getSubclasses(Class<T> superClass)
      Retrieves a list of subclasses of the given class.

      The class must be annotated with IndexSubclasses for it's subclasses to be indexed at compile-time by ClassIndexProcessor.

      Parameters:
      superClass - class to find subclasses for
      Returns:
      list of subclasses
    • getSubclasses

      public static <T> Iterable<Class<? extends T>> getSubclasses(Class<T> superClass, ClassLoader classLoader)
      Retrieves a list of subclasses of the given class.

      The class must be annotated with IndexSubclasses for it's subclasses to be indexed at compile-time by ClassIndexProcessor.

      Parameters:
      superClass - class to find subclasses for
      classLoader - classloader for loading classes
      Returns:
      list of subclasses
    • getSubclassesNames

      public static <T> Iterable<String> getSubclassesNames(Class<T> superClass)
      Retrieves names of subclasses of the given class.

      The class must be annotated with IndexSubclasses for it's subclasses to be indexed at compile-time by ClassIndexProcessor.

      Parameters:
      superClass - class to find subclasses for
      Returns:
      names of subclasses
    • getSubclassesNames

      public static <T> Iterable<String> getSubclassesNames(Class<T> superClass, ClassLoader classLoader)
      Retrieves names of subclasses of the given class.

      The class must be annotated with IndexSubclasses for it's subclasses to be indexed at compile-time by ClassIndexProcessor.

      Parameters:
      superClass - class to find subclasses for
      classLoader - classloader for loading index file
      Returns:
      names of subclasses
    • getPackageClasses

      public static Iterable<Class<?>> getPackageClasses(String packageName)
      Retrieves a list of classes from given package.

      The package must be annotated with IndexSubclasses for the classes inside to be indexed at compile-time by ClassIndexProcessor.

      Parameters:
      packageName - name of the package to search classes for
      Returns:
      list of classes from package
    • getPackageClasses

      public static Iterable<Class<?>> getPackageClasses(String packageName, ClassLoader classLoader)
      Retrieves a list of classes from given package.

      The package must be annotated with IndexSubclasses for the classes inside to be indexed at compile-time by ClassIndexProcessor.

      Parameters:
      packageName - name of the package to search classes for
      classLoader - classloader for loading classes
      Returns:
      list of classes from package
    • getPackageClassesNames

      public static Iterable<String> getPackageClassesNames(String packageName)
      Retrieves names of classes from given package.

      The package must be annotated with IndexSubclasses for the classes inside to be indexed at compile-time by ClassIndexProcessor.

      Parameters:
      packageName - name of the package to search classes for
      Returns:
      names of classes from package
    • getPackageClassesNames

      public static Iterable<String> getPackageClassesNames(String packageName, ClassLoader classLoader)
      Retrieves names of classes from given package.

      The package must be annotated with IndexSubclasses for the classes inside to be indexed at compile-time by ClassIndexProcessor.

      Parameters:
      packageName - name of the package to search classes for
      classLoader - classloader for loading index file
      Returns:
      names of classes from package
    • getAnnotated

      public static Iterable<Class<?>> getAnnotated(Class<? extends Annotation> annotation)
      Retrieves a list of classes annotated by given annotation.

      The annotation must be annotated with IndexAnnotated for annotated classes to be indexed at compile-time by ClassIndexProcessor.

      Parameters:
      annotation - annotation to search class for
      Returns:
      list of annotated classes
    • getAnnotated

      public static Iterable<Class<?>> getAnnotated(Class<? extends Annotation> annotation, ClassLoader classLoader)
      Retrieves a list of classes annotated by given annotation.

      The annotation must be annotated with IndexAnnotated for annotated classes to be indexed at compile-time by ClassIndexProcessor.

      Parameters:
      annotation - annotation to search class for
      classLoader - classloader for loading classes
      Returns:
      list of annotated classes
    • getAnnotatedNames

      public static Iterable<String> getAnnotatedNames(Class<? extends Annotation> annotation)
      Retrieves names of classes annotated by given annotation.

      The annotation must be annotated with IndexAnnotated for annotated classes to be indexed at compile-time by ClassIndexProcessor.

      Please note there is no verification if the class really exists. It can be missing when incremental compilation is used. Use getAnnotated(Class) if you need the verification.

      Parameters:
      annotation - annotation to search class for
      Returns:
      names of annotated classes
    • getAnnotatedNames

      public static Iterable<String> getAnnotatedNames(Class<? extends Annotation> annotation, ClassLoader classLoader)
      Retrieves names of classes annotated by given annotation.

      The annotation must be annotated with IndexAnnotated for annotated classes to be indexed at compile-time by ClassIndexProcessor.

      Please note there is no verification if the class really exists. It can be missing when incremental compilation is used. Use getAnnotated(Class, ClassLoader) if you need the verification.

      Parameters:
      annotation - annotation to search class for
      classLoader - classloader for loading the index file
      Returns:
      names of annotated classes
    • getClassSummary

      public static String getClassSummary(Class<?> klass)
      Returns the Javadoc summary for given class.

      Javadoc summary is the first sentence of a Javadoc.

      You need to use IndexSubclasses or IndexAnnotated with IndexAnnotated.storeJavadoc() set to true.

      Parameters:
      klass - class to retrieve summary for
      Returns:
      summary for given class, or null if it does not exists
      See Also:
    • getClassSummary

      public static String getClassSummary(Class<?> klass, ClassLoader classLoader)
      Returns the Javadoc summary for given class.

      Javadoc summary is the first sentence of a Javadoc.

      You need to use IndexSubclasses or IndexAnnotated with IndexAnnotated.storeJavadoc() set to true.

      Parameters:
      klass - class to retrieve summary for
      classLoader - classloader for loading classes
      Returns:
      summary for given class, or null if it does not exists
      See Also:
    • readIndexFile

      private static Iterable<String> readIndexFile(ClassLoader classLoader, String resourceFile)
    • findClasses

      private static void findClasses(ClassLoader classLoader, Set<Class<?>> classes, Iterable<String> entries)
    • findClassesInPackage

      private static void findClassesInPackage(ClassLoader classLoader, String packageName, Set<Class<?>> classes, Iterable<String> entries)