Class ClasspathScanner

java.lang.Object
dxt.scanpath.v2.ClasspathScanner

public class ClasspathScanner extends Object
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 Details

    • ClasspathScanner

      public ClasspathScanner()
      Creates a new classpath scanner to search for specific items on the classpath.
  • Method Details

    • load

      public void load(ScanScope sscope)
      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

      public List<String> dumpState(String identStr)
      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

      public void setClassLoader(ClassLoader cl)
      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

      public List<Class<?>> listInheritingClasses(Class<?> type)
      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

      public List<Class<?>> listAnnotatedClasses(Class<?> ann)
      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

      public List<Class<?>> listClassesWithAnnotatedFields(Class<?> ann)
      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

      public List<Class<?>> listClassesWithAnnotatedMethods(Class<?> ann)
      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.