1 /* |
|
2 * Copyright (c) 2004, 2005, Oracle and/or its affiliates. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. Oracle designates this |
|
8 * particular file as subject to the "Classpath" exception as provided |
|
9 * by Oracle in the LICENSE file that accompanied this code. |
|
10 * |
|
11 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 * version 2 for more details (a copy is included in the LICENSE file that |
|
15 * accompanied this code). |
|
16 * |
|
17 * You should have received a copy of the GNU General Public License version |
|
18 * 2 along with this work; if not, write to the Free Software Foundation, |
|
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 * |
|
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 * or visit www.oracle.com if you need additional information or have any |
|
23 * questions. |
|
24 */ |
|
25 |
|
26 package com.sun.tools.apt.mirror.type; |
|
27 |
|
28 |
|
29 import java.util.Collection; |
|
30 |
|
31 import com.sun.mirror.declaration.TypeDeclaration; |
|
32 import com.sun.mirror.type.*; |
|
33 import com.sun.tools.apt.mirror.AptEnv; |
|
34 import com.sun.tools.javac.code.*; |
|
35 import com.sun.tools.javac.code.Symbol.ClassSymbol; |
|
36 |
|
37 |
|
38 /** |
|
39 * Implementation of DeclaredType |
|
40 */ |
|
41 @SuppressWarnings("deprecation") |
|
42 abstract class DeclaredTypeImpl extends TypeMirrorImpl |
|
43 implements DeclaredType { |
|
44 |
|
45 protected Type.ClassType type; |
|
46 |
|
47 |
|
48 protected DeclaredTypeImpl(AptEnv env, Type.ClassType type) { |
|
49 super(env, type); |
|
50 this.type = type; |
|
51 } |
|
52 |
|
53 |
|
54 /** |
|
55 * Returns a string representation of this declared type. |
|
56 * This includes the type's name and any actual type arguments. |
|
57 * Type names are qualified. |
|
58 */ |
|
59 public String toString() { |
|
60 return toString(env, type); |
|
61 } |
|
62 |
|
63 /** |
|
64 * {@inheritDoc} |
|
65 */ |
|
66 public TypeDeclaration getDeclaration() { |
|
67 return env.declMaker.getTypeDeclaration((ClassSymbol) type.tsym); |
|
68 } |
|
69 |
|
70 /** |
|
71 * {@inheritDoc} |
|
72 */ |
|
73 public DeclaredType getContainingType() { |
|
74 if (type.getEnclosingType().tag == TypeTags.CLASS) { |
|
75 // This is the type of an inner class. |
|
76 return (DeclaredType) env.typeMaker.getType(type.getEnclosingType()); |
|
77 } |
|
78 ClassSymbol enclosing = type.tsym.owner.enclClass(); |
|
79 if (enclosing != null) { |
|
80 // Nested but not inner. Return the raw type of the enclosing |
|
81 // class or interface. |
|
82 // See java.lang.reflect.ParameterizedType.getOwnerType(). |
|
83 return (DeclaredType) env.typeMaker.getType( |
|
84 env.jctypes.erasure(enclosing.type)); |
|
85 } |
|
86 return null; |
|
87 } |
|
88 |
|
89 /** |
|
90 * {@inheritDoc} |
|
91 */ |
|
92 public Collection<TypeMirror> getActualTypeArguments() { |
|
93 return env.typeMaker.getTypes(type.getTypeArguments()); |
|
94 } |
|
95 |
|
96 /** |
|
97 * {@inheritDoc} |
|
98 */ |
|
99 public Collection<InterfaceType> getSuperinterfaces() { |
|
100 return env.typeMaker.getTypes(env.jctypes.interfaces(type), |
|
101 InterfaceType.class); |
|
102 } |
|
103 |
|
104 |
|
105 /** |
|
106 * Returns a string representation of this declared type. |
|
107 * See {@link #toString()} for details. |
|
108 */ |
|
109 static String toString(AptEnv env, Type.ClassType c) { |
|
110 return c.toString(); |
|
111 } |
|
112 } |
|