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) 1997, 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 |
|
1869
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1264
diff
changeset
|
28 |
import java.lang.reflect.Modifier; |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1264
diff
changeset
|
29 |
import java.text.CollationKey; |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1264
diff
changeset
|
30 |
|
10 | 31 |
import com.sun.javadoc.*; |
32 |
||
14802 | 33 |
import com.sun.source.util.TreePath; |
1869
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1264
diff
changeset
|
34 |
import com.sun.tools.javac.code.Flags; |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1264
diff
changeset
|
35 |
import com.sun.tools.javac.code.Symbol.*; |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1264
diff
changeset
|
36 |
import com.sun.tools.javac.code.Type; |
10 | 37 |
import com.sun.tools.javac.util.List; |
38 |
import com.sun.tools.javac.util.ListBuffer; |
|
39 |
||
40 |
/** |
|
41 |
* Represents a method or constructor of a java class. |
|
42 |
* |
|
14260 | 43 |
* <p><b>This is NOT part of any supported API. |
44 |
* If you write code that depends on this, you do so at your own risk. |
|
45 |
* This code and its internal interfaces are subject to change or |
|
46 |
* deletion without notice.</b> |
|
47 |
* |
|
10 | 48 |
* @since 1.2 |
49 |
* @author Robert Field |
|
50 |
* @author Neal Gafter (rewrite) |
|
51 |
* @author Scott Seligman (generics, annotations) |
|
52 |
*/ |
|
53 |
||
48840
5e2d2067da48
8194651: javadoc: mark the com.sun.javadoc API for removal
ksrini
parents:
47216
diff
changeset
|
54 |
@Deprecated(since="9", forRemoval=true) |
5e2d2067da48
8194651: javadoc: mark the com.sun.javadoc API for removal
ksrini
parents:
47216
diff
changeset
|
55 |
@SuppressWarnings("removal") |
10 | 56 |
public abstract class ExecutableMemberDocImpl |
57 |
extends MemberDocImpl implements ExecutableMemberDoc { |
|
58 |
||
59 |
protected final MethodSymbol sym; |
|
60 |
||
61 |
/** |
|
62 |
* Constructor. |
|
63 |
*/ |
|
14802 | 64 |
public ExecutableMemberDocImpl(DocEnv env, MethodSymbol sym, TreePath treePath) { |
65 |
super(env, sym, treePath); |
|
10 | 66 |
this.sym = sym; |
67 |
} |
|
68 |
||
69 |
/** |
|
70 |
* Constructor. |
|
71 |
*/ |
|
72 |
public ExecutableMemberDocImpl(DocEnv env, MethodSymbol sym) { |
|
14802 | 73 |
this(env, sym, null); |
10 | 74 |
} |
75 |
||
76 |
/** |
|
77 |
* Returns the flags in terms of javac's flags |
|
78 |
*/ |
|
79 |
protected long getFlags() { |
|
80 |
return sym.flags(); |
|
81 |
} |
|
82 |
||
83 |
/** |
|
84 |
* Identify the containing class |
|
85 |
*/ |
|
86 |
protected ClassSymbol getContainingClass() { |
|
87 |
return sym.enclClass(); |
|
88 |
} |
|
89 |
||
90 |
/** |
|
91 |
* Return true if this method is native |
|
92 |
*/ |
|
93 |
public boolean isNative() { |
|
94 |
return Modifier.isNative(getModifiers()); |
|
95 |
} |
|
96 |
||
97 |
/** |
|
98 |
* Return true if this method is synchronized |
|
99 |
*/ |
|
100 |
public boolean isSynchronized() { |
|
101 |
return Modifier.isSynchronized(getModifiers()); |
|
102 |
} |
|
103 |
||
104 |
/** |
|
105 |
* Return true if this method was declared to take a variable number |
|
106 |
* of arguments. |
|
107 |
*/ |
|
108 |
public boolean isVarArgs() { |
|
109 |
return ((sym.flags() & Flags.VARARGS) != 0 |
|
110 |
&& !env.legacyDoclet); |
|
111 |
} |
|
112 |
||
113 |
/** |
|
114 |
* Returns true if this field was synthesized by the compiler. |
|
115 |
*/ |
|
116 |
public boolean isSynthetic() { |
|
117 |
return ((sym.flags() & Flags.SYNTHETIC) != 0); |
|
118 |
} |
|
119 |
||
120 |
public boolean isIncluded() { |
|
121 |
return containingClass().isIncluded() && env.shouldDocument(sym); |
|
122 |
} |
|
123 |
||
124 |
/** |
|
125 |
* Return the throws tags in this method. |
|
126 |
* |
|
127 |
* @return an array of ThrowTagImpl containing all {@code @exception} |
|
128 |
* and {@code @throws} tags. |
|
129 |
*/ |
|
130 |
public ThrowsTag[] throwsTags() { |
|
131 |
return comment().throwsTags(); |
|
132 |
} |
|
133 |
||
134 |
/** |
|
135 |
* Return the param tags in this method, excluding the type |
|
136 |
* parameter tags. |
|
137 |
* |
|
138 |
* @return an array of ParamTagImpl containing all {@code @param} tags. |
|
139 |
*/ |
|
140 |
public ParamTag[] paramTags() { |
|
141 |
return comment().paramTags(); |
|
142 |
} |
|
143 |
||
144 |
/** |
|
145 |
* Return the type parameter tags in this method. |
|
146 |
*/ |
|
147 |
public ParamTag[] typeParamTags() { |
|
148 |
return env.legacyDoclet |
|
149 |
? new ParamTag[0] |
|
150 |
: comment().typeParamTags(); |
|
151 |
} |
|
152 |
||
153 |
/** |
|
154 |
* Return exceptions this method or constructor throws. |
|
155 |
* |
|
156 |
* @return an array of ClassDoc[] representing the exceptions |
|
157 |
* thrown by this method. |
|
158 |
*/ |
|
159 |
public ClassDoc[] thrownExceptions() { |
|
22163 | 160 |
ListBuffer<ClassDocImpl> l = new ListBuffer<>(); |
10 | 161 |
for (Type ex : sym.type.getThrownTypes()) { |
162 |
ex = env.types.erasure(ex); |
|
163 |
//### Will these casts succeed in the face of static semantic |
|
164 |
//### errors in the documented code? |
|
165 |
ClassDocImpl cdi = env.getClassDoc((ClassSymbol)ex.tsym); |
|
166 |
if (cdi != null) l.append(cdi); |
|
167 |
} |
|
168 |
return l.toArray(new ClassDocImpl[l.length()]); |
|
169 |
} |
|
170 |
||
171 |
/** |
|
172 |
* Return exceptions this method or constructor throws. |
|
173 |
* Each array element is either a <code>ClassDoc</code> or a |
|
174 |
* <code>TypeVariable</code>. |
|
175 |
*/ |
|
176 |
public com.sun.javadoc.Type[] thrownExceptionTypes() { |
|
177 |
return TypeMaker.getTypes(env, sym.type.getThrownTypes()); |
|
178 |
} |
|
179 |
||
180 |
/** |
|
181 |
* Get argument information. |
|
182 |
* |
|
183 |
* @see ParameterImpl |
|
184 |
* |
|
185 |
* @return an array of ParameterImpl, one element per argument |
|
186 |
* in the order the arguments are present. |
|
187 |
*/ |
|
188 |
public Parameter[] parameters() { |
|
189 |
// generate the parameters on the fly: they're not cached |
|
190 |
List<VarSymbol> params = sym.params(); |
|
191 |
Parameter result[] = new Parameter[params.length()]; |
|
192 |
||
193 |
int i = 0; |
|
194 |
for (VarSymbol param : params) { |
|
195 |
result[i++] = new ParameterImpl(env, param); |
|
196 |
} |
|
197 |
return result; |
|
198 |
} |
|
199 |
||
16964
096de5815398
8005091: javadoc should be able to return the receiver type
bpatel
parents:
16556
diff
changeset
|
200 |
/** |
096de5815398
8005091: javadoc should be able to return the receiver type
bpatel
parents:
16556
diff
changeset
|
201 |
* Get the receiver type of this executable element. |
096de5815398
8005091: javadoc should be able to return the receiver type
bpatel
parents:
16556
diff
changeset
|
202 |
* |
096de5815398
8005091: javadoc should be able to return the receiver type
bpatel
parents:
16556
diff
changeset
|
203 |
* @return the receiver type of this executable element. |
096de5815398
8005091: javadoc should be able to return the receiver type
bpatel
parents:
16556
diff
changeset
|
204 |
* @since 1.8 |
096de5815398
8005091: javadoc should be able to return the receiver type
bpatel
parents:
16556
diff
changeset
|
205 |
*/ |
096de5815398
8005091: javadoc should be able to return the receiver type
bpatel
parents:
16556
diff
changeset
|
206 |
public com.sun.javadoc.Type receiverType() { |
096de5815398
8005091: javadoc should be able to return the receiver type
bpatel
parents:
16556
diff
changeset
|
207 |
Type recvtype = sym.type.asMethodType().recvtype; |
096de5815398
8005091: javadoc should be able to return the receiver type
bpatel
parents:
16556
diff
changeset
|
208 |
return (recvtype != null) ? TypeMaker.getType(env, recvtype, false, true) : null; |
096de5815398
8005091: javadoc should be able to return the receiver type
bpatel
parents:
16556
diff
changeset
|
209 |
} |
096de5815398
8005091: javadoc should be able to return the receiver type
bpatel
parents:
16556
diff
changeset
|
210 |
|
10 | 211 |
/** |
212 |
* Return the formal type parameters of this method or constructor. |
|
213 |
* Return an empty array if there are none. |
|
214 |
*/ |
|
215 |
public TypeVariable[] typeParameters() { |
|
216 |
if (env.legacyDoclet) { |
|
217 |
return new TypeVariable[0]; |
|
218 |
} |
|
219 |
TypeVariable res[] = new TypeVariable[sym.type.getTypeArguments().length()]; |
|
220 |
TypeMaker.getTypes(env, sym.type.getTypeArguments(), res); |
|
221 |
return res; |
|
222 |
} |
|
223 |
||
224 |
/** |
|
225 |
* Get the signature. It is the parameter list, type is qualified. |
|
226 |
* For instance, for a method <code>mymethod(String x, int y)</code>, |
|
227 |
* it will return <code>(java.lang.String,int)</code>. |
|
228 |
*/ |
|
229 |
public String signature() { |
|
230 |
return makeSignature(true); |
|
231 |
} |
|
232 |
||
233 |
/** |
|
234 |
* Get flat signature. All types are not qualified. |
|
235 |
* Return a String, which is the flat signiture of this member. |
|
236 |
* It is the parameter list, type is not qualified. |
|
237 |
* For instance, for a method <code>mymethod(String x, int y)</code>, |
|
238 |
* it will return <code>(String, int)</code>. |
|
239 |
*/ |
|
240 |
public String flatSignature() { |
|
241 |
return makeSignature(false); |
|
242 |
} |
|
243 |
||
244 |
private String makeSignature(boolean full) { |
|
8631
664f84942e74
6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents:
5520
diff
changeset
|
245 |
StringBuilder result = new StringBuilder(); |
10 | 246 |
result.append("("); |
247 |
for (List<Type> types = sym.type.getParameterTypes(); types.nonEmpty(); ) { |
|
868 | 248 |
Type t = types.head; |
10 | 249 |
result.append(TypeMaker.getTypeString(env, t, full)); |
250 |
types = types.tail; |
|
251 |
if (types.nonEmpty()) { |
|
252 |
result.append(", "); |
|
253 |
} |
|
254 |
} |
|
255 |
if (isVarArgs()) { |
|
256 |
int len = result.length(); |
|
257 |
result.replace(len - 2, len, "..."); |
|
258 |
} |
|
259 |
result.append(")"); |
|
260 |
return result.toString(); |
|
261 |
} |
|
262 |
||
263 |
protected String typeParametersString() { |
|
264 |
return TypeMaker.typeParametersString(env, sym, true); |
|
265 |
} |
|
266 |
||
267 |
/** |
|
268 |
* Generate a key for sorting. |
|
269 |
*/ |
|
8631
664f84942e74
6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents:
5520
diff
changeset
|
270 |
@Override |
10 | 271 |
CollationKey generateKey() { |
272 |
String k = name() + flatSignature() + typeParametersString(); |
|
273 |
// ',' and '&' are between '$' and 'a': normalize to spaces. |
|
274 |
k = k.replace(',', ' ').replace('&', ' '); |
|
275 |
// System.out.println("COLLATION KEY FOR " + this + " is \"" + k + "\""); |
|
276 |
return env.doclocale.collator.getCollationKey(k); |
|
277 |
} |
|
278 |
||
279 |
/** |
|
280 |
* Return the source position of the entity, or null if |
|
281 |
* no position is available. |
|
282 |
*/ |
|
8631
664f84942e74
6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents:
5520
diff
changeset
|
283 |
@Override |
10 | 284 |
public SourcePosition position() { |
285 |
if (sym.enclClass().sourcefile == null) return null; |
|
1869
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1264
diff
changeset
|
286 |
return SourcePositionImpl.make(sym.enclClass().sourcefile, |
10 | 287 |
(tree==null) ? 0 : tree.pos, |
288 |
lineMap); |
|
289 |
} |
|
290 |
} |