A fully automated annotation processor leveraging the Reflections library for efficient class operations.
- 🔍 Automated annotation processing
- 📚 Supports multiple class loaders
- 🔄 Simplifies repetitive class operations
This module combines with the Reflections library to implement a fully automated annotation processor. It's particularly useful for performing repetitive operations on classes.
dependencies {
// Annotation module
compileOnly(files("libs/annotation-1.0-SNAPSHOT.jar"))
}
Imagine you have many books at home, each with different stickers on the cover. When you want to find books with a specific type of sticker, you can ask a helper to look through all the books, identify those with the desired stickers, and pick them out.
- AnnotationProcessingService: Finds classes with specific annotations (like finding books with certain stickers).
- CustomAnnotationProcessor: Performs operations on these classes (like organizing the selected books).
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface SimplixSerializerSerializableAutoRegister {
}
@AnnotationProcessor(SimplixSerializerSerializableAutoRegister.class)
public class SimplixSerializerSerializableAutoRegisterProcessor implements CustomAnnotationProcessor {
@Override
public void process(Class<?> clazz) throws Exception {
// Perform operations
}
@Override
public void exception(Class<?> clazz, Exception exception) {
// Handle exceptions
}
}
@FairyLaunch
public class Launcher extends Plugin {
@Autowired
private AnnotationProcessingServiceInterface annotationProcessingService;
@Override
public void onPluginEnable() {
List<String> basePackages = List.of(
"org.example",
"net.legacy.library.configuration.serialize.annotation"
);
annotationProcessingService.processAnnotations(
basePackages,
false,
this.getClassLoader(),
ConfigurationLauncher.class.getClassLoader()
);
}
}
Each module operates as a plugin, akin to a library containing various books (classes). To access classes from other plugins, you need their ClassLoader
.
- ClassLoader: Think of it as a library. Each plugin is an independent library storing classes it uses.
- Multiple ClassLoaders: Allow scanning across different plugins, ensuring all relevant classes are processed.
By providing multiple ClassLoaders
, AnnotationProcessingService
can scan and match all classes managed by these loaders, handing over the correct classes to CustomAnnotationProcessor
for processing.
This project is licensed under the MIT License - see the LICENSE file for details