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:
36526
diff
changeset
|
26 |
package com.sun.tools.javadoc.main; |
10 | 27 |
|
14258 | 28 |
import java.io.IOException; |
1869 | 29 |
import java.io.InputStream; |
14258 | 30 |
|
1869 | 31 |
import javax.tools.FileObject; |
10 | 32 |
|
1869 | 33 |
import com.sun.javadoc.*; |
14802 | 34 |
import com.sun.source.util.TreePath; |
10 | 35 |
import com.sun.tools.javac.code.Attribute; |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
22163
diff
changeset
|
36 |
import com.sun.tools.javac.code.Symbol; |
10 | 37 |
import com.sun.tools.javac.code.Symbol.ClassSymbol; |
38 |
import com.sun.tools.javac.code.Symbol.PackageSymbol; |
|
39 |
import com.sun.tools.javac.tree.JCTree; |
|
1869 | 40 |
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; |
10 | 41 |
import com.sun.tools.javac.util.List; |
42 |
import com.sun.tools.javac.util.ListBuffer; |
|
43 |
import com.sun.tools.javac.util.Name; |
|
44 |
import com.sun.tools.javac.util.Position; |
|
45 |
||
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
22163
diff
changeset
|
46 |
import static com.sun.tools.javac.code.Scope.LookupKind.NON_RECURSIVE; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
22163
diff
changeset
|
47 |
|
10 | 48 |
/** |
49 |
* Represents a java package. Provides access to information |
|
50 |
* about the package, the package's comment and tags, and the |
|
51 |
* classes in the package. |
|
52 |
* |
|
14260
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
53 |
* <p><b>This is NOT part of any supported API. |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
54 |
* 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
|
55 |
* 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
|
56 |
* deletion without notice.</b> |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
57 |
* |
10 | 58 |
* @since 1.2 |
59 |
* @author Kaiyang Liu (original) |
|
60 |
* @author Robert Field (rewrite) |
|
61 |
* @author Neal Gafter (rewrite) |
|
62 |
* @author Scott Seligman (package-info.java) |
|
63 |
*/ |
|
64 |
||
48840
5e2d2067da48
8194651: javadoc: mark the com.sun.javadoc API for removal
ksrini
parents:
47216
diff
changeset
|
65 |
@Deprecated(since="9", forRemoval=true) |
5e2d2067da48
8194651: javadoc: mark the com.sun.javadoc API for removal
ksrini
parents:
47216
diff
changeset
|
66 |
@SuppressWarnings("removal") |
10 | 67 |
public class PackageDocImpl extends DocImpl implements PackageDoc { |
68 |
||
36526 | 69 |
public final PackageSymbol sym; |
10 | 70 |
private JCCompilationUnit tree = null; // for source position |
71 |
||
1869 | 72 |
public FileObject docPath = null; |
10 | 73 |
private boolean foundDoc; // found a doc comment in either |
74 |
// package.html or package-info.java |
|
75 |
||
76 |
boolean isIncluded = false; // Set in RootDocImpl. |
|
77 |
public boolean setDocPath = false; //Flag to avoid setting doc path multiple times. |
|
78 |
||
79 |
/** |
|
80 |
* Constructor |
|
81 |
*/ |
|
82 |
public PackageDocImpl(DocEnv env, PackageSymbol sym) { |
|
14802 | 83 |
this(env, sym, null); |
10 | 84 |
} |
85 |
||
86 |
/** |
|
87 |
* Constructor |
|
88 |
*/ |
|
14802 | 89 |
public PackageDocImpl(DocEnv env, PackageSymbol sym, TreePath treePath) { |
90 |
super(env, treePath); |
|
10 | 91 |
this.sym = sym; |
14802 | 92 |
this.tree = (treePath == null) ? null : (JCCompilationUnit) treePath.getCompilationUnit(); |
10 | 93 |
foundDoc = (documentation != null); |
94 |
} |
|
95 |
||
96 |
void setTree(JCTree tree) { |
|
97 |
this.tree = (JCCompilationUnit) tree; |
|
98 |
} |
|
99 |
||
14802 | 100 |
public void setTreePath(TreePath treePath) { |
101 |
super.setTreePath(treePath); |
|
10 | 102 |
checkDoc(); |
103 |
} |
|
104 |
||
105 |
/** |
|
106 |
* Do lazy initialization of "documentation" string. |
|
107 |
*/ |
|
10189
57268b86d4da
7059905: (javadoc) promote method visibility for netbeans usage
ksrini
parents:
5520
diff
changeset
|
108 |
protected String documentation() { |
1869 | 109 |
if (documentation != null) |
110 |
return documentation; |
|
10 | 111 |
if (docPath != null) { |
112 |
// read from file |
|
113 |
try { |
|
1869 | 114 |
InputStream s = docPath.openInputStream(); |
10 | 115 |
documentation = readHTMLDocumentation(s, docPath); |
116 |
} catch (IOException exc) { |
|
117 |
documentation = ""; |
|
1869 | 118 |
env.error(null, "javadoc.File_Read_Error", docPath.getName()); |
10 | 119 |
} |
120 |
} else { |
|
121 |
// no doc file to be had |
|
122 |
documentation = ""; |
|
123 |
} |
|
124 |
return documentation; |
|
125 |
} |
|
126 |
||
127 |
/** |
|
128 |
* Cache of all classes contained in this package, including |
|
129 |
* member classes of those classes, and their member classes, etc. |
|
130 |
* Includes only those classes at the specified protection level |
|
131 |
* and weaker. |
|
132 |
*/ |
|
133 |
private List<ClassDocImpl> allClassesFiltered = null; |
|
134 |
||
135 |
/** |
|
136 |
* Cache of all classes contained in this package, including |
|
137 |
* member classes of those classes, and their member classes, etc. |
|
138 |
*/ |
|
139 |
private List<ClassDocImpl> allClasses = null; |
|
140 |
||
141 |
/** |
|
142 |
* Return a list of all classes contained in this package, including |
|
143 |
* member classes of those classes, and their member classes, etc. |
|
144 |
*/ |
|
145 |
private List<ClassDocImpl> getClasses(boolean filtered) { |
|
146 |
if (allClasses != null && !filtered) { |
|
147 |
return allClasses; |
|
148 |
} |
|
149 |
if (allClassesFiltered != null && filtered) { |
|
150 |
return allClassesFiltered; |
|
151 |
} |
|
22163 | 152 |
ListBuffer<ClassDocImpl> classes = new ListBuffer<>(); |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
22163
diff
changeset
|
153 |
for (Symbol enumerated : sym.members().getSymbols(NON_RECURSIVE)) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
22163
diff
changeset
|
154 |
if (enumerated != null) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
22163
diff
changeset
|
155 |
ClassSymbol s = (ClassSymbol)enumerated; |
10 | 156 |
ClassDocImpl c = env.getClassDoc(s); |
157 |
if (c != null && !c.isSynthetic()) |
|
158 |
c.addAllClasses(classes, filtered); |
|
159 |
} |
|
160 |
} |
|
161 |
if (filtered) |
|
162 |
return allClassesFiltered = classes.toList(); |
|
163 |
else |
|
164 |
return allClasses = classes.toList(); |
|
165 |
} |
|
166 |
||
167 |
/** |
|
168 |
* Add all included classes (including Exceptions and Errors) |
|
169 |
* and interfaces. |
|
170 |
*/ |
|
171 |
public void addAllClassesTo(ListBuffer<ClassDocImpl> list) { |
|
172 |
list.appendList(getClasses(true)); |
|
173 |
} |
|
174 |
||
175 |
/** |
|
176 |
* Get all classes (including Exceptions and Errors) |
|
177 |
* and interfaces. |
|
178 |
* @since J2SE1.4. |
|
179 |
* |
|
180 |
* @return all classes and interfaces in this package, filtered to include |
|
181 |
* only the included classes if filter==true. |
|
182 |
*/ |
|
183 |
public ClassDoc[] allClasses(boolean filter) { |
|
184 |
List<ClassDocImpl> classes = getClasses(filter); |
|
185 |
return classes.toArray(new ClassDocImpl[classes.length()]); |
|
186 |
} |
|
187 |
||
188 |
/** |
|
189 |
* Get all included classes (including Exceptions and Errors) |
|
190 |
* and interfaces. Same as allClasses(true). |
|
191 |
* |
|
192 |
* @return all included classes and interfaces in this package. |
|
193 |
*/ |
|
194 |
public ClassDoc[] allClasses() { |
|
195 |
return allClasses(true); |
|
196 |
} |
|
197 |
||
198 |
/** |
|
199 |
* Get ordinary classes (that is, exclude exceptions, errors, |
|
200 |
* enums, interfaces, and annotation types) in this package. |
|
201 |
* |
|
202 |
* @return included ordinary classes in this package. |
|
203 |
*/ |
|
204 |
public ClassDoc[] ordinaryClasses() { |
|
22163 | 205 |
ListBuffer<ClassDocImpl> ret = new ListBuffer<>(); |
10 | 206 |
for (ClassDocImpl c : getClasses(true)) { |
207 |
if (c.isOrdinaryClass()) { |
|
208 |
ret.append(c); |
|
209 |
} |
|
210 |
} |
|
211 |
return ret.toArray(new ClassDocImpl[ret.length()]); |
|
212 |
} |
|
213 |
||
214 |
/** |
|
215 |
* Get Exception classes in this package. |
|
216 |
* |
|
217 |
* @return included Exceptions in this package. |
|
218 |
*/ |
|
219 |
public ClassDoc[] exceptions() { |
|
22163 | 220 |
ListBuffer<ClassDocImpl> ret = new ListBuffer<>(); |
10 | 221 |
for (ClassDocImpl c : getClasses(true)) { |
222 |
if (c.isException()) { |
|
223 |
ret.append(c); |
|
224 |
} |
|
225 |
} |
|
226 |
return ret.toArray(new ClassDocImpl[ret.length()]); |
|
227 |
} |
|
228 |
||
229 |
/** |
|
230 |
* Get Error classes in this package. |
|
231 |
* |
|
232 |
* @return included Errors in this package. |
|
233 |
*/ |
|
234 |
public ClassDoc[] errors() { |
|
22163 | 235 |
ListBuffer<ClassDocImpl> ret = new ListBuffer<>(); |
10 | 236 |
for (ClassDocImpl c : getClasses(true)) { |
237 |
if (c.isError()) { |
|
238 |
ret.append(c); |
|
239 |
} |
|
240 |
} |
|
241 |
return ret.toArray(new ClassDocImpl[ret.length()]); |
|
242 |
} |
|
243 |
||
244 |
/** |
|
245 |
* Get included enum types in this package. |
|
246 |
* |
|
247 |
* @return included enum types in this package. |
|
248 |
*/ |
|
249 |
public ClassDoc[] enums() { |
|
22163 | 250 |
ListBuffer<ClassDocImpl> ret = new ListBuffer<>(); |
10 | 251 |
for (ClassDocImpl c : getClasses(true)) { |
252 |
if (c.isEnum()) { |
|
253 |
ret.append(c); |
|
254 |
} |
|
255 |
} |
|
256 |
return ret.toArray(new ClassDocImpl[ret.length()]); |
|
257 |
} |
|
258 |
||
259 |
/** |
|
260 |
* Get included interfaces in this package, omitting annotation types. |
|
261 |
* |
|
262 |
* @return included interfaces in this package. |
|
263 |
*/ |
|
264 |
public ClassDoc[] interfaces() { |
|
22163 | 265 |
ListBuffer<ClassDocImpl> ret = new ListBuffer<>(); |
10 | 266 |
for (ClassDocImpl c : getClasses(true)) { |
267 |
if (c.isInterface()) { |
|
268 |
ret.append(c); |
|
269 |
} |
|
270 |
} |
|
271 |
return ret.toArray(new ClassDocImpl[ret.length()]); |
|
272 |
} |
|
273 |
||
274 |
/** |
|
275 |
* Get included annotation types in this package. |
|
276 |
* |
|
277 |
* @return included annotation types in this package. |
|
278 |
*/ |
|
279 |
public AnnotationTypeDoc[] annotationTypes() { |
|
22163 | 280 |
ListBuffer<AnnotationTypeDocImpl> ret = new ListBuffer<>(); |
10 | 281 |
for (ClassDocImpl c : getClasses(true)) { |
282 |
if (c.isAnnotationType()) { |
|
283 |
ret.append((AnnotationTypeDocImpl)c); |
|
284 |
} |
|
285 |
} |
|
286 |
return ret.toArray(new AnnotationTypeDocImpl[ret.length()]); |
|
287 |
} |
|
288 |
||
289 |
/** |
|
290 |
* Get the annotations of this package. |
|
291 |
* Return an empty array if there are none. |
|
292 |
*/ |
|
293 |
public AnnotationDesc[] annotations() { |
|
14961
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14802
diff
changeset
|
294 |
AnnotationDesc res[] = new AnnotationDesc[sym.getRawAttributes().length()]; |
10 | 295 |
int i = 0; |
14961
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14802
diff
changeset
|
296 |
for (Attribute.Compound a : sym.getRawAttributes()) { |
10 | 297 |
res[i++] = new AnnotationDescImpl(env, a); |
298 |
} |
|
299 |
return res; |
|
300 |
} |
|
301 |
||
302 |
||
303 |
/** |
|
304 |
* Lookup for a class within this package. |
|
305 |
* |
|
306 |
* @return ClassDocImpl of found class, or null if not found. |
|
307 |
*/ |
|
308 |
public ClassDoc findClass(String className) { |
|
309 |
final boolean filtered = true; |
|
310 |
for (ClassDocImpl c : getClasses(filtered)) { |
|
311 |
if (c.name().equals(className)) { |
|
312 |
return c; |
|
313 |
} |
|
314 |
} |
|
315 |
return null; |
|
316 |
} |
|
317 |
||
318 |
/** |
|
319 |
* Return true if this package is included in the active set. |
|
320 |
*/ |
|
321 |
public boolean isIncluded() { |
|
322 |
return isIncluded; |
|
323 |
} |
|
324 |
||
325 |
/** |
|
326 |
* Get package name. |
|
327 |
* |
|
328 |
* Note that we do not provide a means of obtaining the simple |
|
329 |
* name of a package -- package names are always returned in their |
|
330 |
* uniquely qualified form. |
|
331 |
*/ |
|
332 |
public String name() { |
|
333 |
return qualifiedName(); |
|
334 |
} |
|
335 |
||
336 |
/** |
|
337 |
* Get package name. |
|
338 |
*/ |
|
339 |
public String qualifiedName() { |
|
17275
bcaa1940863a
8012656: cache frequently used name strings for DocImpl classes
jjg
parents:
14961
diff
changeset
|
340 |
if (qualifiedName == null) { |
bcaa1940863a
8012656: cache frequently used name strings for DocImpl classes
jjg
parents:
14961
diff
changeset
|
341 |
Name fullname = sym.getQualifiedName(); |
bcaa1940863a
8012656: cache frequently used name strings for DocImpl classes
jjg
parents:
14961
diff
changeset
|
342 |
// Some bogus tests depend on the interned "" being returned. |
bcaa1940863a
8012656: cache frequently used name strings for DocImpl classes
jjg
parents:
14961
diff
changeset
|
343 |
// See 6457276. |
bcaa1940863a
8012656: cache frequently used name strings for DocImpl classes
jjg
parents:
14961
diff
changeset
|
344 |
qualifiedName = fullname.isEmpty() ? "" : fullname.toString(); |
bcaa1940863a
8012656: cache frequently used name strings for DocImpl classes
jjg
parents:
14961
diff
changeset
|
345 |
} |
bcaa1940863a
8012656: cache frequently used name strings for DocImpl classes
jjg
parents:
14961
diff
changeset
|
346 |
return qualifiedName; |
10 | 347 |
} |
348 |
||
17275
bcaa1940863a
8012656: cache frequently used name strings for DocImpl classes
jjg
parents:
14961
diff
changeset
|
349 |
private String qualifiedName; |
bcaa1940863a
8012656: cache frequently used name strings for DocImpl classes
jjg
parents:
14961
diff
changeset
|
350 |
|
10 | 351 |
/** |
352 |
* set doc path for an unzipped directory |
|
353 |
*/ |
|
1869 | 354 |
public void setDocPath(FileObject path) { |
10 | 355 |
setDocPath = true; |
356 |
if (path == null) |
|
357 |
return; |
|
1869 | 358 |
if (!path.equals(docPath)) { |
359 |
docPath = path; |
|
10 | 360 |
checkDoc(); |
361 |
} |
|
362 |
} |
|
363 |
||
364 |
// Has checkDoc() sounded off yet? |
|
365 |
private boolean checkDocWarningEmitted = false; |
|
366 |
||
367 |
/** |
|
368 |
* Invoked when a source of package doc comments is located. |
|
369 |
* Emits a diagnostic if this is the second one. |
|
370 |
*/ |
|
371 |
private void checkDoc() { |
|
372 |
if (foundDoc) { |
|
373 |
if (!checkDocWarningEmitted) { |
|
374 |
env.warning(null, "javadoc.Multiple_package_comments", name()); |
|
375 |
checkDocWarningEmitted = true; |
|
376 |
} |
|
377 |
} else { |
|
378 |
foundDoc = true; |
|
379 |
} |
|
380 |
} |
|
381 |
||
382 |
/** |
|
383 |
* Return the source position of the entity, or null if |
|
384 |
* no position is available. |
|
385 |
*/ |
|
386 |
public SourcePosition position() { |
|
387 |
return (tree != null) |
|
1869 | 388 |
? SourcePositionImpl.make(tree.sourcefile, tree.pos, tree.lineMap) |
10 | 389 |
: SourcePositionImpl.make(docPath, Position.NOPOS, null); |
390 |
} |
|
391 |
} |