60 R visitSimpleType(SimpleType type, P p); |
63 R visitSimpleType(SimpleType type, P p); |
61 R visitArrayType(ArrayType type, P p); |
64 R visitArrayType(ArrayType type, P p); |
62 R visitMethodType(MethodType type, P p); |
65 R visitMethodType(MethodType type, P p); |
63 R visitClassSigType(ClassSigType type, P p); |
66 R visitClassSigType(ClassSigType type, P p); |
64 R visitClassType(ClassType type, P p); |
67 R visitClassType(ClassType type, P p); |
65 R visitInnerClassType(InnerClassType type, P p); |
68 R visitTypeParamType(TypeParamType type, P p); |
66 R visitTypeArgType(TypeArgType type, P p); |
|
67 R visitWildcardType(WildcardType type, P p); |
69 R visitWildcardType(WildcardType type, P p); |
68 } |
70 } |
69 |
71 |
|
72 /** |
|
73 * Represents a type signature with a simple name. The name may be that of a |
|
74 * primitive type, such "{@code int}, {@code float}, etc |
|
75 * or that of a type argument, such as {@code T}, {@code K}, {@code V}, etc. |
|
76 * |
|
77 * See: |
|
78 * JVMS 4.3.2 |
|
79 * BaseType: |
|
80 * {@code B}, {@code C}, {@code D}, {@code F}, {@code I}, |
|
81 * {@code J}, {@code S}, {@code Z}; |
|
82 * VoidDescriptor: |
|
83 * {@code V}; |
|
84 * JVMS 4.3.4 |
|
85 * TypeVariableSignature: |
|
86 * {@code T} Identifier {@code ;} |
|
87 */ |
70 public static class SimpleType extends Type { |
88 public static class SimpleType extends Type { |
71 public SimpleType(String name) { |
89 public SimpleType(String name) { |
72 this.name = name; |
90 this.name = name; |
73 } |
91 } |
74 |
92 |
106 } |
132 } |
107 |
133 |
108 public final Type elemType; |
134 public final Type elemType; |
109 } |
135 } |
110 |
136 |
|
137 /** |
|
138 * Represents a method type signature. |
|
139 * |
|
140 * See; |
|
141 * JVMS 4.3.4 |
|
142 * MethodTypeSignature: |
|
143 * FormalTypeParameters_opt {@code (} TypeSignature* {@code)} ReturnType |
|
144 * ThrowsSignature* |
|
145 */ |
111 public static class MethodType extends Type { |
146 public static class MethodType extends Type { |
112 public MethodType(List<? extends Type> argTypes, Type resultType) { |
147 public MethodType(List<? extends Type> paramTypes, Type resultType) { |
113 this(null, argTypes, resultType, null); |
148 this(null, paramTypes, resultType, null); |
114 } |
149 } |
115 |
150 |
116 public MethodType(List<? extends Type> typeArgTypes, |
151 public MethodType(List<? extends TypeParamType> typeParamTypes, |
117 List<? extends Type> argTypes, |
152 List<? extends Type> paramTypes, |
118 Type returnType, |
153 Type returnType, |
119 List<? extends Type> throwsTypes) { |
154 List<? extends Type> throwsTypes) { |
120 this.typeArgTypes = typeArgTypes; |
155 this.typeParamTypes = typeParamTypes; |
121 this.argTypes = argTypes; |
156 this.paramTypes = paramTypes; |
122 this.returnType = returnType; |
157 this.returnType = returnType; |
123 this.throwsTypes = throwsTypes; |
158 this.throwsTypes = throwsTypes; |
124 } |
159 } |
125 |
160 |
126 public <R, D> R accept(Visitor<R, D> visitor, D data) { |
161 public <R, D> R accept(Visitor<R, D> visitor, D data) { |
128 } |
163 } |
129 |
164 |
130 @Override |
165 @Override |
131 public String toString() { |
166 public String toString() { |
132 StringBuilder sb = new StringBuilder(); |
167 StringBuilder sb = new StringBuilder(); |
133 appendIfNotEmpty(sb, "<", typeArgTypes, "> "); |
168 appendIfNotEmpty(sb, "<", typeParamTypes, "> "); |
134 sb.append(returnType); |
169 sb.append(returnType); |
135 append(sb, " (", argTypes, ")"); |
170 append(sb, " (", paramTypes, ")"); |
136 appendIfNotEmpty(sb, " throws ", throwsTypes, ""); |
171 appendIfNotEmpty(sb, " throws ", throwsTypes, ""); |
137 return sb.toString(); |
172 return sb.toString(); |
138 } |
173 } |
139 |
174 |
140 public final List<? extends Type> typeArgTypes; |
175 public final List<? extends TypeParamType> typeParamTypes; |
141 public final List<? extends Type> argTypes; |
176 public final List<? extends Type> paramTypes; |
142 public final Type returnType; |
177 public final Type returnType; |
143 public final List<? extends Type> throwsTypes; |
178 public final List<? extends Type> throwsTypes; |
144 } |
179 } |
145 |
180 |
|
181 /** |
|
182 * Represents a class signature. These describe the signature of |
|
183 * a class that has type arguments. |
|
184 * |
|
185 * See: |
|
186 * JVMS 4.3.4 |
|
187 * ClassSignature: |
|
188 * FormalTypeParameters_opt SuperclassSignature SuperinterfaceSignature* |
|
189 */ |
146 public static class ClassSigType extends Type { |
190 public static class ClassSigType extends Type { |
147 public ClassSigType(List<Type> typeArgTypes, Type superclassType, List<Type> superinterfaceTypes) { |
191 public ClassSigType(List<TypeParamType> typeParamTypes, Type superclassType, |
148 this.typeArgTypes = typeArgTypes; |
192 List<Type> superinterfaceTypes) { |
|
193 this.typeParamTypes = typeParamTypes; |
149 this.superclassType = superclassType; |
194 this.superclassType = superclassType; |
150 this.superinterfaceTypes = superinterfaceTypes; |
195 this.superinterfaceTypes = superinterfaceTypes; |
151 } |
196 } |
152 |
197 |
153 public <R, D> R accept(Visitor<R, D> visitor, D data) { |
198 public <R, D> R accept(Visitor<R, D> visitor, D data) { |
155 } |
200 } |
156 |
201 |
157 @Override |
202 @Override |
158 public String toString() { |
203 public String toString() { |
159 StringBuilder sb = new StringBuilder(); |
204 StringBuilder sb = new StringBuilder(); |
160 appendIfNotEmpty(sb, "<", typeArgTypes, ">"); |
205 appendIfNotEmpty(sb, "<", typeParamTypes, ">"); |
161 if (superclassType != null) { |
206 if (superclassType != null) { |
162 sb.append(" extends "); |
207 sb.append(" extends "); |
163 sb.append(superclassType); |
208 sb.append(superclassType); |
164 } |
209 } |
165 appendIfNotEmpty(sb, " implements ", superinterfaceTypes, ""); |
210 appendIfNotEmpty(sb, " implements ", superinterfaceTypes, ""); |
166 return sb.toString(); |
211 return sb.toString(); |
167 } |
212 } |
168 |
213 |
169 public final List<Type> typeArgTypes; |
214 public final List<TypeParamType> typeParamTypes; |
170 public final Type superclassType; |
215 public final Type superclassType; |
171 public final List<Type> superinterfaceTypes; |
216 public final List<Type> superinterfaceTypes; |
172 } |
217 } |
173 |
218 |
|
219 /** |
|
220 * Represents a class type signature. This is used to represent a |
|
221 * reference to a class, such as in a field, parameter, return type, etc. |
|
222 * |
|
223 * See: |
|
224 * JVMS 4.3.4 |
|
225 * ClassTypeSignature: |
|
226 * {@code L} PackageSpecifier_opt SimpleClassTypeSignature |
|
227 * ClassTypeSignatureSuffix* {@code ;} |
|
228 * PackageSpecifier: |
|
229 * Identifier {@code /} PackageSpecifier* |
|
230 * SimpleClassTypeSignature: |
|
231 * Identifier TypeArguments_opt } |
|
232 * ClassTypeSignatureSuffix: |
|
233 * {@code .} SimpleClassTypeSignature |
|
234 */ |
174 public static class ClassType extends Type { |
235 public static class ClassType extends Type { |
175 public ClassType(String name, List<Type> typeArgs) { |
236 public ClassType(ClassType outerType, String name, List<Type> typeArgs) { |
|
237 this.outerType = outerType; |
176 this.name = name; |
238 this.name = name; |
177 this.typeArgs = typeArgs; |
239 this.typeArgs = typeArgs; |
178 } |
240 } |
179 |
241 |
180 public <R, D> R accept(Visitor<R, D> visitor, D data) { |
242 public <R, D> R accept(Visitor<R, D> visitor, D data) { |
181 return visitor.visitClassType(this, data); |
243 return visitor.visitClassType(this, data); |
182 } |
244 } |
183 |
245 |
|
246 public String getBinaryName() { |
|
247 if (outerType == null) |
|
248 return name; |
|
249 else |
|
250 return (outerType.getBinaryName() + "$" + name); |
|
251 } |
|
252 |
184 @Override |
253 @Override |
185 public String toString() { |
254 public String toString() { |
186 StringBuilder sb = new StringBuilder(); |
255 StringBuilder sb = new StringBuilder(); |
|
256 if (outerType != null) { |
|
257 sb.append(outerType); |
|
258 sb.append("."); |
|
259 } |
187 sb.append(name); |
260 sb.append(name); |
188 appendIfNotEmpty(sb, "<", typeArgs, ">"); |
261 appendIfNotEmpty(sb, "<", typeArgs, ">"); |
189 return sb.toString(); |
262 return sb.toString(); |
190 } |
263 } |
191 |
264 |
|
265 public final ClassType outerType; |
192 public final String name; |
266 public final String name; |
193 public final List<Type> typeArgs; |
267 public final List<Type> typeArgs; |
194 } |
268 } |
195 |
269 |
196 |
270 /** |
197 public static class InnerClassType extends Type { |
271 * Represents a FormalTypeParameter. These are used to declare the type |
198 public InnerClassType(Type outerType, Type innerType) { |
272 * parameters for generic classes and methods. |
199 this.outerType = outerType; |
273 * |
200 this.innerType = innerType; |
274 * See: |
201 } |
275 * JVMS 4.3.4 |
202 |
276 * FormalTypeParameters: |
203 public <R, D> R accept(Visitor<R, D> visitor, D data) { |
277 * {@code <} FormalTypeParameter+ {@code >} |
204 return visitor.visitInnerClassType(this, data); |
278 * FormalTypeParameter: |
205 } |
279 * Identifier ClassBound InterfaceBound* |
206 |
280 * ClassBound: |
207 @Override |
281 * {@code :} FieldTypeSignature_opt |
208 public String toString() { |
282 * InterfaceBound: |
209 return outerType + "." + innerType; |
283 * {@code :} FieldTypeSignature |
210 } |
284 */ |
211 |
285 public static class TypeParamType extends Type { |
212 public final Type outerType; |
286 public TypeParamType(String name, Type classBound, List<Type> interfaceBounds) { |
213 public final Type innerType; |
|
214 } |
|
215 |
|
216 public static class TypeArgType extends Type { |
|
217 public TypeArgType(String name, Type classBound, List<Type> interfaceBounds) { |
|
218 this.name = name; |
287 this.name = name; |
219 this.classBound = classBound; |
288 this.classBound = classBound; |
220 this.interfaceBounds = interfaceBounds; |
289 this.interfaceBounds = interfaceBounds; |
221 } |
290 } |
222 |
291 |
223 public <R, D> R accept(Visitor<R, D> visitor, D data) { |
292 public <R, D> R accept(Visitor<R, D> visitor, D data) { |
224 return visitor.visitTypeArgType(this, data); |
293 return visitor.visitTypeParamType(this, data); |
225 } |
294 } |
226 |
295 |
227 @Override |
296 @Override |
228 public String toString() { |
297 public String toString() { |
229 StringBuilder sb = new StringBuilder(); |
298 StringBuilder sb = new StringBuilder(); |
247 public final String name; |
316 public final String name; |
248 public final Type classBound; |
317 public final Type classBound; |
249 public final List<Type> interfaceBounds; |
318 public final List<Type> interfaceBounds; |
250 } |
319 } |
251 |
320 |
|
321 /** |
|
322 * Represents a wildcard type argument. A type argument that is not a |
|
323 * wildcard type argument will be represented by a ClassType, ArrayType, etc. |
|
324 * |
|
325 * See: |
|
326 * JVMS 4.3.4 |
|
327 * TypeArgument: |
|
328 * WildcardIndicator_opt FieldTypeSignature |
|
329 * {@code *} |
|
330 * WildcardIndicator: |
|
331 * {@code +} |
|
332 * {@code -} |
|
333 */ |
252 public static class WildcardType extends Type { |
334 public static class WildcardType extends Type { |
|
335 public enum Kind { UNBOUNDED, EXTENDS, SUPER }; |
253 public WildcardType() { |
336 public WildcardType() { |
254 this(null, null); |
337 this(Kind.UNBOUNDED, null); |
255 } |
338 } |
256 |
339 public WildcardType(Kind kind, Type boundType) { |
257 public WildcardType(String kind, Type boundType) { |
|
258 this.kind = kind; |
340 this.kind = kind; |
259 this.boundType = boundType; |
341 this.boundType = boundType; |
260 } |
342 } |
261 |
343 |
262 public <R, D> R accept(Visitor<R, D> visitor, D data) { |
344 public <R, D> R accept(Visitor<R, D> visitor, D data) { |
263 return visitor.visitWildcardType(this, data); |
345 return visitor.visitWildcardType(this, data); |
264 } |
346 } |
265 |
347 |
266 @Override |
348 @Override |
267 public String toString() { |
349 public String toString() { |
268 if (kind == null) |
350 switch (kind) { |
269 return "?"; |
351 case UNBOUNDED: |
270 else |
352 return "?"; |
271 return "? " + kind + " " + boundType; |
353 case EXTENDS: |
272 } |
354 return "? extends " + boundType; |
273 |
355 case SUPER: |
274 public final String kind; |
356 return "? super " + boundType; |
|
357 default: |
|
358 throw new AssertionError(); |
|
359 } |
|
360 } |
|
361 |
|
362 public final Kind kind; |
275 public final Type boundType; |
363 public final Type boundType; |
276 } |
364 } |
277 } |
365 } |