Package com.zetaplugins.zetacore.scan
Class ClassScanner
java.lang.Object
com.zetaplugins.zetacore.scan.ClassScanner
Scans a package for classes using a specific class loader.
Class files are read without loading them; only classes matching a query are loaded (without being initialized).
The package is scanned once, on first use, and the result is reused for every query.
Share one instance between the ServiceRegistry and the registrars
instead of letting each of them scan on its own.
If ZetaCore is shaded and relocated into the scanned package, its own classes are excluded. Classes that cannot be loaded (for example because they depend on a plugin that is not installed) are skipped.
-
Constructor Summary
ConstructorsConstructorDescriptionClassScanner(String packagePrefix, ClassLoader classLoader) Creates a scanner for the given package. -
Method Summary
Modifier and TypeMethodDescriptionGets the class loader used for scanning and loading classes.Gets the scanned package.getSubTypesOf(Class<T> type) Finds all subtypes of the given type.getTypesAnnotatedWith(Class<? extends Annotation> annotation) Finds all classes annotated with the given annotation, including subclasses of annotated classes and classes annotated with an annotation that is itself annotated with it.getTypesWithMethodsAnnotatedWith(Class<? extends Annotation> annotation) Finds all classes that declare at least one method annotated with the given annotation.
-
Constructor Details
-
ClassScanner
Creates a scanner for the given package.- Parameters:
packagePrefix- The package to scan, including all sub-packages.classLoader- The class loader that can see the classes in the package (usually the plugin's class loader).
-
-
Method Details
-
getPackagePrefix
Gets the scanned package.- Returns:
- The package prefix.
-
getClassLoader
Gets the class loader used for scanning and loading classes.- Returns:
- The class loader.
-
getTypesAnnotatedWith
Finds all classes annotated with the given annotation, including subclasses of annotated classes and classes annotated with an annotation that is itself annotated with it.- Parameters:
annotation- The annotation to look for.- Returns:
- The annotated classes, sorted by name.
-
getSubTypesOf
Finds all subtypes of the given type.- Type Parameters:
T- The supertype.- Parameters:
type- The supertype.- Returns:
- The subtypes, not including the type itself, sorted by name.
-
getTypesWithMethodsAnnotatedWith
Finds all classes that declare at least one method annotated with the given annotation.- Parameters:
annotation- The method annotation to look for.- Returns:
- The declaring classes, sorted by name.
-