author | jfranck |
Fri, 19 Apr 2013 11:57:46 +0200 | |
changeset 17276 | d0957ee0fad7 |
parent 14359 | d4099818ab70 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
14260 | 2 |
* Copyright (c) 2003, 2012, 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 |
import com.sun.javadoc.*; |
|
29 |
||
30 |
import com.sun.tools.javac.code.Symbol.ClassSymbol; |
|
31 |
import com.sun.tools.javac.code.Type; |
|
32 |
import com.sun.tools.javac.code.Type.ClassType; |
|
33 |
||
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14260
diff
changeset
|
34 |
import static com.sun.tools.javac.code.TypeTag.CLASS; |
10 | 35 |
|
36 |
||
37 |
/** |
|
38 |
* Implementation of <code>ParameterizedType</code>, which |
|
39 |
* represents an invocation of a generic class or interface. |
|
40 |
* |
|
14260 | 41 |
* <p><b>This is NOT part of any supported API. |
42 |
* If you write code that depends on this, you do so at your own risk. |
|
43 |
* This code and its internal interfaces are subject to change or |
|
44 |
* deletion without notice.</b> |
|
45 |
* |
|
10 | 46 |
* @author Scott Seligman |
47 |
* @since 1.5 |
|
48 |
*/ |
|
49 |
public class ParameterizedTypeImpl |
|
50 |
extends AbstractTypeImpl implements ParameterizedType { |
|
51 |
||
52 |
ParameterizedTypeImpl(DocEnv env, Type type) { |
|
53 |
super(env, type); |
|
54 |
} |
|
55 |
||
56 |
/** |
|
57 |
* Return the generic class or interface that declared this type. |
|
58 |
*/ |
|
8631
664f84942e74
6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents:
5520
diff
changeset
|
59 |
@Override |
10 | 60 |
public ClassDoc asClassDoc() { |
61 |
return env.getClassDoc((ClassSymbol)type.tsym); |
|
62 |
} |
|
63 |
||
64 |
/** |
|
65 |
* Return the actual type arguments of this type. |
|
66 |
*/ |
|
67 |
public com.sun.javadoc.Type[] typeArguments() { |
|
68 |
return TypeMaker.getTypes(env, type.getTypeArguments()); |
|
69 |
} |
|
70 |
||
71 |
/** |
|
72 |
* Return the class type that is a direct supertype of this one. |
|
73 |
* Return null if this is an interface type. |
|
74 |
*/ |
|
75 |
public com.sun.javadoc.Type superclassType() { |
|
76 |
if (asClassDoc().isInterface()) { |
|
77 |
return null; |
|
78 |
} |
|
79 |
Type sup = env.types.supertype(type); |
|
80 |
return TypeMaker.getType(env, |
|
81 |
(sup != type) ? sup : env.syms.objectType); |
|
82 |
} |
|
83 |
||
84 |
/** |
|
85 |
* Return the interface types directly implemented by or extended by this |
|
86 |
* parameterized type. |
|
87 |
* Return an empty array if there are no interfaces. |
|
88 |
*/ |
|
89 |
public com.sun.javadoc.Type[] interfaceTypes() { |
|
90 |
return TypeMaker.getTypes(env, env.types.interfaces(type)); |
|
91 |
} |
|
92 |
||
93 |
/** |
|
94 |
* Return the type that contains this type as a member. |
|
95 |
* Return null is this is a top-level type. |
|
96 |
*/ |
|
97 |
public com.sun.javadoc.Type containingType() { |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14260
diff
changeset
|
98 |
if (type.getEnclosingType().hasTag(CLASS)) { |
10 | 99 |
// This is the type of an inner class. |
100 |
return TypeMaker.getType(env, type.getEnclosingType()); |
|
101 |
} |
|
102 |
ClassSymbol enclosing = type.tsym.owner.enclClass(); |
|
103 |
if (enclosing != null) { |
|
104 |
// Nested but not inner. Return the ClassDoc of the enclosing |
|
105 |
// class or interface. |
|
106 |
// See java.lang.reflect.ParameterizedType.getOwnerType(). |
|
107 |
return env.getClassDoc(enclosing); |
|
108 |
} |
|
109 |
return null; |
|
110 |
} |
|
111 |
||
112 |
||
113 |
// Asking for the "name" of a parameterized type doesn't exactly make |
|
114 |
// sense. It's a type expression. Return the name of its generic |
|
115 |
// type. |
|
8631
664f84942e74
6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents:
5520
diff
changeset
|
116 |
@Override |
10 | 117 |
public String typeName() { |
118 |
return TypeMaker.getTypeName(type, false); |
|
119 |
} |
|
120 |
||
8631
664f84942e74
6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents:
5520
diff
changeset
|
121 |
@Override |
10 | 122 |
public ParameterizedType asParameterizedType() { |
123 |
return this; |
|
124 |
} |
|
125 |
||
8631
664f84942e74
6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents:
5520
diff
changeset
|
126 |
@Override |
10 | 127 |
public String toString() { |
128 |
return parameterizedTypeToString(env, (ClassType)type, true); |
|
129 |
} |
|
130 |
||
131 |
static String parameterizedTypeToString(DocEnv env, ClassType cl, |
|
132 |
boolean full) { |
|
133 |
if (env.legacyDoclet) { |
|
134 |
return TypeMaker.getTypeName(cl, full); |
|
135 |
} |
|
8631
664f84942e74
6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents:
5520
diff
changeset
|
136 |
StringBuilder s = new StringBuilder(); |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14260
diff
changeset
|
137 |
if (!(cl.getEnclosingType().hasTag(CLASS))) { // if not an inner class... |
10 | 138 |
s.append(TypeMaker.getTypeName(cl, full)); |
139 |
} else { |
|
140 |
ClassType encl = (ClassType)cl.getEnclosingType(); |
|
141 |
s.append(parameterizedTypeToString(env, encl, full)) |
|
142 |
.append('.') |
|
143 |
.append(cl.tsym.name.toString()); |
|
144 |
} |
|
145 |
s.append(TypeMaker.typeArgumentsString(env, cl, full)); |
|
146 |
return s.toString(); |
|
147 |
} |
|
148 |
} |