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