Class ClasspathScanner
java.lang.Object
dxt.scanpath.v2.ClasspathScanner
Scans one or more Java classpaths and indexes the discovered types so callers can query
inheritance, annotation, field, and method metadata without having to load every class manually.
- Author:
- indroneel
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new classpath scanner to search for specific items on the classpath. -
Method Summary
Modifier and TypeMethodDescriptionDumps the internal state of the classpath scanner, in terms of the list of Java types that were discovered and indexed, along with their inheritance, annotation, field, and method metadata.listAnnotatedClasses(Class<?> ann) Retrieves a list of Java types, that are qualified with the given annotation.listClassesWithAnnotatedFields(Class<?> ann) Retrieves a list of Java types, that encapsulates at least one field, that is qualified with the given annotation.listClassesWithAnnotatedMethods(Class<?> ann) Retrieves a list of Java types, that encapsulates at least one method, that is qualified with the given annotation.listInheritingClasses(Class<?> type) Retrieves a list of Java types that derives/implements, either directly or indirectly, the given type.voidPrepare the list of Java types that would be further looked up for types with specific characteristics and/or constructs.voidSets a custom classloader that is subsequently used to load classes from the scanned class path.
-
Constructor Details
-
ClasspathScanner
public ClasspathScanner()Creates a new classpath scanner to search for specific items on the classpath.
-
-
Method Details
-
load
Prepare the list of Java types that would be further looked up for types with specific characteristics and/or constructs.- Parameters:
sscope- provides the configuration, in terms of classpaths and name matching criteria, that is used to arrive at the list of Java types for further lookup.
-
dumpState
Dumps the internal state of the classpath scanner, in terms of the list of Java types that were discovered and indexed, along with their inheritance, annotation, field, and method metadata.- Parameters:
identStr- a string that is used to indent the output for better readability.- Returns:
- a list of strings, each string being a line of the dumped state.
-
setClassLoader
Sets a custom classloader that is subsequently used to load classes from the scanned class path.- Parameters:
cl- a custom classloader that is used to load the classes. A null value will default to the system classloader.
-
listInheritingClasses
Retrieves a list of Java types that derives/implements, either directly or indirectly, the given type.- Parameters:
type- a Java type that is present on the type hierarchy for each entry in the returned list of Java types.- Returns:
- the corresponding list of Java types.
-
listAnnotatedClasses
Retrieves a list of Java types, that are qualified with the given annotation. The list also includes types that derive from or inherit at least one Java type that is qualified with the given annotation.- Parameters:
ann- the annotation, the target type being a Java class.- Returns:
- the corresponding list of Java types that have the annotation, or derive/inherit from one or more Java types that bear the annotation.
-
listClassesWithAnnotatedFields
Retrieves a list of Java types, that encapsulates at least one field, that is qualified with the given annotation. The list also includes types that derive/inherit from at least one Java type that encapsulates at least one field that is qualified with the given annotation.- Parameters:
ann- the annotation, the target type being a field within a Java class.- Returns:
- the corresponding list of Java types.
-
listClassesWithAnnotatedMethods
Retrieves a list of Java types, that encapsulates at least one method, that is qualified with the given annotation. The list also includes types that derive/inherit from at least one Java type that encapsulates at least one method that is qualified with the given annotation.- Parameters:
ann- the annotation, the target type being a method within a Java class.- Returns:
- the corresponding list of Java types.
-