-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBCELTools.java
36 lines (32 loc) · 1.2 KB
/
BCELTools.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package nl.rug.jbi.jsm.bcel;
import org.apache.bcel.Constants;
import org.apache.bcel.generic.ArrayType;
import org.apache.bcel.generic.Type;
/**
* Utility class exposing methods that are useful for processing the BCEL data objects into data usable by metrics.
*
* @author David van Leusen
* @since 2014-05-28
*/
public class BCELTools {
/**
* Converts any type into the correct string representing the underlying type.
* It will unroll ArrayTypes and turn primitive types into a common type "java.PRIMITIVE".
* Based on the implementation by dspinellis
*
* @param t BCEL Type object
* @return String representation of the base type of the provided type object.
* @see <a href="https://github.com/dspinellis/ckjm/blob/master/src/gr/spinellis/ckjm/ClassVisitor.java#L180">
* Original Implementation</a>
*/
public static String type2className(final Type t) {
final String className = t.toString();
if (t.getType() <= Constants.T_VOID) {
return "java.PRIMITIVE";
} else if (t instanceof ArrayType) {
return type2className(((ArrayType) t).getBasicType());
} else {
return className;
}
}
}