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.ArrayList;
019: import java.util.List;
020:
021: /**
022: * Represents a raw type; that is a generic type with no type arguments.
023: */
024: public class JRawType extends JDelegatingClassType {
025: private static final Substitution ERASURE_SUBSTITUTION = new Substitution() {
026: public JType getSubstitution(JType type) {
027: return type.getErasedType();
028: }
029: };
030:
031: private final JClassType enclosingType;
032:
033: private List<JClassType> interfaces;
034:
035: private final AbstractMembers members;
036:
037: public JRawType(JGenericType genericType, JClassType enclosingType) {
038: super .setBaseType(genericType);
039: this .enclosingType = enclosingType;
040:
041: // NOTE: this instance is not considered a nested type of the enclosing type
042:
043: members = new DelegateMembers(this , getBaseType(),
044: ERASURE_SUBSTITUTION);
045: }
046:
047: @Override
048: public JConstructor findConstructor(JType[] paramTypes) {
049: return members.findConstructor(paramTypes);
050: }
051:
052: @Override
053: public JField findField(String name) {
054: return members.findField(name);
055: }
056:
057: @Override
058: public JMethod findMethod(String name, JType[] paramTypes) {
059: return members.findMethod(name, paramTypes);
060: }
061:
062: @Override
063: public JClassType findNestedType(String typeName) {
064: return members.findNestedType(typeName);
065: }
066:
067: @Override
068: public JGenericType getBaseType() {
069: JGenericType genericType = super .getBaseType().isGenericType();
070: assert (genericType != null);
071: return genericType;
072: }
073:
074: @Override
075: public JConstructor getConstructor(JType[] paramTypes)
076: throws NotFoundException {
077: return members.getConstructor(paramTypes);
078: }
079:
080: @Override
081: public JConstructor[] getConstructors() {
082: return members.getConstructors();
083: }
084:
085: @Override
086: public JField getField(String name) {
087: return members.getField(name);
088: }
089:
090: @Override
091: public JField[] getFields() {
092: return members.getFields();
093: }
094:
095: public JGenericType getGenericType() {
096: return getBaseType();
097: }
098:
099: @Override
100: public JClassType[] getImplementedInterfaces() {
101: if (interfaces == null) {
102: interfaces = new ArrayList<JClassType>();
103: JClassType[] intfs = getBaseType()
104: .getImplementedInterfaces();
105: for (JClassType intf : intfs) {
106: JClassType newIntf = intf.getErasedType();
107: interfaces.add(newIntf);
108: }
109: }
110: return interfaces.toArray(TypeOracle.NO_JCLASSES);
111: }
112:
113: @Override
114: public JMethod getMethod(String name, JType[] paramTypes)
115: throws NotFoundException {
116: return members.getMethod(name, paramTypes);
117: }
118:
119: @Override
120: public JMethod[] getMethods() {
121: return members.getMethods();
122: }
123:
124: @Override
125: public JClassType getNestedType(String typeName)
126: throws NotFoundException {
127: return members.getNestedType(typeName);
128: }
129:
130: @Override
131: public JClassType[] getNestedTypes() {
132: return members.getNestedTypes();
133: }
134:
135: @Override
136: public JMethod[] getOverloads(String name) {
137: return members.getOverloads(name);
138: }
139:
140: @Override
141: public JMethod[] getOverridableMethods() {
142: return members.getOverridableMethods();
143: }
144:
145: @Override
146: public String getParameterizedQualifiedSourceName() {
147: return getQualifiedSourceName();
148: }
149:
150: @Override
151: public String getQualifiedSourceName() {
152: return getBaseType().getQualifiedSourceName();
153: }
154:
155: @Override
156: public String getSimpleSourceName() {
157: return getBaseType().getSimpleSourceName();
158: }
159:
160: @Override
161: public JClassType[] getSubtypes() {
162: JClassType[] baseSubTypes = super .getSubtypes();
163: JClassType[] rawSubTypes = new JClassType[baseSubTypes.length];
164: for (int i = 0; i < baseSubTypes.length; ++i) {
165: JClassType subType = baseSubTypes[i];
166: JGenericType isGenericType = subType.isGenericType();
167: if (isGenericType != null) {
168: rawSubTypes[i] = isGenericType.getRawType();
169: } else {
170: rawSubTypes[i] = subType;
171: }
172: }
173: return rawSubTypes;
174: }
175:
176: @Override
177: public JClassType getSuperclass() {
178: JClassType baseSuper = getBaseType().getSuperclass();
179: if (baseSuper == null) {
180: return null;
181: }
182:
183: return baseSuper.getErasedType();
184: }
185:
186: @Override
187: public boolean isAssignableFrom(JClassType otherType) {
188: otherType = maybeGetGenericBaseType(otherType);
189:
190: return getBaseType().isAssignableFrom(otherType);
191: }
192:
193: @Override
194: public boolean isAssignableTo(JClassType otherType) {
195: otherType = maybeGetGenericBaseType(otherType);
196:
197: return getBaseType().isAssignableTo(otherType);
198: }
199:
200: @Override
201: public JGenericType isGenericType() {
202: return null;
203: }
204:
205: @Override
206: public JParameterizedType isParameterized() {
207: return null;
208: }
209:
210: @Override
211: public JRawType isRawType() {
212: return this ;
213: }
214:
215: @Override
216: public JWildcardType isWildcard() {
217: return null;
218: }
219:
220: @Override
221: JRawType getSubstitutedType(JParameterizedType parameterizedType) {
222: /*
223: * Raw types do not participate in substitution.
224: */
225: return this;
226: }
227: }
|