10
|
1 |
/*
|
5520
|
2 |
* Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved.
|
10
|
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
|
5520
|
7 |
* published by the Free Software Foundation. Oracle designates this
|
10
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
5520
|
9 |
* by Oracle in the LICENSE file that accompanied this code.
|
10
|
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 |
*
|
5520
|
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.
|
10
|
24 |
*/
|
|
25 |
|
|
26 |
package com.sun.tools.javadoc;
|
|
27 |
|
|
28 |
|
|
29 |
import com.sun.javadoc.*;
|
|
30 |
|
|
31 |
import static com.sun.javadoc.LanguageVersion.*;
|
|
32 |
|
|
33 |
import com.sun.tools.javac.code.Symbol.ClassSymbol;
|
|
34 |
import com.sun.tools.javac.code.Type;
|
|
35 |
import com.sun.tools.javac.code.Type.ClassType;
|
|
36 |
import com.sun.tools.javac.util.List;
|
|
37 |
|
|
38 |
import static com.sun.tools.javac.code.TypeTags.*;
|
|
39 |
|
|
40 |
|
|
41 |
/**
|
|
42 |
* Implementation of <code>ParameterizedType</code>, which
|
|
43 |
* represents an invocation of a generic class or interface.
|
|
44 |
*
|
|
45 |
* @author Scott Seligman
|
|
46 |
* @since 1.5
|
|
47 |
*/
|
|
48 |
public class ParameterizedTypeImpl
|
|
49 |
extends AbstractTypeImpl implements ParameterizedType {
|
|
50 |
|
|
51 |
ParameterizedTypeImpl(DocEnv env, Type type) {
|
|
52 |
super(env, type);
|
|
53 |
}
|
|
54 |
|
|
55 |
/**
|
|
56 |
* Return the generic class or interface that declared this type.
|
|
57 |
*/
|
|
58 |
public ClassDoc asClassDoc() {
|
|
59 |
return env.getClassDoc((ClassSymbol)type.tsym);
|
|
60 |
}
|
|
61 |
|
|
62 |
/**
|
|
63 |
* Return the actual type arguments of this type.
|
|
64 |
*/
|
|
65 |
public com.sun.javadoc.Type[] typeArguments() {
|
|
66 |
return TypeMaker.getTypes(env, type.getTypeArguments());
|
|
67 |
}
|
|
68 |
|
|
69 |
/**
|
|
70 |
* Return the class type that is a direct supertype of this one.
|
|
71 |
* Return null if this is an interface type.
|
|
72 |
*/
|
|
73 |
public com.sun.javadoc.Type superclassType() {
|
|
74 |
if (asClassDoc().isInterface()) {
|
|
75 |
return null;
|
|
76 |
}
|
|
77 |
Type sup = env.types.supertype(type);
|
|
78 |
return TypeMaker.getType(env,
|
|
79 |
(sup != type) ? sup : env.syms.objectType);
|
|
80 |
}
|
|
81 |
|
|
82 |
/**
|
|
83 |
* Return the interface types directly implemented by or extended by this
|
|
84 |
* parameterized type.
|
|
85 |
* Return an empty array if there are no interfaces.
|
|
86 |
*/
|
|
87 |
public com.sun.javadoc.Type[] interfaceTypes() {
|
|
88 |
return TypeMaker.getTypes(env, env.types.interfaces(type));
|
|
89 |
}
|
|
90 |
|
|
91 |
/**
|
|
92 |
* Return the type that contains this type as a member.
|
|
93 |
* Return null is this is a top-level type.
|
|
94 |
*/
|
|
95 |
public com.sun.javadoc.Type containingType() {
|
|
96 |
if (type.getEnclosingType().tag == CLASS) {
|
|
97 |
// This is the type of an inner class.
|
|
98 |
return TypeMaker.getType(env, type.getEnclosingType());
|
|
99 |
}
|
|
100 |
ClassSymbol enclosing = type.tsym.owner.enclClass();
|
|
101 |
if (enclosing != null) {
|
|
102 |
// Nested but not inner. Return the ClassDoc of the enclosing
|
|
103 |
// class or interface.
|
|
104 |
// See java.lang.reflect.ParameterizedType.getOwnerType().
|
|
105 |
return env.getClassDoc(enclosing);
|
|
106 |
}
|
|
107 |
return null;
|
|
108 |
}
|
|
109 |
|
|
110 |
|
|
111 |
// Asking for the "name" of a parameterized type doesn't exactly make
|
|
112 |
// sense. It's a type expression. Return the name of its generic
|
|
113 |
// type.
|
|
114 |
public String typeName() {
|
|
115 |
return TypeMaker.getTypeName(type, false);
|
|
116 |
}
|
|
117 |
|
|
118 |
public ParameterizedType asParameterizedType() {
|
|
119 |
return this;
|
|
120 |
}
|
|
121 |
|
|
122 |
public String toString() {
|
|
123 |
return parameterizedTypeToString(env, (ClassType)type, true);
|
|
124 |
}
|
|
125 |
|
|
126 |
static String parameterizedTypeToString(DocEnv env, ClassType cl,
|
|
127 |
boolean full) {
|
|
128 |
if (env.legacyDoclet) {
|
|
129 |
return TypeMaker.getTypeName(cl, full);
|
|
130 |
}
|
|
131 |
StringBuffer s = new StringBuffer();
|
|
132 |
if (cl.getEnclosingType().tag != CLASS) { // if not an inner class...
|
|
133 |
s.append(TypeMaker.getTypeName(cl, full));
|
|
134 |
} else {
|
|
135 |
ClassType encl = (ClassType)cl.getEnclosingType();
|
|
136 |
s.append(parameterizedTypeToString(env, encl, full))
|
|
137 |
.append('.')
|
|
138 |
.append(cl.tsym.name.toString());
|
|
139 |
}
|
|
140 |
s.append(TypeMaker.typeArgumentsString(env, cl, full));
|
|
141 |
return s.toString();
|
|
142 |
}
|
|
143 |
}
|