bozaro / evo-classindex

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

About

ClassIndex is a much quicker alternative to every run-time annotation scanning library like Reflections or Scannotations.

ClassIndex is an annotation processor which at compile-time generates an index of classes implementing given interface, classes annotated by given annotation or placed in a common package. Java automatically discovers the processor from the classpath.

Changes

Version 3.0

  • Static inner classes are also indexed
  • Fix: incremental compilation in IntelliJ IDEA
  • You can now specify class loader
  • package name nad groupId has changed to org.atteo.classindex

Version 2.2

  • Fix: jaxb.index was in incorrect format

Version 2.1

  • Fix: custom processor with indexAnnotation() call resulted in javac throwing Error

Version 2.0

Version 1.4

  • Fix FileNotFoundException when executed under Tomcat from Eclipse

Version 1.3

  • Ignore classes which don't exist at runtime (#4). This fixes some issues in Eclipse.
  • Allow to create custom processors which index subclasses and packages

Version 1.2

  • Fix Eclipse support (#3)

Version 1.1

  • Fix incremental compilation (#1)

Basic usage

There are two annotations which trigger the indexing:

  • @IndexSubclasses when placed on interface makes an index of all classes implementing the interface, when placed on class makes an index of its subclasses and finally when placed in package-info.java it creates an index of all classes in that package.
  • @IndexAnnotated when placed on an annotation makes an index of all classes marked with that annotation. To access the index at run-time use static methods of ClassIndex class.
@IndexAnnotated
public @interface Entity {
}
 
@Entity
public class Car {
}
 
...
 
for (Class<?> klass : ClassIndex.getAnnotated(Entity.class)) {
    System.out.println(klass.getName());
}

For subclasses of the given class the index file name and format is compatible with what ServiceLoader expects. Keep in mind that ServiceLoader also requires for the classes to have zero-argument default constructor.

For classes inside given package the index file is named "jaxb.index", it is located inside the package folder and it's format is compatible with what JAXBContext.newInstance(String) expects.

Javadoc storage

From version 2.0 @IndexAnnotated and @IndexSubclasses allow to specify storeJavadoc attribute. When set to true Javadoc comment for the indexed classes will be stored. You can retrieve first sentence of the Javadoc using [ClassIndex.getClassSummary()](http://www.atteo.org/static/classindex/apidocs/org/atteo/classindex/ClassIndex.html#getClassSummary(java.lang.Class%29).

@IndexAnnotated(storeJavadoc = true)
public @interface Entity {
}
 
/**
 * This is car.
 * Detailed car description follows.
 */
@Entity
public class Car {
}
 
...
 
assertEquals("This is car", ClassIndex.getClassSummary(Car.class));

Eclipse

Eclipse uses its own Java compiler which is not strictly standard compliant and requires extra configuration. In Java Compiler -> Annotation Processing -> Factory Path you need to add both ClassIndex and Guava jar files. See the screenshot.

License

ClassIndex is available under Apache License 2.0.

Download

You can download the library from here or use the following Maven dependency:

<dependency>
    <groupId>org.atteo.classindex</groupId>
    <artifactId>classindex</artifactId>
    <version>3.0</version>
</dependency>

About

License:Apache License 2.0


Languages

Language:Java 100.0%