| 1 |
|
package com.atlassian.core.util; |
| 2 |
|
|
| 3 |
|
import com.atlassian.core.util.ClassLoaderUtils; |
| 4 |
|
|
| 5 |
|
import java.lang.reflect.Constructor; |
| 6 |
|
import java.lang.reflect.InvocationTargetException; |
| 7 |
|
|
|
|
|
| 0% |
Uncovered Elements: 20 (20) |
Complexity: 5 |
Complexity Density: 0.42 |
|
| 8 |
|
public class ClassHelper |
| 9 |
|
{ |
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 4 |
Complexity Density: 0.4 |
|
| 10 |
0
|
public static Object instantiateClass(Class clazz, Object[] constructorArgs) throws ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException... |
| 11 |
|
{ |
| 12 |
0
|
Class args[] = new Class[constructorArgs.length]; |
| 13 |
0
|
for (int i = 0; i < constructorArgs.length; i++) |
| 14 |
|
{ |
| 15 |
0
|
if (constructorArgs == null) |
| 16 |
|
{ |
| 17 |
0
|
args[i] = null; |
| 18 |
|
} |
| 19 |
|
else |
| 20 |
|
{ |
| 21 |
0
|
args[i] = constructorArgs[i].getClass(); |
| 22 |
|
} |
| 23 |
|
} |
| 24 |
0
|
Constructor ctor = null; |
| 25 |
0
|
if (clazz.getConstructors().length == 1) |
| 26 |
|
{ |
| 27 |
0
|
ctor = clazz.getConstructors()[0]; |
| 28 |
|
} else { |
| 29 |
|
|
| 30 |
|
|
| 31 |
|
|
| 32 |
0
|
ctor = clazz.getConstructor(args); |
| 33 |
|
} |
| 34 |
0
|
return ctor.newInstance(constructorArgs); |
| 35 |
|
} |
| 36 |
|
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 37 |
0
|
public static Object instantiateClass(String name, Object[] constructorArgs) throws ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException... |
| 38 |
|
{ |
| 39 |
0
|
Class clazz = ClassLoaderUtils.loadClass(name, ClassHelper.class); |
| 40 |
0
|
return instantiateClass(clazz, constructorArgs); |
| 41 |
|
} |
| 42 |
|
} |