KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > emn > info > eaop > recoderaux > AuxTypeKit


1 /* ----------------------------------------------------------------------------
2  * EAOP 1.0, 2002-12-19
3  * (c) 2002 Remi Douence, Mario Sudholt; OBASCO group; EMN/INRIA; France
4  * THIS SOFTWARE IS PROVIDED AS IS AND WITHOUT ANY WARRANTY
5   -------------------------------------------------------------------------- */

6
7 package fr.emn.info.eaop.recoderaux;
8
9 import recoder.abstraction.*;
10
11 /**
12  * This class provides auxiliary methods for the manipulation of
13  * Recoder types.
14  */

15 public class AuxTypeKit {
16     public static boolean isPrimitive(Type t) {
17     return t instanceof PrimitiveType;
18     }
19
20     public static boolean isPrimitive(String JavaDoc tName) {
21     return tName == "boolean" || tName == "byte" || tName == "char"
22         || tName == "double" || tName == "float" || tName == "int"
23         || tName == "long" || tName == "short";
24     }
25
26     /**
27      * Converts primitive type names into their object counterparts,
28      * identity on other strings.
29      */

30     public static String JavaDoc primitiveT2objectT(String JavaDoc tname) {
31     if (tname == "boolean" || tname == "byte" || tname == "char" ||
32         tname == "double" || tname == "float" || tname == "long" ||
33         tname == "short") {
34         return tname.substring(0, 1).toUpperCase() + tname.substring(1);
35     } else if (tname == "int") return "Integer";
36     else return tname;
37     }
38
39     /**
40      * Return the name representing the type <code>t</code>.
41      */

42     public static String JavaDoc type2representingType(Type t) {
43     String JavaDoc reprT = "";
44
45     if (isPrimitive(t))
46         reprT = primitiveT2objectT(t.getName()) + ".TYPE";
47     else reprT = "Class.forName(\"" + t.getFullName() + "\")";
48
49     return reprT;
50     }
51
52     /**
53      * Return an arbitrary element of the given type <code>td</code>.
54      */

55     public static String JavaDoc elementOfType(String JavaDoc tName) {
56     if (tName.equals(primitiveT2objectT(tName))) return "null";
57     else return elementOfPrimitiveType(tName);
58     }
59
60     /**
61      * Return an arbitrary element of the given
62      * primitive type <code>tn</code>.
63      */

64     public static String JavaDoc elementOfPrimitiveType(String JavaDoc tName) {
65     String JavaDoc str = "";
66
67     if (tName == "boolean") str = "true";
68     else if (tName == "char") str = " ";
69     str = "0";
70
71     return str;
72     }
73 }
74
Popular Tags