Package de.intarsys.tools.reflect
Class ClassTools
java.lang.Object
de.intarsys.tools.reflect.ClassTools
Tool class to enhance the reflective capabilities about classes.
-
Method Summary
Modifier and TypeMethodDescriptionstatic ListcollectClasses(String classPath) Create a list of all classes that are available from classPath.static ListcollectClassNames(String classPath) Create a list of class names in dot notation that can be found in the classPath.static <T> Class<T> createClass(String className, Class<T> expectedClass, ClassLoader classLoader) static ClassLoadercreateClassLoader(String classPath) Create a new ClassLoader on the specified classpathprotected static voidextractClassNamesFromDir(List result, File currentFile, String relativePath) Create a list of all classes "current" and its subdirectories.protected static voidextractClassNamesFromJar(List result, File file) Create a list of all ".class" entries in the jar file.static StringgetPackageName(Class clazz) static StringgetUnqualifiedName(Class clazz)
-
Method Details
-
collectClasses
Create a list of all classes that are available from classPath.Be aware that the classes are loaded and so any static code is executed.
- Parameters:
classPath- The classpath to inspect- Returns:
- A list of all classes that are available from classPath.
- Throws:
IOException
-
collectClassNames
Create a list of class names in dot notation that can be found in the classPath.- Parameters:
classPath- The classpath to inspect- Returns:
- A list of class names in dot notation that can be found in the classPath.
- Throws:
IOException
-
createClass
public static <T> Class<T> createClass(String className, Class<T> expectedClass, ClassLoader classLoader) throws ObjectCreationException - Throws:
ObjectCreationException
-
createClassLoader
Create a new ClassLoader on the specified classpath- Parameters:
classPath- The classpath we want to load from.- Returns:
- A new ClassLoader on the specified classpath
-
extractClassNamesFromDir
protected static void extractClassNamesFromDir(List result, File currentFile, String relativePath) throws IOException Create a list of all classes "current" and its subdirectories.- Parameters:
result- The collection that is filled with new classnamescurrentFile- The directory/file under inspectionrelativePath- The path extending from the initial root we are currently inspecting.- Throws:
IOException
-
extractClassNamesFromJar
Create a list of all ".class" entries in the jar file.- Parameters:
result- The collection that is filled with new classnamesfile- The jar file we are inspecting.- Throws:
IOException
-
getPackageName
-
getUnqualifiedName
-