Class ClassPathScanner

java.lang.Object
tk.airshipcraft.commonlib.utils.classes.ClassPathScanner

public class ClassPathScanner extends Object
A utility class for scanning the classpath to find classes of a particular type. It can scan within specified packages or across the entire classpath. This can be particularly useful for dynamically loading classes at runtime for purposes such as plugin systems or application frameworks.
Since:
2023-05-31
Version:
1.0.0
Author:
Locutusque, notzune
  • Constructor Details

    • ClassPathScanner

      public ClassPathScanner()
      Default constructor.
    • ClassPathScanner

      public ClassPathScanner(String... packages)
      Constructor with package names to restrict the scanning scope.
      Parameters:
      packages - Array of package names to scan within.
  • Method Details

    • scanClasses

      public List<Class<?>> scanClasses(Class<?> superClass, String... packages)
      Scans for all classes extending the specified superclass within the given package names.
      Parameters:
      superClass - The class to scan for subclasses.
      packages - A list of package names to restrict the scanning scope.
      Returns:
      A list of classes that extend the specified superclass.
    • scanClasses

      public <T> List<Class<? extends T>> scanClasses(Class<T> superClass, List<String> packages)
      Scans for all classes extending the specified superclass within the given package names.
      Type Parameters:
      T - The type parameter representing the superclass.
      Parameters:
      superClass - The class to scan for subclasses.
      packages - A list of package names to restrict the scanning scope.
      Returns:
      A list of classes that extend the specified superclass.
    • scanClasses

      public List<Class<?>> scanClasses()
      Scans for all .class files available in the classpath of the current thread's context class loader. It is assumed that this method will be used in an environment where the classes are unpacked or directly available as .class files (not within a JAR).
      Returns:
      A list of Class<?> objects representing all the classes found in the classpath.