author | ksrini |
Fri, 09 Feb 2018 13:58:17 -0800 | |
changeset 48840 | 5e2d2067da48 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
48840
5e2d2067da48
8194651: javadoc: mark the com.sun.javadoc API for removal
ksrini
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2003, 2018, 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 |
||
37938
42baa89d2156
8075703: jdk.javadoc module exports com.sun.tools.javadoc package which contains a lot of internal API.
jjg
parents:
25874
diff
changeset
|
26 |
package com.sun.tools.javadoc.main; |
10 | 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 |
*/ |
|
48840
5e2d2067da48
8194651: javadoc: mark the com.sun.javadoc API for removal
ksrini
parents:
47216
diff
changeset
|
49 |
@Deprecated(since="9", forRemoval=true) |
5e2d2067da48
8194651: javadoc: mark the com.sun.javadoc API for removal
ksrini
parents:
47216
diff
changeset
|
50 |
@SuppressWarnings("removal") |
10 | 51 |
public class ParameterizedTypeImpl |
52 |
extends AbstractTypeImpl implements ParameterizedType { |
|
53 |
||
54 |
ParameterizedTypeImpl(DocEnv env, Type type) { |
|
55 |
super(env, type); |
|
56 |
} |
|
57 |
||
58 |
/** |
|
59 |
* Return the generic class or interface that declared this type. |
|
60 |
*/ |
|
8631
664f84942e74
6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents:
5520
diff
changeset
|
61 |
@Override |
10 | 62 |
public ClassDoc asClassDoc() { |
63 |
return env.getClassDoc((ClassSymbol)type.tsym); |
|
64 |
} |
|
65 |
||
66 |
/** |
|
67 |
* Return the actual type arguments of this type. |
|
68 |
*/ |
|
69 |
public com.sun.javadoc.Type[] typeArguments() { |
|
70 |
return TypeMaker.getTypes(env, type.getTypeArguments()); |
|
71 |
} |
|
72 |
||
73 |
/** |
|
74 |
* Return the class type that is a direct supertype of this one. |
|
75 |
* Return null if this is an interface type. |
|
76 |
*/ |
|
77 |
public com.sun.javadoc.Type superclassType() { |
|
78 |
if (asClassDoc().isInterface()) { |
|
79 |
return null; |
|
80 |
} |
|
81 |
Type sup = env.types.supertype(type); |
|
82 |
return TypeMaker.getType(env, |
|
83 |
(sup != type) ? sup : env.syms.objectType); |
|
84 |
} |
|
85 |
||
86 |
/** |
|
87 |
* Return the interface types directly implemented by or extended by this |
|
88 |
* parameterized type. |
|
89 |
* Return an empty array if there are no interfaces. |
|
90 |
*/ |
|
91 |
public com.sun.javadoc.Type[] interfaceTypes() { |
|
92 |
return TypeMaker.getTypes(env, env.types.interfaces(type)); |
|
93 |
} |
|
94 |
||
95 |
/** |
|
96 |
* Return the type that contains this type as a member. |
|
97 |
* Return null is this is a top-level type. |
|
98 |
*/ |
|
99 |
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
|
100 |
if (type.getEnclosingType().hasTag(CLASS)) { |
10 | 101 |
// This is the type of an inner class. |
102 |
return TypeMaker.getType(env, type.getEnclosingType()); |
|
103 |
} |
|
104 |
ClassSymbol enclosing = type.tsym.owner.enclClass(); |
|
105 |
if (enclosing != null) { |
|
106 |
// Nested but not inner. Return the ClassDoc of the enclosing |
|
107 |
// class or interface. |
|
108 |
// See java.lang.reflect.ParameterizedType.getOwnerType(). |
|
109 |
return env.getClassDoc(enclosing); |
|
110 |
} |
|
111 |
return null; |
|
112 |
} |
|
113 |
||
114 |
||
115 |
// Asking for the "name" of a parameterized type doesn't exactly make |
|
116 |
// sense. It's a type expression. Return the name of its generic |
|
117 |
// type. |
|
8631
664f84942e74
6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents:
5520
diff
changeset
|
118 |
@Override |
10 | 119 |
public String typeName() { |
120 |
return TypeMaker.getTypeName(type, false); |
|
121 |
} |
|
122 |
||
8631
664f84942e74
6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents:
5520
diff
changeset
|
123 |
@Override |
10 | 124 |
public ParameterizedType asParameterizedType() { |
125 |
return this; |
|
126 |
} |
|
127 |
||
8631
664f84942e74
6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents:
5520
diff
changeset
|
128 |
@Override |
10 | 129 |
public String toString() { |
130 |
return parameterizedTypeToString(env, (ClassType)type, true); |
|
131 |
} |
|
132 |
||
133 |
static String parameterizedTypeToString(DocEnv env, ClassType cl, |
|
134 |
boolean full) { |
|
135 |
if (env.legacyDoclet) { |
|
136 |
return TypeMaker.getTypeName(cl, full); |
|
137 |
} |
|
8631
664f84942e74
6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents:
5520
diff
changeset
|
138 |
StringBuilder s = new StringBuilder(); |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14260
diff
changeset
|
139 |
if (!(cl.getEnclosingType().hasTag(CLASS))) { // if not an inner class... |
10 | 140 |
s.append(TypeMaker.getTypeName(cl, full)); |
141 |
} else { |
|
142 |
ClassType encl = (ClassType)cl.getEnclosingType(); |
|
143 |
s.append(parameterizedTypeToString(env, encl, full)) |
|
144 |
.append('.') |
|
145 |
.append(cl.tsym.name.toString()); |
|
146 |
} |
|
147 |
s.append(TypeMaker.typeArgumentsString(env, cl, full)); |
|
148 |
return s.toString(); |
|
149 |
} |
|
150 |
} |