KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > google > gwt > core > ext > typeinfo > JPrimitiveType


1 /*
2  * Copyright 2006 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  */

16 package com.google.gwt.core.ext.typeinfo;
17
18 import java.util.HashMap JavaDoc;
19 import java.util.Map JavaDoc;
20
21 /**
22  * Represents a primitive type in a declaration.
23  */

24 public class JPrimitiveType extends JType {
25
26   public static final JPrimitiveType BOOLEAN = create("boolean", "Z");
27   public static final JPrimitiveType BYTE = create("byte", "B");
28   public static final JPrimitiveType CHAR = create("char", "C");
29   public static final JPrimitiveType DOUBLE = create("double", "D");
30   public static final JPrimitiveType FLOAT = create("float", "F");
31   public static final JPrimitiveType INT = create("int", "I");
32   public static final JPrimitiveType LONG = create("long", "J");
33   public static final JPrimitiveType SHORT = create("short", "S");
34   public static final JPrimitiveType VOID = create("void", "V");
35
36   private static Map JavaDoc map;
37
38   public static JPrimitiveType valueOf(String JavaDoc typeName) {
39     return (JPrimitiveType) getMap().get(typeName);
40   }
41
42   private static JPrimitiveType create(String JavaDoc name, String JavaDoc jni) {
43     JPrimitiveType type = new JPrimitiveType(name, jni);
44     Object JavaDoc existing = getMap().put(name, type);
45     assert (existing == null);
46     return type;
47   }
48
49   private static Map JavaDoc getMap() {
50     if (map == null) {
51       map = new HashMap JavaDoc();
52     }
53     return map;
54   }
55
56   private final String JavaDoc jni;
57
58   private final String JavaDoc name;
59
60   private JPrimitiveType(String JavaDoc name, String JavaDoc jni) {
61     this.name = name;
62     this.jni = jni;
63   }
64
65   public String JavaDoc getJNISignature() {
66     return jni;
67   }
68
69   public String JavaDoc getQualifiedSourceName() {
70     return name;
71   }
72
73   public String JavaDoc getSimpleSourceName() {
74     return name;
75   }
76
77   public JArrayType isArray() {
78     // intentional null
79
return null;
80   }
81
82   public JClassType isClass() {
83     // intentional null
84
return null;
85   }
86
87   public JClassType isInterface() {
88     // intentional null
89
return null;
90   }
91
92   public JParameterizedType isParameterized() {
93     // intentional null
94
return null;
95   }
96
97   public JPrimitiveType isPrimitive() {
98     return this;
99   }
100 }
101
Popular Tags