Class ClassIndex
- java.lang.Object
-
- org.atteo.classindex.ClassIndex
-
public class ClassIndex extends java.lang.ObjectAccess to the compile-time generated index of classes.Use @
IndexAnnotatedand @IndexSubclassesannotations 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 Summary
Fields Modifier and Type Field Description static java.lang.StringANNOTATED_INDEX_PREFIXstatic java.lang.StringJAVADOC_PREFIXstatic java.lang.StringPACKAGE_INDEX_NAMEstatic java.lang.StringSUBCLASS_INDEX_PREFIX
-
Constructor Summary
Constructors Modifier Constructor Description privateClassIndex()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static voidfindClasses(java.lang.ClassLoader classLoader, java.util.Set<java.lang.Class<?>> classes, java.lang.Iterable<java.lang.String> entries)private static voidfindClassesInPackage(java.lang.ClassLoader classLoader, java.lang.String packageName, java.util.Set<java.lang.Class<?>> classes, java.lang.Iterable<java.lang.String> entries)static java.lang.Iterable<java.lang.Class<?>>getAnnotated(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)Retrieves a list of classes annotated by given annotation.static java.lang.Iterable<java.lang.Class<?>>getAnnotated(java.lang.Class<? extends java.lang.annotation.Annotation> annotation, java.lang.ClassLoader classLoader)Retrieves a list of classes annotated by given annotation.static java.lang.Iterable<java.lang.String>getAnnotatedNames(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)Retrieves names of classes annotated by given annotation.static java.lang.Iterable<java.lang.String>getAnnotatedNames(java.lang.Class<? extends java.lang.annotation.Annotation> annotation, java.lang.ClassLoader classLoader)Retrieves names of classes annotated by given annotation.static java.lang.StringgetClassSummary(java.lang.Class<?> klass)Returns the Javadoc summary for given class.static java.lang.StringgetClassSummary(java.lang.Class<?> klass, java.lang.ClassLoader classLoader)Returns the Javadoc summary for given class.static java.lang.Iterable<java.lang.Class<?>>getPackageClasses(java.lang.String packageName)Retrieves a list of classes from given package.static java.lang.Iterable<java.lang.Class<?>>getPackageClasses(java.lang.String packageName, java.lang.ClassLoader classLoader)Retrieves a list of classes from given package.static java.lang.Iterable<java.lang.String>getPackageClassesNames(java.lang.String packageName)Retrieves names of classes from given package.static java.lang.Iterable<java.lang.String>getPackageClassesNames(java.lang.String packageName, java.lang.ClassLoader classLoader)Retrieves names of classes from given package.static <T> java.lang.Iterable<java.lang.Class<? extends T>>getSubclasses(java.lang.Class<T> superClass)Retrieves a list of subclasses of the given class.static <T> java.lang.Iterable<java.lang.Class<? extends T>>getSubclasses(java.lang.Class<T> superClass, java.lang.ClassLoader classLoader)Retrieves a list of subclasses of the given class.static <T> java.lang.Iterable<java.lang.String>getSubclassesNames(java.lang.Class<T> superClass)Retrieves names of subclasses of the given class.static <T> java.lang.Iterable<java.lang.String>getSubclassesNames(java.lang.Class<T> superClass, java.lang.ClassLoader classLoader)Retrieves names of subclasses of the given class.private static java.lang.Iterable<java.lang.String>readIndexFile(java.lang.ClassLoader classLoader, java.lang.String resourceFile)
-
-
-
Field Detail
-
SUBCLASS_INDEX_PREFIX
public static final java.lang.String SUBCLASS_INDEX_PREFIX
- See Also:
- Constant Field Values
-
ANNOTATED_INDEX_PREFIX
public static final java.lang.String ANNOTATED_INDEX_PREFIX
- See Also:
- Constant Field Values
-
PACKAGE_INDEX_NAME
public static final java.lang.String PACKAGE_INDEX_NAME
- See Also:
- Constant Field Values
-
JAVADOC_PREFIX
public static final java.lang.String JAVADOC_PREFIX
- See Also:
- Constant Field Values
-
-
Method Detail
-
getSubclasses
public static <T> java.lang.Iterable<java.lang.Class<? extends T>> getSubclasses(java.lang.Class<T> superClass)
Retrieves a list of subclasses of the given class.The class must be annotated with
IndexSubclassesfor it's subclasses to be indexed at compile-time byClassIndexProcessor.- Parameters:
superClass- class to find subclasses for- Returns:
- list of subclasses
-
getSubclasses
public static <T> java.lang.Iterable<java.lang.Class<? extends T>> getSubclasses(java.lang.Class<T> superClass, java.lang.ClassLoader classLoader)Retrieves a list of subclasses of the given class.The class must be annotated with
IndexSubclassesfor it's subclasses to be indexed at compile-time byClassIndexProcessor.- Parameters:
superClass- class to find subclasses forclassLoader- classloader for loading classes- Returns:
- list of subclasses
-
getSubclassesNames
public static <T> java.lang.Iterable<java.lang.String> getSubclassesNames(java.lang.Class<T> superClass)
Retrieves names of subclasses of the given class.The class must be annotated with
IndexSubclassesfor it's subclasses to be indexed at compile-time byClassIndexProcessor.- Parameters:
superClass- class to find subclasses for- Returns:
- names of subclasses
-
getSubclassesNames
public static <T> java.lang.Iterable<java.lang.String> getSubclassesNames(java.lang.Class<T> superClass, java.lang.ClassLoader classLoader)Retrieves names of subclasses of the given class.The class must be annotated with
IndexSubclassesfor it's subclasses to be indexed at compile-time byClassIndexProcessor.- Parameters:
superClass- class to find subclasses forclassLoader- classloader for loading index file- Returns:
- names of subclasses
-
getPackageClasses
public static java.lang.Iterable<java.lang.Class<?>> getPackageClasses(java.lang.String packageName)
Retrieves a list of classes from given package.The package must be annotated with
IndexSubclassesfor the classes inside to be indexed at compile-time byClassIndexProcessor.- Parameters:
packageName- name of the package to search classes for- Returns:
- list of classes from package
-
getPackageClasses
public static java.lang.Iterable<java.lang.Class<?>> getPackageClasses(java.lang.String packageName, java.lang.ClassLoader classLoader)Retrieves a list of classes from given package.The package must be annotated with
IndexSubclassesfor the classes inside to be indexed at compile-time byClassIndexProcessor.- Parameters:
packageName- name of the package to search classes forclassLoader- classloader for loading classes- Returns:
- list of classes from package
-
getPackageClassesNames
public static java.lang.Iterable<java.lang.String> getPackageClassesNames(java.lang.String packageName)
Retrieves names of classes from given package.The package must be annotated with
IndexSubclassesfor the classes inside to be indexed at compile-time byClassIndexProcessor.- Parameters:
packageName- name of the package to search classes for- Returns:
- names of classes from package
-
getPackageClassesNames
public static java.lang.Iterable<java.lang.String> getPackageClassesNames(java.lang.String packageName, java.lang.ClassLoader classLoader)Retrieves names of classes from given package.The package must be annotated with
IndexSubclassesfor the classes inside to be indexed at compile-time byClassIndexProcessor.- Parameters:
packageName- name of the package to search classes forclassLoader- classloader for loading index file- Returns:
- names of classes from package
-
getAnnotated
public static java.lang.Iterable<java.lang.Class<?>> getAnnotated(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
Retrieves a list of classes annotated by given annotation.The annotation must be annotated with
IndexAnnotatedfor annotated classes to be indexed at compile-time byClassIndexProcessor.- Parameters:
annotation- annotation to search class for- Returns:
- list of annotated classes
-
getAnnotated
public static java.lang.Iterable<java.lang.Class<?>> getAnnotated(java.lang.Class<? extends java.lang.annotation.Annotation> annotation, java.lang.ClassLoader classLoader)Retrieves a list of classes annotated by given annotation.The annotation must be annotated with
IndexAnnotatedfor annotated classes to be indexed at compile-time byClassIndexProcessor.- Parameters:
annotation- annotation to search class forclassLoader- classloader for loading classes- Returns:
- list of annotated classes
-
getAnnotatedNames
public static java.lang.Iterable<java.lang.String> getAnnotatedNames(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
Retrieves names of classes annotated by given annotation.The annotation must be annotated with
IndexAnnotatedfor annotated classes to be indexed at compile-time byClassIndexProcessor.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 java.lang.Iterable<java.lang.String> getAnnotatedNames(java.lang.Class<? extends java.lang.annotation.Annotation> annotation, java.lang.ClassLoader classLoader)Retrieves names of classes annotated by given annotation.The annotation must be annotated with
IndexAnnotatedfor annotated classes to be indexed at compile-time byClassIndexProcessor.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 forclassLoader- classloader for loading the index file- Returns:
- names of annotated classes
-
getClassSummary
public static java.lang.String getClassSummary(java.lang.Class<?> klass)
Returns the Javadoc summary for given class.Javadoc summary is the first sentence of a Javadoc.
You need to use
IndexSubclassesorIndexAnnotatedwithIndexAnnotated.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:
- Writing doc comments
-
getClassSummary
public static java.lang.String getClassSummary(java.lang.Class<?> klass, java.lang.ClassLoader classLoader)Returns the Javadoc summary for given class.Javadoc summary is the first sentence of a Javadoc.
You need to use
IndexSubclassesorIndexAnnotatedwithIndexAnnotated.storeJavadoc()set to true.- Parameters:
klass- class to retrieve summary forclassLoader- classloader for loading classes- Returns:
- summary for given class, or null if it does not exists
- See Also:
- Writing doc comments
-
readIndexFile
private static java.lang.Iterable<java.lang.String> readIndexFile(java.lang.ClassLoader classLoader, java.lang.String resourceFile)
-
findClasses
private static void findClasses(java.lang.ClassLoader classLoader, java.util.Set<java.lang.Class<?>> classes, java.lang.Iterable<java.lang.String> entries)
-
findClassesInPackage
private static void findClassesInPackage(java.lang.ClassLoader classLoader, java.lang.String packageName, java.util.Set<java.lang.Class<?>> classes, java.lang.Iterable<java.lang.String> entries)
-
-