Package de.intarsys.tools.reflect
Class ClassTools
- java.lang.Object
-
- de.intarsys.tools.reflect.ClassTools
-
public class ClassTools extends java.lang.Object
Tool class to enhance the reflective capabilities about classes.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.util.List
collectClasses(java.lang.String classPath)
Create a list of all classes that are available from classPath.static java.util.List
collectClassNames(java.lang.String classPath)
Create a list of class names in dot notation that can be found in the classPath.static <T> java.lang.Class<T>
createClass(java.lang.String className, java.lang.Class<T> expectedClass, java.lang.ClassLoader classLoader)
static java.lang.ClassLoader
createClassLoader(java.lang.String classPath)
Create a new ClassLoader on the specified classpathprotected static void
extractClassNamesFromDir(java.util.List result, java.io.File currentFile, java.lang.String relativePath)
Create a list of all classes "current" and its subdirectories.protected static void
extractClassNamesFromJar(java.util.List result, java.io.File file)
Create a list of all ".class" entries in the jar file.static java.lang.String
getPackageName(java.lang.Class clazz)
static java.lang.String
getUnqualifiedName(java.lang.Class clazz)
-
-
-
Method Detail
-
collectClasses
public static java.util.List collectClasses(java.lang.String classPath) throws java.io.IOException
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:
java.io.IOException
-
collectClassNames
public static java.util.List collectClassNames(java.lang.String classPath) throws java.io.IOException
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:
java.io.IOException
-
createClass
public static <T> java.lang.Class<T> createClass(java.lang.String className, java.lang.Class<T> expectedClass, java.lang.ClassLoader classLoader) throws ObjectCreationException
- Throws:
ObjectCreationException
-
createClassLoader
public static java.lang.ClassLoader createClassLoader(java.lang.String classPath)
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(java.util.List result, java.io.File currentFile, java.lang.String relativePath) throws java.io.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:
java.io.IOException
-
extractClassNamesFromJar
protected static void extractClassNamesFromJar(java.util.List result, java.io.File file) throws java.io.IOException
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:
java.io.IOException
-
getPackageName
public static java.lang.String getPackageName(java.lang.Class clazz)
-
getUnqualifiedName
public static java.lang.String getUnqualifiedName(java.lang.Class clazz)
-
-