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:
27224
diff
changeset
|
26 |
package com.sun.tools.javadoc.main; |
10 | 27 |
|
28 |
import com.sun.javadoc.*; |
|
29 |
||
15385 | 30 |
import com.sun.tools.javac.code.Attribute; |
31 |
import com.sun.tools.javac.code.Attribute.TypeCompound; |
|
10 | 32 |
import com.sun.tools.javac.code.Kinds; |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
33 |
import com.sun.tools.javac.code.Kinds.KindSelector; |
10 | 34 |
import com.sun.tools.javac.code.Symbol; |
35 |
import com.sun.tools.javac.code.Symbol.ClassSymbol; |
|
36 |
import com.sun.tools.javac.code.Symbol.MethodSymbol; |
|
37 |
import com.sun.tools.javac.code.Type; |
|
38 |
import com.sun.tools.javac.code.Type.TypeVar; |
|
39 |
import com.sun.tools.javac.util.List; |
|
40 |
import com.sun.tools.javac.util.Name; |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
41 |
import com.sun.tools.javac.util.Names; |
10 | 42 |
|
43 |
/** |
|
44 |
* Implementation of <code>TypeVariable</code>, which |
|
45 |
* represents a type variable. |
|
46 |
* |
|
14260
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
47 |
* <p><b>This is NOT part of any supported API. |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
48 |
* If you write code that depends on this, you do so at your own risk. |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
49 |
* This code and its internal interfaces are subject to change or |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
50 |
* deletion without notice.</b> |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
51 |
* |
10 | 52 |
* @author Scott Seligman |
53 |
* @since 1.5 |
|
54 |
*/ |
|
48840
5e2d2067da48
8194651: javadoc: mark the com.sun.javadoc API for removal
ksrini
parents:
47216
diff
changeset
|
55 |
@Deprecated(since="9", forRemoval=true) |
5e2d2067da48
8194651: javadoc: mark the com.sun.javadoc API for removal
ksrini
parents:
47216
diff
changeset
|
56 |
@SuppressWarnings("removal") |
10 | 57 |
public class TypeVariableImpl extends AbstractTypeImpl implements TypeVariable { |
58 |
||
59 |
TypeVariableImpl(DocEnv env, TypeVar type) { |
|
60 |
super(env, type); |
|
61 |
} |
|
62 |
||
63 |
/** |
|
64 |
* Return the bounds of this type variable. |
|
65 |
*/ |
|
66 |
public com.sun.javadoc.Type[] bounds() { |
|
67 |
return TypeMaker.getTypes(env, getBounds((TypeVar)type, env)); |
|
68 |
} |
|
69 |
||
70 |
/** |
|
71 |
* Return the class, interface, method, or constructor within |
|
72 |
* which this type variable is declared. |
|
73 |
*/ |
|
74 |
public ProgramElementDoc owner() { |
|
75 |
Symbol osym = type.tsym.owner; |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
76 |
if (osym.kind.matches(KindSelector.TYP)) { |
10 | 77 |
return env.getClassDoc((ClassSymbol)osym); |
78 |
} |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
79 |
Names names = osym.name.table.names; |
10 | 80 |
if (osym.name == names.init) { |
81 |
return env.getConstructorDoc((MethodSymbol)osym); |
|
82 |
} else { |
|
83 |
return env.getMethodDoc((MethodSymbol)osym); |
|
84 |
} |
|
85 |
} |
|
86 |
||
87 |
/** |
|
88 |
* Return the ClassDoc of the erasure of this type variable. |
|
89 |
*/ |
|
8631
664f84942e74
6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents:
5520
diff
changeset
|
90 |
@Override |
10 | 91 |
public ClassDoc asClassDoc() { |
92 |
return env.getClassDoc((ClassSymbol)env.types.erasure(type).tsym); |
|
93 |
} |
|
94 |
||
8631
664f84942e74
6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents:
5520
diff
changeset
|
95 |
@Override |
10 | 96 |
public TypeVariable asTypeVariable() { |
97 |
return this; |
|
98 |
} |
|
99 |
||
8631
664f84942e74
6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents:
5520
diff
changeset
|
100 |
@Override |
10 | 101 |
public String toString() { |
102 |
return typeVarToString(env, (TypeVar)type, true); |
|
103 |
} |
|
104 |
||
105 |
||
106 |
/** |
|
107 |
* Return the string form of a type variable along with any |
|
108 |
* "extends" clause. Class names are qualified if "full" is true. |
|
109 |
*/ |
|
110 |
static String typeVarToString(DocEnv env, TypeVar v, boolean full) { |
|
8631
664f84942e74
6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents:
5520
diff
changeset
|
111 |
StringBuilder s = new StringBuilder(v.toString()); |
10 | 112 |
List<Type> bounds = getBounds(v, env); |
113 |
if (bounds.nonEmpty()) { |
|
114 |
boolean first = true; |
|
115 |
for (Type b : bounds) { |
|
116 |
s.append(first ? " extends " : " & "); |
|
117 |
s.append(TypeMaker.getTypeString(env, b, full)); |
|
118 |
first = false; |
|
119 |
} |
|
120 |
} |
|
121 |
return s.toString(); |
|
122 |
} |
|
123 |
||
124 |
/** |
|
125 |
* Get the bounds of a type variable as listed in the "extends" clause. |
|
126 |
*/ |
|
127 |
private static List<Type> getBounds(TypeVar v, DocEnv env) { |
|
15385 | 128 |
final Type upperBound = v.getUpperBound(); |
129 |
Name boundname = upperBound.tsym.getQualifiedName(); |
|
130 |
if (boundname == boundname.table.names.java_lang_Object |
|
16556
f4adc5bb4652
8008425: Remove interim new javax.lang.model API for type-annotations
jjg
parents:
15385
diff
changeset
|
131 |
&& !upperBound.isAnnotated()) { |
10 | 132 |
return List.nil(); |
133 |
} else { |
|
134 |
return env.types.getBounds(v); |
|
135 |
} |
|
136 |
} |
|
15385 | 137 |
|
138 |
/** |
|
139 |
* Get the annotations of this program element. |
|
140 |
* Return an empty array if there are none. |
|
141 |
*/ |
|
142 |
public AnnotationDesc[] annotations() { |
|
16556
f4adc5bb4652
8008425: Remove interim new javax.lang.model API for type-annotations
jjg
parents:
15385
diff
changeset
|
143 |
if (!type.isAnnotated()) { |
15385 | 144 |
return new AnnotationDesc[0]; |
145 |
} |
|
19906
2698aaacb4b2
8023833: Replace direct use of AnnotatedType in javadoc code
jjg
parents:
17578
diff
changeset
|
146 |
List<? extends TypeCompound> tas = type.getAnnotationMirrors(); |
15385 | 147 |
AnnotationDesc res[] = new AnnotationDesc[tas.length()]; |
148 |
int i = 0; |
|
149 |
for (Attribute.Compound a : tas) { |
|
150 |
res[i++] = new AnnotationDescImpl(env, a); |
|
151 |
} |
|
152 |
return res; |
|
153 |
} |
|
10 | 154 |
} |