diff --git a/annotation/README.md b/annotation/README.md index 5313fbf..ec832b8 100644 --- a/annotation/README.md +++ b/annotation/README.md @@ -57,7 +57,7 @@ This is very simple, right? But now that the definition is complete, how does th @InjectableComponent public class AnnotationLauncher extends Plugin { @Autowired - private AnnotationProcessingService annotationProcessingService; + private AnnotationProcessingServiceInterface annotationProcessingService; @Override public void onPluginEnable() { diff --git a/annotation/src/main/java/me/qwqdev/library/annotation/service/AnnotationProcessingService.java b/annotation/src/main/java/me/qwqdev/library/annotation/service/AnnotationProcessingService.java index 1fbe278..1383c0c 100644 --- a/annotation/src/main/java/me/qwqdev/library/annotation/service/AnnotationProcessingService.java +++ b/annotation/src/main/java/me/qwqdev/library/annotation/service/AnnotationProcessingService.java @@ -1,57 +1,123 @@ package me.qwqdev.library.annotation.service; +import io.fairyproject.container.Containers; +import io.fairyproject.container.InjectableComponent; +import io.fairyproject.log.Log; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; +import me.qwqdev.library.annotation.utils.AnnotationScanner; +import org.reflections.util.ClasspathHelper; + +import java.lang.annotation.Annotation; +import java.lang.reflect.InvocationTargetException; import java.net.URL; import java.util.Collection; +import java.util.Set; /** - * Service interface for processing annotations using custom annotation processors. + * Service implementation for processing annotations using custom annotation processors. * - *
This interface defines methods for processing annotations within classes in the specified base package or - * from a collection of URLs. It allows for processing using default or custom annotation processors. + *
This class provides the core functionality for scanning and processing annotations + * within a specified package or set of URLs. It implements the {@link AnnotationProcessingServiceInterface} + * interface and uses reflection to dynamically instantiate and execute custom annotation processors. * * @author qwq-dev * @version 1.1 + * @see AnnotationProcessingServiceInterface + * @see CustomAnnotationProcessor + * @see AnnotationProcessor * @since 2024-12-19 17:00 */ -public interface AnnotationProcessingService { +@InjectableComponent +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class AnnotationProcessingService implements AnnotationProcessingServiceInterface { /** - * Processes annotations within the specified base package using the default annotation processors. - * - *
This method scans the specified base package and its sub-packages for classes annotated with specific - * annotations, and then processes them using default annotation processors. + * {@inheritDoc} * - * @param basePackage the base package to scan for annotated classes - * @param fromFairyIoCSingleton whether handlerClass should be injected into a singleton by the Fairy framework - * If false, it will be created by reflection without parameters, - * but it still supports setter injection with Fairy {@link io.fairyproject.container.Autowired} annotation - * @param classLoader optional class loaders to use for classpath scanning; if not provided, the default class loader is used + * @param basePackage {@inheritDoc} + * @param classLoader {@inheritDoc} + * @param fromFairyIoCSingleton {@inheritDoc} */ - void processAnnotations(String basePackage, boolean fromFairyIoCSingleton, ClassLoader... classLoader); + @Override + public void processAnnotations(String basePackage, boolean fromFairyIoCSingleton, ClassLoader... classLoader) { + processAnnotations(ClasspathHelper.forPackage(basePackage, classLoader), fromFairyIoCSingleton); + } /** - * Processes annotations within the specified collection of URLs using default annotation processors. - * - *
This method scans the classes located at the provided URLs for annotations and processes them using
- * default annotation processors. The URLs can represent locations like JAR files, directories, or classpath entries.
+ * {@inheritDoc}
*
- * @param urls the collection of URLs to scan for annotated classes
- * @param fromFairyIoCSingleton whether handlerClass should be injected into a singleton by the Fairy framework
- * If false, it will be created by reflection without parameters,
- * but it still supports setter injection with Fairy {@link io.fairyproject.container.Autowired} annotation
+ * @param urls {@inheritDoc}
+ * @param fromFairyIoCSingleton {@inheritDoc}
*/
- void processAnnotations(Collection This method allows for processing annotations in the classes located at the specified URLs using a custom
- * annotation processor, which allows for more fine-grained control over the processing logic.
+ * {@inheritDoc}
*
- * @param urls the collection of URLs to scan for annotated classes
- * @param handlerClass the class of the custom annotation processor to handle annotation processing
- * @param fromFairyIoCSingleton whether handlerClass should be injected into a singleton by the Fairy framework
- * If false, it will be created by reflection without parameters,
- * but it still supports setter injection with Fairy {@link io.fairyproject.container.Autowired} annotation
+ * @param urls {@inheritDoc}
+ * @param handlerClass {@inheritDoc}
+ * @param fromFairyIoCSingleton {@inheritDoc}
*/
- void processAnnotations(Collection This class provides the core functionality for scanning and processing annotations
- * within a specified package or set of URLs. It implements the {@link AnnotationProcessingService}
- * interface and uses reflection to dynamically instantiate and execute custom annotation processors.
- *
- * @author qwq-dev
- * @version 1.1
- * @see AnnotationProcessingService
- * @see CustomAnnotationProcessor
- * @see AnnotationProcessor
- * @since 2024-12-19 17:00
- */
-@InjectableComponent
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public class AnnotationProcessingServiceImpl implements AnnotationProcessingService {
- /**
- * {@inheritDoc}
- *
- * @param basePackage {@inheritDoc}
- * @param classLoader {@inheritDoc}
- * @param fromFairyIoCSingleton {@inheritDoc}
- */
- @Override
- public void processAnnotations(String basePackage, boolean fromFairyIoCSingleton, ClassLoader... classLoader) {
- processAnnotations(ClasspathHelper.forPackage(basePackage, classLoader), fromFairyIoCSingleton);
- }
-
- /**
- * {@inheritDoc}
- *
- * @param urls {@inheritDoc}
- * @param fromFairyIoCSingleton {@inheritDoc}
- */
- @Override
- public void processAnnotations(Collection This interface defines methods for processing annotations within classes in the specified base package or
+ * from a collection of URLs. It allows for processing using default or custom annotation processors.
+ *
+ * @author qwq-dev
+ * @version 1.1
+ * @since 2024-12-19 17:00
+ */
+public interface AnnotationProcessingServiceInterface {
+ /**
+ * Processes annotations within the specified base package using the default annotation processors.
+ *
+ * This method scans the specified base package and its sub-packages for classes annotated with specific
+ * annotations, and then processes them using default annotation processors.
+ *
+ * @param basePackage the base package to scan for annotated classes
+ * @param fromFairyIoCSingleton whether handlerClass should be injected into a singleton by the Fairy framework
+ * If false, it will be created by reflection without parameters,
+ * but it still supports setter injection with Fairy {@link io.fairyproject.container.Autowired} annotation
+ * @param classLoader optional class loaders to use for classpath scanning; if not provided, the default class loader is used
+ */
+ void processAnnotations(String basePackage, boolean fromFairyIoCSingleton, ClassLoader... classLoader);
+
+ /**
+ * Processes annotations within the specified collection of URLs using default annotation processors.
+ *
+ * This method scans the classes located at the provided URLs for annotations and processes them using
+ * default annotation processors. The URLs can represent locations like JAR files, directories, or classpath entries.
+ *
+ * @param urls the collection of URLs to scan for annotated classes
+ * @param fromFairyIoCSingleton whether handlerClass should be injected into a singleton by the Fairy framework
+ * If false, it will be created by reflection without parameters,
+ * but it still supports setter injection with Fairy {@link io.fairyproject.container.Autowired} annotation
+ */
+ void processAnnotations(Collection This method allows for processing annotations in the classes located at the specified URLs using a custom
+ * annotation processor, which allows for more fine-grained control over the processing logic.
+ *
+ * @param urls the collection of URLs to scan for annotated classes
+ * @param handlerClass the class of the custom annotation processor to handle annotation processing
+ * @param fromFairyIoCSingleton whether handlerClass should be injected into a singleton by the Fairy framework
+ * If false, it will be created by reflection without parameters,
+ * but it still supports setter injection with Fairy {@link io.fairyproject.container.Autowired} annotation
+ */
+ void processAnnotations(Collection