public class SubClassFinder
extends java.lang.Object
findSubclassesOf(Class, boolean)
Constructor and Description |
---|
SubClassFinder() |
Modifier and Type | Method and Description |
---|---|
private static <E> void |
checkClass(java.lang.Class<?> subClass,
java.lang.Class<E> superClass,
java.util.List<java.lang.Class<? extends E>> resultList,
boolean onlyDirect)
Check if the class
fqClassName is a subclass of c . |
private static <E> void |
checkClass(java.lang.String fqClassName,
java.lang.Class<E> c,
java.util.List<java.lang.Class<? extends E>> result,
boolean onlyDirect)
Check if the class
fqClassName is a subclass of c . |
static <E> java.util.ArrayList<java.lang.Class<? extends E>> |
findSubclassesOf(java.lang.Class<E> superClass)
Find all subclasses of the given
superClass . |
static <E> java.util.ArrayList<java.lang.Class<? extends E>> |
findSubclassesOf(java.lang.Class<E> superClass,
boolean onlyDirect)
Find all subclasses of the given
superClass . |
static void |
main(java.lang.String[] args)
For testing: Searches and prints all subclasses of
BackgroundImageVisualizer . |
private static <E> void |
searchDir(java.io.File dir,
java.lang.Class<E> superClass,
java.util.List<java.lang.Class<? extends E>> resultList,
boolean onlyDirect)
Recursivly search through the given directory for subclasses of
dir . |
private static <E> void |
searchDir(java.io.File dir,
java.lang.Class<E> superClass,
java.util.List<java.lang.Class<? extends E>> resultList,
java.lang.String relPath,
boolean onlyDirect)
Recursivly search through the given directory for subclasses of
dir . |
private static <E> void |
searchJarFile(java.io.File jarFile,
java.lang.Class<E> superClass,
java.util.List<java.lang.Class<? extends E>> resultList,
boolean onlyDirect)
Search through the jar-file
jarFile for subclasses of superClass . |
public static void main(java.lang.String[] args)
BackgroundImageVisualizer
.args
- Superclassespublic static <E> java.util.ArrayList<java.lang.Class<? extends E>> findSubclassesOf(java.lang.Class<E> superClass)
superClass
. Searches through the complete classpath.E
- superClass classsuperClass
- the classpublic static <E> java.util.ArrayList<java.lang.Class<? extends E>> findSubclassesOf(java.lang.Class<E> superClass, boolean onlyDirect)
superClass
. Searches through the complete classpath.E
- superClass classsuperClass
- the class (e.g. Object.class
)onlyDirect
- it true
only direct subclasses are found, i.e. classes that directly
extend/implement superClass
checkClass(Class, Class, List, boolean)
private static <E> void searchDir(java.io.File dir, java.lang.Class<E> superClass, java.util.List<java.lang.Class<? extends E>> resultList, boolean onlyDirect)
dir
.E
- superClass classdir
- the Directory to search through.superClass
- the class to search subclasses of.resultList
- List where to add found subclasses to.onlyDirect
- only consider direct subclasses.checkClass(Class, Class, List, boolean)
private static <E> void searchDir(java.io.File dir, java.lang.Class<E> superClass, java.util.List<java.lang.Class<? extends E>> resultList, java.lang.String relPath, boolean onlyDirect)
dir
.E
- superClass classdir
- the Directory to search through.superClass
- the class to search subclasses of.resultList
- List where to add found subclasses to.relPath
- relative path within dir to search from, needed for recursion.onlyDirect
- only consider direct subclasses.searchDir(File, Class, List, boolean)
private static <E> void checkClass(java.lang.String fqClassName, java.lang.Class<E> c, java.util.List<java.lang.Class<? extends E>> result, boolean onlyDirect)
fqClassName
is a subclass of c
.E
- superClass classfqClassName
- the fully qualified class name to checkc
- the superClassresult
- ArrayList where to add fqClassName
if it is a subclassonlyDirect
- if true
only consider direct subclasses, i.e. classes that directly
extend/implement superClass
checkClass(Class, Class, List, boolean)
private static <E> void checkClass(java.lang.Class<?> subClass, java.lang.Class<E> superClass, java.util.List<java.lang.Class<? extends E>> resultList, boolean onlyDirect)
fqClassName
is a subclass of c
.E
- superClass classsubClass
- the class to checksuperClass
- the superClassresultList
- ArrayList where to add fqClassName
if it is a subclassonlyDirect
- if true
only consider direct subclasses, i.e. classes that directly
extend/implement superClass
checkClass(Class, Class, List, boolean)
private static <E> void searchJarFile(java.io.File jarFile, java.lang.Class<E> superClass, java.util.List<java.lang.Class<? extends E>> resultList, boolean onlyDirect)
jarFile
for subclasses of superClass
.E
- superClass classjarFile
- the jar-file to searchsuperClass
- the superClassresultList
- ArrayList where to add subClasses of superClass
onlyDirect
- if true
only consider direct subclasses, i.e. classes that directly
extend/implement superClass
checkClass(Class, Class, List, boolean)