Class ClassIndex
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 Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static void
findClasses
(ClassLoader classLoader, Set<Class<?>> classes, Iterable<String> entries) private static void
findClassesInPackage
(ClassLoader classLoader, String packageName, Set<Class<?>> classes, Iterable<String> entries) getAnnotated
(Class<? extends Annotation> annotation) Retrieves a list of classes annotated by given annotation.getAnnotated
(Class<? extends Annotation> annotation, ClassLoader classLoader) Retrieves a list of classes annotated by given annotation.getAnnotatedNames
(Class<? extends Annotation> annotation) Retrieves names of classes annotated by given annotation.getAnnotatedNames
(Class<? extends Annotation> annotation, ClassLoader classLoader) Retrieves names of classes annotated by given annotation.static String
getClassSummary
(Class<?> klass) Returns the Javadoc summary for given class.static String
getClassSummary
(Class<?> klass, ClassLoader classLoader) Returns the Javadoc summary for given class.getPackageClasses
(String packageName) Retrieves a list of classes from given package.getPackageClasses
(String packageName, ClassLoader classLoader) Retrieves a list of classes from given package.getPackageClassesNames
(String packageName) Retrieves names of classes from given package.getPackageClassesNames
(String packageName, ClassLoader classLoader) Retrieves names of classes from given package.getSubclasses
(Class<T> superClass) Retrieves a list of subclasses of the given class.getSubclasses
(Class<T> superClass, ClassLoader classLoader) Retrieves a list of subclasses of the given class.getSubclassesNames
(Class<T> superClass) Retrieves names of subclasses of the given class.getSubclassesNames
(Class<T> superClass, ClassLoader classLoader) Retrieves names of subclasses of the given class.readIndexFile
(ClassLoader classLoader, String resourceFile)
-
Field Details
-
SUBCLASS_INDEX_PREFIX
- See Also:
-
ANNOTATED_INDEX_PREFIX
- See Also:
-
PACKAGE_INDEX_NAME
- See Also:
-
JAVADOC_PREFIX
- See Also:
-
-
Constructor Details
-
ClassIndex
private ClassIndex()
-
-
Method Details
-
getSubclasses
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 byClassIndexProcessor
.- 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 byClassIndexProcessor
.- Parameters:
superClass
- class to find subclasses forclassLoader
- classloader for loading classes- Returns:
- list of subclasses
-
getSubclassesNames
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 byClassIndexProcessor
.- Parameters:
superClass
- class to find subclasses for- Returns:
- names of subclasses
-
getSubclassesNames
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 byClassIndexProcessor
.- Parameters:
superClass
- class to find subclasses forclassLoader
- classloader for loading index file- Returns:
- names of subclasses
-
getPackageClasses
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 byClassIndexProcessor
.- Parameters:
packageName
- name of the package to search classes for- Returns:
- list of classes from package
-
getPackageClasses
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 byClassIndexProcessor
.- Parameters:
packageName
- name of the package to search classes forclassLoader
- classloader for loading classes- Returns:
- list of classes from package
-
getPackageClassesNames
Retrieves names of classes from given package.The package must be annotated with
IndexSubclasses
for 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
Retrieves names of classes from given package.The package must be annotated with
IndexSubclasses
for 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
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 byClassIndexProcessor
.- 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 byClassIndexProcessor
.- Parameters:
annotation
- annotation to search class forclassLoader
- classloader for loading classes- Returns:
- list of annotated classes
-
getAnnotatedNames
Retrieves names of classes annotated by given annotation.The annotation must be annotated with
IndexAnnotated
for 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 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 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
Returns the Javadoc summary for given class.Javadoc summary is the first sentence of a Javadoc.
You need to use
IndexSubclasses
orIndexAnnotated
withIndexAnnotated.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
Returns the Javadoc summary for given class.Javadoc summary is the first sentence of a Javadoc.
You need to use
IndexSubclasses
orIndexAnnotated
withIndexAnnotated.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:
-
readIndexFile
-
findClasses
private static void findClasses(ClassLoader classLoader, Set<Class<?>> classes, Iterable<String> entries) -
findClassesInPackage
-