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()ClassFinder(File jarFile)ClassFinder(ClassLoader loader)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidfind(String packageName, Class<?> parentType)Scans the classpath for classes within the specified package and sub-packages that extend the parentType.Set<Class<?>>getClasses()Fetches the set of classes discovered so far.Set<Class<?>>getConcreteClasses()Fetches the set of classes discovered so far, subsetted down to concrete (non-abstract/interface) classes onlyprotected voidhandleItem(String name)Checks an item to see if it is a class and is annotated with the specified annotation.static booleanisConcrete(Class<?> clazz)Determines whether or not the specified class is concrete (ie., non-abstract and non-interface)protected voidscanDir(File file, String path)Scans a directory on the filesystem for classes.protected voidscanJar(File file, String packagePath)Scans the entries in a ZIP/JAR file for classes under the parent package.StringtoClassName(String filename)Convert a filename to a class name by removing '.class' and converting '/'s to '.'s.
-
-
-
Constructor Detail
-
ClassFinder
public ClassFinder()
-
ClassFinder
public ClassFinder(ClassLoader loader)
-
ClassFinder
public ClassFinder(File jarFile) throws IOException
- Throws:
IOException
-
-
Method Detail
-
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 callinggetClasses().
-
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 scannedpackagePath- 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 examinepath- 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
-
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
-
-