KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > uka > ipd > coverage > utils > BCELFillIn


1 /*
2  * Created on 20.12.2004
3  *
4  * written by Matthias Kempka
5  */

6 package de.uka.ipd.coverage.utils;
7
8 import org.apache.bcel.classfile.Constant;
9 import org.apache.bcel.generic.Type;
10
11 /**
12  * Created on 20.12.2004
13  * @author Matthias Kempka
14  */

15 public class BCELFillIn {
16     /**
17      * This is a workaround class to get the type of a constant in the
18      * constant pool. BCEL doesn't seem to support this action.
19      */

20     public static Type findType(Constant constant) {
21         byte tag = constant.getTag();
22         Type[] types = new Type[] {
23                 Type.BOOLEAN,
24                 Type.BYTE,
25                 Type.CHAR,
26                 Type.DOUBLE,
27                 Type.FLOAT,
28                 Type.INT,
29                 Type.LONG,
30                 Type.NULL,
31                 Type.OBJECT,
32                 Type.SHORT,
33                 Type.STRING,
34                 Type.STRINGBUFFER,
35                 Type.THROWABLE,
36                 Type.UNKNOWN,
37         };
38         for (int i = 0; i < types.length; i++) {
39             if (tag == types[i].getType()) {
40                 return types[i];
41             }
42         }
43         throw new AssertionError JavaDoc("constant " + constant + " has unknown type."); //$NON-NLS-1$ //$NON-NLS-2$
44
}
45
46 }
47
Popular Tags