Skip to content

Latest commit

 

History

History
125 lines (92 loc) · 4.15 KB

README.md

File metadata and controls

125 lines (92 loc) · 4.15 KB

📚 Annotation Module

A fully automated annotation processor leveraging the Reflections library for efficient class operations.

JDK License

📋 Table of Contents

✨ Features

  • 🔍 Automated annotation processing
  • 📚 Supports multiple class loaders
  • 🔄 Simplifies repetitive class operations

📝 Introduction

This module combines with the Reflections library to implement a fully automated annotation processor. It's particularly useful for performing repetitive operations on classes.

💻 Usage

Dependencies

dependencies {
    // Annotation module
    compileOnly(files("libs/annotation-1.0-SNAPSHOT.jar"))
}

Concept

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).

Example

Define an Annotation

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface SimplixSerializerSerializableAutoRegister {
}

Implement a Processor

@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
    }
}

Usage in a Plugin

@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()
        );
    }
}

📚 ClassLoader Explanation

Each module operates as a plugin, akin to a library containing various books (classes). To access classes from other plugins, you need their ClassLoader.

Key Concepts

  • 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.

🔗 Additional Resources

📄 License

This project is licensed under the MIT License - see the LICENSE file for details