Package htsjdk.utils

Class ClassFinder

java.lang.Object
htsjdk.utils.ClassFinder

public class ClassFinder extends Object
Utility class that can scan for classes in the classpath and find all the ones annotated with a particular annotation.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
    ClassFinder(File jarFile)
     
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    find(String packageName, Class<?> parentType)
    Scans the classpath for classes within the specified package and sub-packages that extend the parentType.
    Fetches the set of classes discovered so far.
    Fetches the set of classes discovered so far, subsetted down to concrete (non-abstract/interface) classes only
    protected void
    Checks an item to see if it is a class and is annotated with the specified annotation.
    static boolean
    isConcrete(Class<?> clazz)
    Determines whether or not the specified class is concrete (ie., non-abstract and non-interface)
    protected void
    scanDir(File file, String path)
    Scans a directory on the filesystem for classes.
    protected void
    scanJar(File file, String packagePath)
    Scans the entries in a ZIP/JAR file for classes under the parent package.
    toClassName(String filename)
    Convert a filename to a class name by removing '.class' and converting '/'s to '.'s.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • toClassName

      public String toClassName(String filename)
      Convert a filename to a class name by removing '.class' and converting '/'s to '.'s.
    • find

      public void find(String packageName, Class<?> parentType)
      Scans the classpath for classes within the specified package and sub-packages that extend the parentType. This method can be called repeatedly with different packages. Classes are accumulated internally and can be accessed by calling getClasses().
    • scanJar

      protected void scanJar(File file, String packagePath) throws IOException
      Scans the entries in a ZIP/JAR file for classes under the parent package.
      Parameters:
      file - the jar file to be scanned
      packagePath - the top level package to start from
      Throws:
      IOException
    • scanDir

      protected void scanDir(File file, String path)
      Scans a directory on the filesystem for classes.
      Parameters:
      file - the directory or file to examine
      path - the package path acculmulated so far (e.g. edu/mit/broad)
    • handleItem

      protected void handleItem(String name)
      Checks an item to see if it is a class and is annotated with the specified annotation. If so, adds it to the set, otherwise ignores it.
      Parameters:
      name - the path equivelant to the package + class/item name
    • getClasses

      public Set<Class<?>> getClasses()
      Fetches the set of classes discovered so far.
    • getConcreteClasses

      public Set<Class<?>> getConcreteClasses()
      Fetches the set of classes discovered so far, subsetted down to concrete (non-abstract/interface) classes only
      Returns:
      subset of classes discovered so far including only concrete (non-abstract/interface) classes
    • isConcrete

      public static boolean isConcrete(Class<?> clazz)
      Determines whether or not the specified class is concrete (ie., non-abstract and non-interface)
      Parameters:
      clazz - class to check
      Returns:
      true if the class is neither abstract nor an interface, otherwise false