001: /*
002: * Copyright 2006 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 java.lang;
017:
018: import com.google.gwt.core.client.JavaScriptObject;
019:
020: /**
021: * Generally unsupported. This class is provided so that the GWT compiler can
022: * choke down class literal references.
023: *
024: * @param <T> the type of the object
025: */
026: public final class Class<T> {
027:
028: private static final int PRIMITIVE = 0x00000001;
029: private static final int INTERFACE = 0x00000002;
030: private static final int ARRAY = 0x00000004;
031: private static final int ENUM = 0x00000008;
032:
033: /**
034: * Create a Class object for an array.
035: *
036: * @skip
037: */
038: static <T> Class<T> createForArray(String packageName,
039: String className) {
040: // Initialize here to avoid method inliner
041: Class<T> clazz = new Class<T>();
042: clazz.typeName = packageName + className;
043: clazz.modifiers = ARRAY;
044: clazz.super class = Object.class;
045: return clazz;
046: }
047:
048: /**
049: * Create a Class object for a class.
050: *
051: * @skip
052: */
053: static <T> Class<T> createForClass(String packageName,
054: String className, Class<? super T> super class) {
055: // Initialize here to avoid method inliner
056: Class<T> clazz = new Class<T>();
057: clazz.typeName = packageName + className;
058: clazz.super class = super class;
059: return clazz;
060: }
061:
062: /**
063: * Create a Class object for an enum.
064: *
065: * @skip
066: */
067: static <T> Class<T> createForEnum(String packageName,
068: String className, Class<? super T> super class,
069: JavaScriptObject enumConstantsFunc) {
070: // Initialize here to avoid method inliner
071: Class<T> clazz = new Class<T>();
072: clazz.typeName = packageName + className;
073: clazz.modifiers = ENUM;
074: clazz.super class = super class;
075: clazz.enumConstantsFunc = enumConstantsFunc;
076: return clazz;
077: }
078:
079: /**
080: * Create a Class object for an interface.
081: *
082: * @skip
083: */
084: static <T> Class<T> createForInterface(String packageName,
085: String className) {
086: // Initialize here to avoid method inliner
087: Class<T> clazz = new Class<T>();
088: clazz.typeName = packageName + className;
089: clazz.modifiers = INTERFACE;
090: return clazz;
091: }
092:
093: /**
094: * Create a Class object for a primitive.
095: *
096: * @skip
097: */
098: static Class<?> createForPrimitive(String packageName,
099: String className) {
100: // Initialize here to avoid method inliner
101: Class<?> clazz = new Class<Object>();
102: clazz.typeName = packageName + className;
103: clazz.modifiers = PRIMITIVE;
104: return clazz;
105: }
106:
107: @SuppressWarnings("unused")
108: private JavaScriptObject enumConstantsFunc;
109:
110: private int modifiers;
111:
112: private String typeName;
113:
114: private Class<? super T> super class;
115:
116: /**
117: * Not publicly instantiable.
118: *
119: * @skip
120: */
121: private Class() {
122: }
123:
124: public native T[] getEnumConstants() /*-{
125: return this.@java.lang.Class::enumConstantsFunc
126: && (this.@java.lang.Class::enumConstantsFunc)();
127: }-*/;
128:
129: public String getName() {
130: return typeName;
131: }
132:
133: public Class<? super T> getSuperclass() {
134: return super class;
135: }
136:
137: public boolean isArray() {
138: return (modifiers & ARRAY) != 0;
139: }
140:
141: public boolean isEnum() {
142: return (modifiers & ENUM) != 0;
143: }
144:
145: public boolean isInterface() {
146: return (modifiers & INTERFACE) != 0;
147: }
148:
149: public boolean isPrimitive() {
150: return (modifiers & PRIMITIVE) != 0;
151: }
152:
153: public String toString() {
154: return (isInterface() ? "interface " : (isPrimitive() ? ""
155: : "class "))
156: + getName();
157: }
158: }
|