KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hansel > Util


1 package org.hansel;
2
3 import java.util.Enumeration JavaDoc;
4
5 import junit.framework.TestFailure;
6 import junit.framework.TestResult;
7
8 import org.objectweb.asm.Label;
9 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 JavaDoc("Class is static.");
25     }
26
27     public static String JavaDoc[] concat(String JavaDoc[] a, String JavaDoc[] b) {
28         String JavaDoc[] result = new String JavaDoc[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 JavaDoc leftFill(int length, String JavaDoc 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 JavaDoc 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 JavaDoc 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 }
75
Popular Tags