001: /*
002: * Copyright 2007 Google Inc.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005: * use this file except in compliance with the License. You may obtain a copy of
006: * the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013: * License for the specific language governing permissions and limitations under
014: * the License.
015: */
016: package com.google.gwt.core.ext.typeinfo;
017:
018: import java.util.HashMap;
019: import java.util.Map;
020:
021: /**
022: * Represents a primitive type in a declaration.
023: */
024: public class JPrimitiveType extends JType {
025:
026: public static final JPrimitiveType BOOLEAN = create("boolean", "Z");
027: public static final JPrimitiveType BYTE = create("byte", "B");
028: public static final JPrimitiveType CHAR = create("char", "C");
029: public static final JPrimitiveType DOUBLE = create("double", "D");
030: public static final JPrimitiveType FLOAT = create("float", "F");
031: public static final JPrimitiveType INT = create("int", "I");
032: public static final JPrimitiveType LONG = create("long", "J");
033: public static final JPrimitiveType SHORT = create("short", "S");
034: public static final JPrimitiveType VOID = create("void", "V");
035:
036: private static Map<String, JPrimitiveType> map;
037:
038: public static JPrimitiveType valueOf(String typeName) {
039: return getMap().get(typeName);
040: }
041:
042: private static JPrimitiveType create(String name, String jni) {
043: JPrimitiveType type = new JPrimitiveType(name, jni);
044: Object existing = getMap().put(name, type);
045: assert (existing == null);
046: return type;
047: }
048:
049: private static Map<String, JPrimitiveType> getMap() {
050: if (map == null) {
051: map = new HashMap<String, JPrimitiveType>();
052: }
053: return map;
054: }
055:
056: private final String jni;
057:
058: private final String name;
059:
060: private JPrimitiveType(String name, String jni) {
061: this .name = name;
062: this .jni = jni;
063: }
064:
065: @Override
066: public JType getErasedType() {
067: return this ;
068: }
069:
070: @Override
071: public String getJNISignature() {
072: return jni;
073: }
074:
075: @Override
076: public String getQualifiedSourceName() {
077: return name;
078: }
079:
080: @Override
081: public String getSimpleSourceName() {
082: return name;
083: }
084:
085: @Override
086: public JArrayType isArray() {
087: // intentional null
088: return null;
089: }
090:
091: @Override
092: public JClassType isClass() {
093: // intentional null
094: return null;
095: }
096:
097: @Override
098: public JEnumType isEnum() {
099: return null;
100: }
101:
102: @Override
103: public JGenericType isGenericType() {
104: return null;
105: }
106:
107: @Override
108: public JClassType isInterface() {
109: // intentional null
110: return null;
111: }
112:
113: @Override
114: public JParameterizedType isParameterized() {
115: // intentional null
116: return null;
117: }
118:
119: @Override
120: public JPrimitiveType isPrimitive() {
121: return this ;
122: }
123:
124: @Override
125: public JRawType isRawType() {
126: // intentional null
127: return null;
128: }
129:
130: @Override
131: public JWildcardType isWildcard() {
132: return null;
133: }
134:
135: @Override
136: JPrimitiveType getSubstitutedType(
137: JParameterizedType parameterizedType) {
138: return this;
139: }
140: }
|