Package ru.objectsfill.utils
Class ScanningForClassUtils
java.lang.Object
ru.objectsfill.utils.ScanningForClassUtils
Utility class for scanning classes and retrieving annotated instances or implementations of interfaces.
-
Method Summary
Modifier and TypeMethodDescriptionstatic Class<?>Deduces the main application class by inspecting the stack trace.static <T> List<T>scanClassImplInterface(Class<T> castInterface, String packagePath) Scans the classpath for classes implementing a specific interface.static <T extends Annotation,K>
List<K>scanProjectForAnnotationAndCastToInterface(Class<T> annotationClazz, Class<K> castInterface) Scans the project for classes annotated with a specific annotation and casts them to a given interface.
-
Method Details
-
scanProjectForAnnotationAndCastToInterface
public static <T extends Annotation,K> List<K> scanProjectForAnnotationAndCastToInterface(Class<T> annotationClazz, Class<K> castInterface) Scans the project for classes annotated with a specific annotation and casts them to a given interface.- Type Parameters:
T- the type of the annotationK- the type of the interface- Parameters:
annotationClazz- the class object representing the annotation to scan forcastInterface- the class object representing the interface to cast the annotated classes to- Returns:
- a list of instances of the annotated classes casted to the specified interface
-
scanClassImplInterface
Scans the classpath for classes implementing a specific interface.- Type Parameters:
T- the type of the interface- Parameters:
castInterface- the class object representing the interface to scan for implementationspackagePath- the package path to scan for classes- Returns:
- a list of instances of the classes implementing the specified interface
-
deduceMainApplicationClass
Deduces the main application class by inspecting the stack trace.- Returns:
- the main application class, or null if it cannot be deduced
-