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 List
collectClasses
(String classPath) Create a list of all classes that are available from classPath.static List
collectClassNames
(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 ClassLoader
createClassLoader
(String classPath) Create a new ClassLoader on the specified classpathprotected static void
extractClassNamesFromDir
(List result, File currentFile, String relativePath) Create a list of all classes "current" and its subdirectories.protected static void
extractClassNamesFromJar
(List result, File file) Create a list of all ".class" entries in the jar file.static String
getPackageName
(Class clazz) static String
getUnqualifiedName
(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
-