/easy-reflect

Small, zero dependency library to make working with reflection (for example finding all classes with a certain annotation in a package) easier.

Primary LanguageJavaApache License 2.0Apache-2.0

EasyReflect

Example usage:

final EasyReflect easyReflect = EasyReflect.builder()
    .classLoader(ClassLoader.getSystemClassLoader())
    .ignoredPackage("com.example.project.external")
    .resolvePackage("com.example.project")
    .build();

easyReflect.resolvePackage(ClassLoader.getSystemClassLoader(), "com.example.external");
    
final Map<Class<?>, ExampleAnnotation> results = easyReflect.findAnnotatedClasses(ExampleAnnotation.class);
final ExampleAnnotation exampleAnnotation = results.get(Example.class);
assertEquals("exampleStringValue", exampleAnnotation.value())

Example in the entry class (simplified):

final EasyReflect easyReflect = EasyReflect.owned(this.getClass());
final Map<Class<?>, ExampleAnnotation> results = easyReflect.findAnnotatedClasses(ExampleAnnotation.class);
final ExampleAnnotation exampleAnnotation = results.get(Example.class);
assertEquals("exampleStringValue", exampleAnnotation.value())
<repositories>
    <repository>
        <id>jitpack.io</id>
	<url>https://jitpack.io</url>
    </repository>
</repositories>

<dependency>
    <groupId>com.github.dexuby</groupId>
    <artifactId>easy-reflect</artifactId>
    <version>...</version>
</dependency>