public final class ClassHelper
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private static java.lang.String |
JUNIT_4_TESTRUNNER |
private static java.lang.String |
JUNIT_TESTRUNNER |
private static java.util.List<java.lang.ClassLoader> |
m_classLoaders
The additional class loaders to find classes in.
|
private static int |
m_lastGoodRootIndex
When given a file name to form a class name, the file name is parsed and divided
into segments.
|
Modifier | Constructor and Description |
---|---|
private |
ClassHelper()
Hide constructor.
|
Modifier and Type | Method and Description |
---|---|
static void |
addClassLoader(java.lang.ClassLoader loader)
Add a class loader to the searchable loaders.
|
static java.lang.Object |
createInstance(java.lang.Class<?> declaringClass,
java.util.Map<java.lang.Class,IClass> classes,
XmlTest xmlTest,
IAnnotationFinder finder,
ITestObjectFactory objectFactory)
Create an instance for the given class.
|
static java.lang.Object |
createInstance1(java.lang.Class<?> declaringClass,
java.util.Map<java.lang.Class,IClass> classes,
XmlTest xmlTest,
IAnnotationFinder finder,
IObjectFactory objectFactory) |
private static java.lang.Object |
createInstance2(java.lang.Class<?> declaringClass,
IObjectFactory2 objectFactory) |
static IMethodSelector |
createSelector(XmlMethodSelector selector) |
static IJUnitTestRunner |
createTestRunner(TestRunner runner) |
private static java.util.Set<java.lang.reflect.Method> |
extractMethods(java.lang.Class<?> childClass,
java.lang.Class<?> clazz,
java.util.Set<java.lang.reflect.Method> collected) |
static java.lang.Class<?> |
fileToClass(java.lang.String file)
Returns the Class object corresponding to the given name.
|
private static java.lang.reflect.Constructor<?> |
findAnnotatedConstructor(IAnnotationFinder finder,
java.lang.Class<?> declaringClass)
Find the best constructor given the parameters found on the annotation
|
static ConstructorOrMethod |
findDeclaredFactoryMethod(java.lang.Class<?> cls,
IAnnotationFinder finder)
For the given class, returns the method annotated with @Factory or null
if none is found.
|
static java.lang.Class<?> |
forName(java.lang.String className)
Tries to load the specified class using the context ClassLoader or if none,
than from the default ClassLoader.
|
static java.util.Set<java.lang.reflect.Method> |
getAvailableMethods(java.lang.Class<?> clazz)
Extract all callable methods of a class and all its super (keeping in mind
the Java access rules).
|
private static java.lang.Class<?> |
getEnclosingClass(java.lang.Class<?> declaringClass)
Class.getEnclosingClass() only exists on JDK5, so reimplementing it
here.
|
private static boolean |
isOverridden(java.lang.reflect.Method method,
java.util.Set<java.lang.reflect.Method> collectedMethods) |
private static void |
logClassNotFoundError(java.lang.String className,
java.lang.Exception ex) |
static <T> T |
newInstance(java.lang.Class<T> clazz) |
static <T> T |
newInstance(java.lang.reflect.Constructor<T> constructor,
java.lang.Object... parameters) |
static <T> T |
tryOtherConstructor(java.lang.Class<T> declaringClass) |
private static final java.lang.String JUNIT_TESTRUNNER
private static final java.lang.String JUNIT_4_TESTRUNNER
private static final java.util.List<java.lang.ClassLoader> m_classLoaders
private static int m_lastGoodRootIndex
public static void addClassLoader(java.lang.ClassLoader loader)
public static <T> T newInstance(java.lang.Class<T> clazz)
public static <T> T newInstance(java.lang.reflect.Constructor<T> constructor, java.lang.Object... parameters)
public static java.lang.Class<?> forName(java.lang.String className)
className
- the class name to be loaded.private static void logClassNotFoundError(java.lang.String className, java.lang.Exception ex)
public static ConstructorOrMethod findDeclaredFactoryMethod(java.lang.Class<?> cls, IAnnotationFinder finder)
cls
- The class to search for the @Factory annotation.finder
- The finder (JDK 1.4 or JDK 5.0+) use to search for the annotation.method
or nullpublic static java.util.Set<java.lang.reflect.Method> getAvailableMethods(java.lang.Class<?> clazz)
public static IJUnitTestRunner createTestRunner(TestRunner runner)
private static java.util.Set<java.lang.reflect.Method> extractMethods(java.lang.Class<?> childClass, java.lang.Class<?> clazz, java.util.Set<java.lang.reflect.Method> collected)
private static boolean isOverridden(java.lang.reflect.Method method, java.util.Set<java.lang.reflect.Method> collectedMethods)
public static IMethodSelector createSelector(XmlMethodSelector selector)
public static java.lang.Object createInstance(java.lang.Class<?> declaringClass, java.util.Map<java.lang.Class,IClass> classes, XmlTest xmlTest, IAnnotationFinder finder, ITestObjectFactory objectFactory)
private static java.lang.Object createInstance2(java.lang.Class<?> declaringClass, IObjectFactory2 objectFactory)
public static java.lang.Object createInstance1(java.lang.Class<?> declaringClass, java.util.Map<java.lang.Class,IClass> classes, XmlTest xmlTest, IAnnotationFinder finder, IObjectFactory objectFactory)
private static java.lang.Class<?> getEnclosingClass(java.lang.Class<?> declaringClass)
private static java.lang.reflect.Constructor<?> findAnnotatedConstructor(IAnnotationFinder finder, java.lang.Class<?> declaringClass)
public static <T> T tryOtherConstructor(java.lang.Class<T> declaringClass)
public static java.lang.Class<?> fileToClass(java.lang.String file)
file
- the class name.