01: // This file is part of KeY - Integrated Deductive Software Design
02: // Copyright (C) 2001-2007 Universitaet Karlsruhe, Germany
03: // Universitaet Koblenz-Landau, Germany
04: // Chalmers University of Technology, Sweden
05: //
06: // The KeY system is protected by the GNU General Public License.
07: // See LICENSE.TXT for details.
08: //
09: //
10:
11: package de.uka.ilkd.key.java;
12:
13: public class TypeNameTranslator {
14:
15: private TypeNameTranslator() {
16: }
17:
18: /**
19: * returns the basetype of <code>t</code>.
20: * example: <code>getBaseType("[[[I")</code> returns "int".
21: */
22: public static String getBaseType(String t) {
23: if (t == null || !t.startsWith("[")) {
24: return t;
25: }
26: while (t.startsWith("[")) {
27: t = t.substring(1);
28: }
29: if (t.startsWith("L")) {
30: return t.substring(1);
31: } else if (t.startsWith("B")) {
32: return "byte";
33: } else if (t.startsWith("C")) {
34: return "char";
35: } else if (t.startsWith("D")) {
36: return "double";
37: } else if (t.startsWith("F")) {
38: return "float";
39: } else if (t.startsWith("I")) {
40: return "int";
41: } else if (t.startsWith("J")) {
42: return "long";
43: } else if (t.startsWith("S")) {
44: return "short";
45: } else if (t.startsWith("Z")) {
46: return "boolean";
47: } else {
48: return t;
49: }
50: }
51:
52: /** returns the dimensions of an ArrayType. Returns 0 if
53: * <code>t</code> doesn't represent an ArrayType.
54: */
55: public static int getDimensions(String t) {
56: if (t == null || !t.startsWith("[")) {
57: return 0;
58: }
59: int i = 0;
60: while (t.startsWith("[")) {
61: t = t.substring(1);
62: i++;
63: }
64: return i;
65: }
66:
67: }
|