01: package org.hansel;
02:
03: import java.util.Enumeration;
04:
05: import junit.framework.TestFailure;
06: import junit.framework.TestResult;
07:
08: import org.objectweb.asm.Label;
09: import org.objectweb.asm.tree.InsnList;
10: import org.objectweb.asm.tree.LabelNode;
11:
12: /**
13: * Class containing utility methods.
14: *
15: * @author Niklas Mehner
16: */
17: public class Util {
18:
19: /**
20: * This class is static and cannot be instantiated.
21: * @throws UnsupportedOperationException Always.
22: */
23: public Util() {
24: throw new UnsupportedOperationException("Class is static.");
25: }
26:
27: public static String[] concat(String[] a, String[] b) {
28: String[] result = new String[a.length + b.length];
29:
30: System.arraycopy(a, 0, result, 0, a.length);
31: System.arraycopy(b, 0, result, a.length, b.length);
32:
33: return result;
34: }
35:
36: public static String leftFill(int length, String text) {
37: while (text.length() < length) {
38: text = " " + text;
39: }
40:
41: return text;
42: }
43:
44: /**
45: * Dumps the Failures and Errors contained in the result to stdio.
46: * @param result Result to dump.
47: */
48: public static void dumpResult(TestResult result) {
49: Enumeration e = result.failures();
50: while (e.hasMoreElements()) {
51: TestFailure failure = (TestFailure) e.nextElement();
52: failure.thrownException().printStackTrace();
53: }
54:
55: e = result.errors();
56: while (e.hasMoreElements()) {
57: TestFailure failure = (TestFailure) e.nextElement();
58: failure.thrownException().printStackTrace();
59: }
60: }
61:
62: public static int findIndex(InsnList instructions, Label label) {
63: for (int i = 0; i < instructions.size(); i++) {
64: Object obj = instructions.get(i);
65: if (obj instanceof LabelNode) {
66: if (((LabelNode) obj).getLabel() == label) {
67: return i;
68: }
69: }
70: }
71:
72: return -1;
73: }
74: }
|