1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
package junit.extensions; |
17 |
|
|
18 |
|
import java.lang.reflect.Array; |
19 |
|
import java.lang.reflect.Constructor; |
20 |
|
import java.lang.reflect.Field; |
21 |
|
import java.lang.reflect.InvocationTargetException; |
22 |
|
import java.lang.reflect.Method; |
23 |
|
import java.lang.reflect.Modifier; |
24 |
|
import java.security.InvalidParameterException; |
25 |
|
import java.util.ArrayList; |
26 |
|
import java.util.Collection; |
27 |
|
import java.util.Collections; |
28 |
|
import java.util.HashMap; |
29 |
|
import java.util.Map; |
30 |
|
import java.util.StringTokenizer; |
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
@author |
47 |
|
@author |
48 |
|
@author |
49 |
|
|
50 |
|
@deprecated |
51 |
|
|
52 |
|
|
53 |
|
@Deprecated |
|
|
| 14.6% |
Uncovered Elements: 204 (239) |
Complexity: 68 |
Complexity Density: 0.44 |
|
54 |
|
final class PrivilegedAccessor |
55 |
|
{ |
56 |
|
|
57 |
|
|
58 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
59 |
0 |
private PrivilegedAccessor() {... |
60 |
|
assert false : "You mustn't instantiate PrivilegedAccessor, use its methods statically"; |
61 |
|
} |
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
@param |
69 |
|
@return |
70 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 3 |
Complexity Density: 0.3 |
|
71 |
0 |
public static String toString(final Object instanceOrClass) {... |
72 |
0 |
Collection<String> fields = getFieldNames(instanceOrClass); |
73 |
|
|
74 |
0 |
if (fields.isEmpty()) |
75 |
|
{ |
76 |
0 |
return getClass(instanceOrClass).getName(); |
77 |
|
} |
78 |
|
|
79 |
0 |
StringBuffer stringBuffer = new StringBuffer(); |
80 |
|
|
81 |
0 |
stringBuffer.append(getClass(instanceOrClass).getName() + " {"); |
82 |
|
|
83 |
0 |
for (String fieldName : fields) { |
84 |
0 |
try { |
85 |
0 |
stringBuffer.append(fieldName + "=" + getValue(instanceOrClass, fieldName) + ", "); |
86 |
|
} catch (NoSuchFieldException e) { |
87 |
|
assert false : "It should always be possible to get a field that was just here"; |
88 |
|
} |
89 |
|
} |
90 |
|
|
91 |
0 |
stringBuffer.replace(stringBuffer.lastIndexOf(", "), stringBuffer.length(), "}"); |
92 |
0 |
return stringBuffer.toString(); |
93 |
|
} |
94 |
|
|
95 |
|
|
96 |
|
|
97 |
|
|
98 |
|
|
99 |
|
@param |
100 |
|
@return |
101 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 2 |
Complexity Density: 0.22 |
|
102 |
0 |
public static Collection<String> getFieldNames(final Object instanceOrClass) {... |
103 |
0 |
if (instanceOrClass == null) |
104 |
|
{ |
105 |
0 |
return Collections.EMPTY_LIST; |
106 |
|
} |
107 |
|
|
108 |
0 |
Class<?> clazz = getClass(instanceOrClass); |
109 |
0 |
Field[] fields = clazz.getDeclaredFields(); |
110 |
0 |
Collection<String> fieldNames = new ArrayList<String>(fields.length); |
111 |
|
|
112 |
0 |
for (Field field : fields) { |
113 |
0 |
fieldNames.add(field.getName()); |
114 |
|
} |
115 |
0 |
fieldNames.addAll(getFieldNames(clazz.getSuperclass())); |
116 |
|
|
117 |
0 |
return fieldNames; |
118 |
|
} |
119 |
|
|
120 |
|
|
121 |
|
|
122 |
|
|
123 |
|
|
124 |
|
@param |
125 |
|
@return |
126 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 2 |
Complexity Density: 0.22 |
|
127 |
0 |
public static Collection<String> getMethodSignatures(final Object instanceOrClass) {... |
128 |
0 |
if (instanceOrClass == null) |
129 |
|
{ |
130 |
0 |
return Collections.EMPTY_LIST; |
131 |
|
} |
132 |
|
|
133 |
0 |
Class<?> clazz = getClass(instanceOrClass); |
134 |
0 |
Method[] methods = clazz.getDeclaredMethods(); |
135 |
0 |
Collection<String> methodSignatures = new ArrayList<String>(methods.length + Object.class.getDeclaredMethods().length); |
136 |
|
|
137 |
0 |
for (Method method : methods) { |
138 |
0 |
methodSignatures.add(method.getName() + "(" + getParameterTypesAsString(method.getParameterTypes()) + ")"); |
139 |
|
} |
140 |
0 |
methodSignatures.addAll(getMethodSignatures(clazz.getSuperclass())); |
141 |
|
|
142 |
0 |
return methodSignatures; |
143 |
|
} |
144 |
|
|
145 |
|
|
146 |
|
|
147 |
|
|
148 |
|
@param |
149 |
|
@param |
150 |
|
@return |
151 |
|
@throws |
152 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
|
153 |
173 |
public static Object getValue(final Object instanceOrClass, final String fieldName) throws NoSuchFieldException {... |
154 |
173 |
Field field = getField(instanceOrClass, fieldName); |
155 |
173 |
try { |
156 |
173 |
return field.get(instanceOrClass); |
157 |
|
} catch (IllegalAccessException e) { |
158 |
|
assert false : "getField() should have setAccessible(true), so an IllegalAccessException should not occur in this place"; |
159 |
0 |
return null; |
160 |
|
} |
161 |
|
} |
162 |
|
|
163 |
|
|
164 |
|
|
165 |
|
|
166 |
|
|
167 |
|
@param |
168 |
|
@param |
169 |
|
@return |
170 |
|
@throws |
171 |
|
|
172 |
|
|
173 |
|
@throws |
174 |
|
|
175 |
|
@throws |
176 |
|
@throws |
177 |
|
@throws |
178 |
|
|
179 |
|
@see |
180 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
181 |
0 |
public static <T> T instantiate(final Class<? extends T> fromClass, final Object[] args) throws IllegalArgumentException,... |
182 |
|
InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { |
183 |
0 |
return instantiate(fromClass, getParameterTypes(args), args); |
184 |
|
} |
185 |
|
|
186 |
|
|
187 |
|
|
188 |
|
|
189 |
|
|
190 |
|
|
191 |
|
@param |
192 |
|
@param |
193 |
|
@param |
194 |
|
@return |
195 |
|
@throws |
196 |
|
|
197 |
|
|
198 |
|
@throws |
199 |
|
|
200 |
|
@throws |
201 |
|
@throws |
202 |
|
@throws |
203 |
|
|
204 |
|
@see |
205 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
206 |
0 |
public static <T> T instantiate(final Class<? extends T> fromClass, final Class<?>[] argumentTypes, final Object[] args)... |
207 |
|
throws IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException, |
208 |
|
NoSuchMethodException { |
209 |
0 |
return getConstructor(fromClass, argumentTypes).newInstance(args); |
210 |
|
} |
211 |
|
|
212 |
|
|
213 |
|
|
214 |
|
|
215 |
|
|
216 |
|
@param |
217 |
|
@param |
218 |
|
|
219 |
|
@param |
220 |
|
@return |
221 |
|
@throws |
222 |
|
@throws |
223 |
|
@throws |
224 |
|
@throws |
225 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 3 |
Complexity Density: 0.75 |
|
226 |
0 |
public static Object invokeMethod(final Object instanceOrClass, final String methodSignature, final Object[] arguments)... |
227 |
|
throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { |
228 |
0 |
if ((methodSignature.indexOf('(') == -1) || (methodSignature.indexOf('(') >= methodSignature.indexOf(')'))) |
229 |
|
{ |
230 |
0 |
throw new NoSuchMethodException(methodSignature); |
231 |
|
} |
232 |
0 |
Class<?>[] parameterTypes = getParameterTypes(methodSignature); |
233 |
0 |
return getMethod(instanceOrClass, getMethodName(methodSignature), parameterTypes).invoke(instanceOrClass, |
234 |
|
getCorrectedArguments(parameterTypes, arguments)); |
235 |
|
} |
236 |
|
|
237 |
|
|
238 |
|
|
239 |
|
|
240 |
|
|
241 |
|
@param |
242 |
|
@param |
243 |
|
@return |
244 |
|
|
|
|
| 0% |
Uncovered Elements: 18 (18) |
Complexity: 4 |
Complexity Density: 0.33 |
|
245 |
0 |
private static Object[] getCorrectedArguments(Class<?>[] parameterTypes, Object[] arguments) {... |
246 |
0 |
if (arguments == null) |
247 |
|
{ |
248 |
0 |
return arguments; |
249 |
|
} |
250 |
0 |
if (parameterTypes.length > arguments.length) |
251 |
|
{ |
252 |
0 |
return arguments; |
253 |
|
} |
254 |
0 |
if (parameterTypes.length < arguments.length) |
255 |
|
{ |
256 |
0 |
return getCorrectedArguments(parameterTypes, new Object[] {arguments}); |
257 |
|
} |
258 |
|
|
259 |
0 |
Object[] correctedArguments = new Object[arguments.length]; |
260 |
0 |
int currentArgument = 0; |
261 |
0 |
for (Class<?> parameterType : parameterTypes) { |
262 |
0 |
correctedArguments[currentArgument] = getCorrectedArgument(parameterType, arguments[currentArgument]); |
263 |
0 |
currentArgument++; |
264 |
|
} |
265 |
0 |
return correctedArguments; |
266 |
|
} |
267 |
|
|
268 |
|
|
269 |
|
|
270 |
|
|
271 |
|
|
272 |
|
@param |
273 |
|
@param |
274 |
|
@return |
275 |
|
|
|
|
| 0% |
Uncovered Elements: 24 (24) |
Complexity: 8 |
Complexity Density: 0.57 |
|
276 |
0 |
private static Object getCorrectedArgument(Class<?> parameterType, Object argument) {... |
277 |
0 |
if (!parameterType.isArray() || (argument == null)) { |
278 |
0 |
return argument; |
279 |
|
} |
280 |
|
|
281 |
0 |
if (!argument.getClass().isArray()) { |
282 |
0 |
return new Object[] {argument}; |
283 |
|
} |
284 |
|
|
285 |
0 |
if (parameterType.equals(argument.getClass())) |
286 |
|
{ |
287 |
0 |
return argument; |
288 |
|
} |
289 |
|
|
290 |
|
|
291 |
0 |
Object correctedArrayArgument = Array.newInstance(parameterType.getComponentType(), Array.getLength(argument)); |
292 |
0 |
for (int index = 0; index < Array.getLength(argument); index++) { |
293 |
0 |
if (parameterType.getComponentType().isPrimitive()) { |
294 |
0 |
Array.set(correctedArrayArgument, index, Array.get(argument, index)); |
295 |
|
} else { |
296 |
0 |
try { |
297 |
0 |
Array.set(correctedArrayArgument, index, parameterType.getComponentType().cast(Array.get(argument, index))); |
298 |
|
} catch (ClassCastException e) { |
299 |
0 |
throw new IllegalArgumentException("Argument " + argument + " of type " + argument.getClass() |
300 |
|
+ " does not match expected argument type " + parameterType + "."); |
301 |
|
} |
302 |
|
} |
303 |
|
} |
304 |
0 |
return correctedArrayArgument; |
305 |
|
} |
306 |
|
|
307 |
|
|
308 |
|
|
309 |
|
|
310 |
|
|
311 |
|
|
312 |
|
|
313 |
|
|
314 |
|
|
315 |
|
|
316 |
|
|
317 |
|
|
318 |
|
|
319 |
|
|
320 |
|
|
321 |
|
|
322 |
|
|
323 |
|
|
324 |
|
|
325 |
|
@param |
326 |
|
@param |
327 |
|
@param |
328 |
|
@throws |
329 |
|
@throws |
330 |
|
|
|
|
| 66.7% |
Uncovered Elements: 2 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
331 |
18 |
public static void setValue(final Object instanceOrClass, final String fieldName, final Object value) throws NoSuchFieldException,... |
332 |
|
IllegalAccessException { |
333 |
18 |
Field field = getField(instanceOrClass, fieldName); |
334 |
18 |
if (Modifier.isFinal(field.getModifiers())) { |
335 |
0 |
PrivilegedAccessor.setValue(field, "modifiers", field.getModifiers() ^ Modifier.FINAL); |
336 |
|
} |
337 |
18 |
field.set(instanceOrClass, value); |
338 |
|
} |
339 |
|
|
340 |
|
|
341 |
|
|
342 |
|
|
343 |
|
@param |
344 |
|
@return |
345 |
|
@throws |
346 |
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 4 |
Complexity Density: 0.44 |
|
347 |
0 |
private static Class<?> getClassForName(final String className) throws ClassNotFoundException {... |
348 |
0 |
if (className.indexOf('[') > -1) { |
349 |
0 |
Class<?> clazz = getClassForName(className.substring(0, className.indexOf('['))); |
350 |
0 |
return Array.newInstance(clazz, 0).getClass(); |
351 |
|
} |
352 |
|
|
353 |
0 |
if (className.indexOf("...") > -1) { |
354 |
0 |
Class<?> clazz = getClassForName(className.substring(0, className.indexOf("..."))); |
355 |
0 |
return Array.newInstance(clazz, 0).getClass(); |
356 |
|
} |
357 |
|
|
358 |
0 |
try { |
359 |
0 |
return Class.forName(className, false, Thread.currentThread().getContextClassLoader()); |
360 |
|
} catch (ClassNotFoundException e) { |
361 |
0 |
return getSpecialClassForName(className); |
362 |
|
} |
363 |
|
} |
364 |
|
|
365 |
|
|
366 |
|
|
367 |
|
|
368 |
|
private static final Map<String, Class<?>> PRIMITIVE_MAPPER = new HashMap<String, Class<?>>(8); |
369 |
|
|
370 |
|
|
371 |
|
|
372 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
373 |
1 |
static {... |
374 |
1 |
PRIMITIVE_MAPPER.put("int", Integer.TYPE); |
375 |
1 |
PRIMITIVE_MAPPER.put("float", Float.TYPE); |
376 |
1 |
PRIMITIVE_MAPPER.put("double", Double.TYPE); |
377 |
1 |
PRIMITIVE_MAPPER.put("short", Short.TYPE); |
378 |
1 |
PRIMITIVE_MAPPER.put("long", Long.TYPE); |
379 |
1 |
PRIMITIVE_MAPPER.put("byte", Byte.TYPE); |
380 |
1 |
PRIMITIVE_MAPPER.put("char", Character.TYPE); |
381 |
1 |
PRIMITIVE_MAPPER.put("boolean", Boolean.TYPE); |
382 |
|
} |
383 |
|
|
384 |
|
|
385 |
|
|
386 |
|
|
387 |
|
@param |
388 |
|
@return |
389 |
|
@throws |
390 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
391 |
0 |
private static Class<?> getSpecialClassForName(final String className) throws ClassNotFoundException {... |
392 |
0 |
if (PRIMITIVE_MAPPER.containsKey(className)) |
393 |
|
{ |
394 |
0 |
return PRIMITIVE_MAPPER.get(className); |
395 |
|
} |
396 |
|
|
397 |
0 |
if (missesPackageName(className)) |
398 |
|
{ |
399 |
0 |
return getStandardClassForName(className); |
400 |
|
} |
401 |
|
|
402 |
0 |
throw new ClassNotFoundException(className); |
403 |
|
} |
404 |
|
|
405 |
|
|
406 |
|
|
407 |
|
|
408 |
|
@param |
409 |
|
@return |
410 |
|
@throws |
411 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 3 |
Complexity Density: 0.6 |
|
412 |
0 |
private static Class<?> getStandardClassForName(String className) throws ClassNotFoundException {... |
413 |
0 |
try { |
414 |
0 |
return Class.forName("java.lang." + className, false, Thread.currentThread().getContextClassLoader()); |
415 |
|
} catch (ClassNotFoundException e) { |
416 |
0 |
try { |
417 |
0 |
return Class.forName("java.util." + className, false, Thread.currentThread().getContextClassLoader()); |
418 |
|
} catch (ClassNotFoundException e1) { |
419 |
0 |
throw new ClassNotFoundException(className); |
420 |
|
} |
421 |
|
} |
422 |
|
} |
423 |
|
|
424 |
|
|
425 |
|
|
426 |
|
|
427 |
|
@param |
428 |
|
@return |
429 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
430 |
0 |
private static boolean missesPackageName(String className) {... |
431 |
0 |
if (className.contains(".")) |
432 |
|
{ |
433 |
0 |
return false; |
434 |
|
} |
435 |
0 |
if (className.startsWith(className.substring(0, 1).toUpperCase())) |
436 |
|
{ |
437 |
0 |
return true; |
438 |
|
} |
439 |
0 |
return false; |
440 |
|
} |
441 |
|
|
442 |
|
|
443 |
|
|
444 |
|
|
445 |
|
@param |
446 |
|
@param |
447 |
|
@return |
448 |
|
@throws |
449 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
450 |
0 |
private static <T> Constructor<T> getConstructor(final Class<T> type, final Class<?>[] parameterTypes) throws NoSuchMethodException {... |
451 |
0 |
Constructor<T> constructor = type.getDeclaredConstructor(parameterTypes); |
452 |
0 |
constructor.setAccessible(true); |
453 |
0 |
return constructor; |
454 |
|
} |
455 |
|
|
456 |
|
|
457 |
|
|
458 |
|
|
459 |
|
@param |
460 |
|
@param |
461 |
|
@return |
462 |
|
@throws |
463 |
|
@throws |
464 |
|
|
|
|
| 71.4% |
Uncovered Elements: 4 (14) |
Complexity: 4 |
Complexity Density: 0.4 |
|
465 |
203 |
private static Field getField(final Object instanceOrClass, final String fieldName) throws NoSuchFieldException,... |
466 |
|
InvalidParameterException { |
467 |
203 |
if (instanceOrClass == null) |
468 |
|
{ |
469 |
0 |
throw new InvalidParameterException("Can't get field on null object/class"); |
470 |
|
} |
471 |
|
|
472 |
203 |
Class<?> type = getClass(instanceOrClass); |
473 |
|
|
474 |
203 |
try { |
475 |
203 |
Field field = type.getDeclaredField(fieldName); |
476 |
191 |
field.setAccessible(true); |
477 |
191 |
return field; |
478 |
|
} catch (NoSuchFieldException e) { |
479 |
12 |
if (type.getSuperclass() == null) |
480 |
|
{ |
481 |
0 |
throw e; |
482 |
|
} |
483 |
12 |
return getField(type.getSuperclass(), fieldName); |
484 |
|
} |
485 |
|
} |
486 |
|
|
487 |
|
|
488 |
|
|
489 |
|
|
490 |
|
@param |
491 |
|
@return |
492 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
493 |
203 |
private static Class<?> getClass(final Object instanceOrClass) {... |
494 |
203 |
if (instanceOrClass instanceof Class) |
495 |
|
{ |
496 |
14 |
return (Class<?>) instanceOrClass; |
497 |
|
} |
498 |
|
|
499 |
189 |
return instanceOrClass.getClass(); |
500 |
|
} |
501 |
|
|
502 |
|
|
503 |
|
|
504 |
|
|
505 |
|
@param |
506 |
|
@param |
507 |
|
@param |
508 |
|
@return |
509 |
|
@throws |
510 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 3 |
Complexity Density: 0.6 |
|
511 |
0 |
private static Method getMethod(final Class<?> type, final String methodName, final Class<?>[] parameterTypes)... |
512 |
|
throws NoSuchMethodException { |
513 |
0 |
try { |
514 |
0 |
return type.getDeclaredMethod(methodName, parameterTypes); |
515 |
|
} catch (NoSuchMethodException e) { |
516 |
0 |
if (type.getSuperclass() == null) |
517 |
|
{ |
518 |
0 |
throw e; |
519 |
|
} |
520 |
0 |
return getMethod(type.getSuperclass(), methodName, parameterTypes); |
521 |
|
} |
522 |
|
} |
523 |
|
|
524 |
|
|
525 |
|
|
526 |
|
|
527 |
|
|
528 |
|
@param |
529 |
|
@param |
530 |
|
@param |
531 |
|
@return |
532 |
|
@throws |
533 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
534 |
0 |
private static Method getMethod(final Object instanceOrClass, final String methodName, final Class<?>[] parameterTypes)... |
535 |
|
throws NoSuchMethodException { |
536 |
0 |
Class<?> type; |
537 |
|
|
538 |
0 |
type = getClass(instanceOrClass); |
539 |
|
|
540 |
0 |
Method accessMethod = getMethod(type, methodName, parameterTypes); |
541 |
0 |
accessMethod.setAccessible(true); |
542 |
0 |
return accessMethod; |
543 |
|
} |
544 |
|
|
545 |
|
|
546 |
|
|
547 |
|
|
548 |
|
@param |
549 |
|
@return |
550 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
551 |
0 |
private static String getMethodName(final String methodSignature) {... |
552 |
0 |
try { |
553 |
0 |
return methodSignature.substring(0, methodSignature.indexOf('(')).trim(); |
554 |
|
} catch (StringIndexOutOfBoundsException e) { |
555 |
|
assert false : "Signature must have been checked before this method was called"; |
556 |
0 |
return null; |
557 |
|
} |
558 |
|
} |
559 |
|
|
560 |
|
|
561 |
|
|
562 |
|
|
563 |
|
@param |
564 |
|
@return |
565 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
566 |
0 |
private static Class<?>[] getParameterTypes(final Object[] parameters) {... |
567 |
0 |
if (parameters == null) |
568 |
|
{ |
569 |
0 |
return new Class[0]; |
570 |
|
} |
571 |
|
|
572 |
0 |
Class<?>[] typesOfParameters = new Class[parameters.length]; |
573 |
|
|
574 |
0 |
for (int i = 0; i < parameters.length; i++) { |
575 |
0 |
typesOfParameters[i] = parameters[i].getClass(); |
576 |
|
} |
577 |
0 |
return typesOfParameters; |
578 |
|
} |
579 |
|
|
580 |
|
|
581 |
|
|
582 |
|
|
583 |
|
|
584 |
|
@param |
585 |
|
@return |
586 |
|
@throws |
587 |
|
@throws |
588 |
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 3 |
Complexity Density: 0.27 |
|
589 |
0 |
private static Class<?>[] getParameterTypes(final String methodSignature) throws NoSuchMethodException, IllegalArgumentException {... |
590 |
0 |
String signature = getSignatureWithoutBraces(methodSignature); |
591 |
|
|
592 |
0 |
StringTokenizer tokenizer = new StringTokenizer(signature, ", *"); |
593 |
0 |
Class<?>[] typesInSignature = new Class[tokenizer.countTokens()]; |
594 |
|
|
595 |
0 |
for (int x = 0; tokenizer.hasMoreTokens(); x++) { |
596 |
0 |
String className = tokenizer.nextToken(); |
597 |
0 |
try { |
598 |
0 |
typesInSignature[x] = getClassForName(className); |
599 |
|
} catch (ClassNotFoundException e) { |
600 |
0 |
NoSuchMethodException noSuchMethodException = new NoSuchMethodException(methodSignature); |
601 |
0 |
noSuchMethodException.initCause(e); |
602 |
0 |
throw noSuchMethodException; |
603 |
|
} |
604 |
|
} |
605 |
0 |
return typesInSignature; |
606 |
|
} |
607 |
|
|
608 |
|
|
609 |
|
|
610 |
|
|
611 |
|
@param |
612 |
|
@return |
613 |
|
|
614 |
|
@see |
615 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 4 |
Complexity Density: 0.67 |
|
616 |
0 |
private static String getParameterTypesAsString(final Class<?>[] classTypes) {... |
617 |
0 |
assert classTypes != null : "getParameterTypes() should have been called before this method and should have provided not-null classTypes"; |
618 |
0 |
if (classTypes.length == 0) |
619 |
|
{ |
620 |
0 |
return ""; |
621 |
|
} |
622 |
|
|
623 |
0 |
StringBuilder parameterTypes = new StringBuilder(); |
624 |
0 |
for (Class<?> clazz : classTypes) { |
625 |
0 |
assert clazz != null : "getParameterTypes() should have been called before this method and should have provided not-null classTypes"; |
626 |
0 |
parameterTypes.append(clazz.getName()).append(", "); |
627 |
|
} |
628 |
|
|
629 |
0 |
return parameterTypes.substring(0, parameterTypes.length() - 2); |
630 |
|
} |
631 |
|
|
632 |
|
|
633 |
|
|
634 |
|
|
635 |
|
@param |
636 |
|
@return |
637 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
638 |
0 |
private static String getSignatureWithoutBraces(final String methodSignature) {... |
639 |
0 |
try { |
640 |
0 |
return methodSignature.substring(methodSignature.indexOf('(') + 1, methodSignature.indexOf(')')); |
641 |
|
} catch (IndexOutOfBoundsException e) { |
642 |
|
assert false : "signature must have been checked before this method"; |
643 |
0 |
return null; |
644 |
|
} |
645 |
|
} |
646 |
|
|
647 |
|
} |