author | mcimadamore |
Mon, 04 Dec 2017 17:54:49 +0000 | |
changeset 48054 | 702043a4cdeb |
parent 47216 | 71c04702a3d5 |
child 48840 | 5e2d2067da48 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
43261 | 2 |
* Copyright (c) 1997, 2016, 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:
29957
diff
changeset
|
26 |
package com.sun.tools.javadoc.main; |
10 | 27 |
|
28 |
import java.io.IOException; |
|
15354 | 29 |
import java.util.Collection; |
1869
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1863
diff
changeset
|
30 |
import java.util.Locale; |
15354 | 31 |
|
14544 | 32 |
import javax.tools.JavaFileManager; |
1869
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1863
diff
changeset
|
33 |
import javax.tools.JavaFileObject; |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1863
diff
changeset
|
34 |
import javax.tools.StandardJavaFileManager; |
10 | 35 |
|
36 |
import com.sun.javadoc.*; |
|
48054
702043a4cdeb
8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents:
47216
diff
changeset
|
37 |
import com.sun.tools.javac.code.Source.Feature; |
10 | 38 |
import com.sun.tools.javac.tree.JCTree.JCClassDecl; |
39 |
import com.sun.tools.javac.util.List; |
|
40 |
import com.sun.tools.javac.util.ListBuffer; |
|
41 |
import com.sun.tools.javac.util.Position; |
|
42 |
||
43 |
/** |
|
44 |
* This class holds the information from one run of javadoc. |
|
45 |
* Particularly the packages, classes and options specified |
|
14260 | 46 |
* by the user. |
47 |
* |
|
48 |
* <p><b>This is NOT part of any supported API. |
|
49 |
* If you write code that depends on this, you do so at your own risk. |
|
50 |
* This code and its internal interfaces are subject to change or |
|
51 |
* deletion without notice.</b> |
|
10 | 52 |
* |
53 |
* @since 1.2 |
|
54 |
* @author Robert Field |
|
55 |
* @author Atul M Dambalkar |
|
56 |
* @author Neal Gafter (rewrite) |
|
57 |
*/ |
|
38617 | 58 |
@Deprecated |
10 | 59 |
public class RootDocImpl extends DocImpl implements RootDoc { |
60 |
||
61 |
/** |
|
62 |
* list of classes specified on the command line. |
|
63 |
*/ |
|
64 |
private List<ClassDocImpl> cmdLineClasses; |
|
65 |
||
66 |
/** |
|
67 |
* list of packages specified on the command line. |
|
68 |
*/ |
|
69 |
private List<PackageDocImpl> cmdLinePackages; |
|
70 |
||
71 |
/** |
|
72 |
* a collection of all options. |
|
73 |
*/ |
|
74 |
private List<String[]> options; |
|
75 |
||
76 |
/** |
|
77 |
* Constructor used when reading source files. |
|
78 |
* |
|
79 |
* @param env the documentation environment, state for this javadoc run |
|
80 |
* @param classes list of classes specified on the commandline |
|
81 |
* @param packages list of package names specified on the commandline |
|
82 |
* @param options list of options |
|
83 |
*/ |
|
84 |
public RootDocImpl(DocEnv env, List<JCClassDecl> classes, List<String> packages, List<String[]> options) { |
|
85 |
super(env, null); |
|
86 |
this.options = options; |
|
87 |
setPackages(env, packages); |
|
88 |
setClasses(env, classes); |
|
89 |
} |
|
90 |
||
91 |
/** |
|
92 |
* Constructor used when reading class files. |
|
93 |
* |
|
94 |
* @param env the documentation environment, state for this javadoc run |
|
95 |
* @param classes list of class names specified on the commandline |
|
96 |
* @param options list of options |
|
97 |
*/ |
|
98 |
public RootDocImpl(DocEnv env, List<String> classes, List<String[]> options) { |
|
99 |
super(env, null); |
|
100 |
this.options = options; |
|
101 |
cmdLinePackages = List.nil(); |
|
22163 | 102 |
ListBuffer<ClassDocImpl> classList = new ListBuffer<>(); |
10 | 103 |
for (String className : classes) { |
104 |
ClassDocImpl c = env.loadClass(className); |
|
105 |
if (c == null) |
|
106 |
env.error(null, "javadoc.class_not_found", className); |
|
107 |
else |
|
108 |
classList = classList.append(c); |
|
109 |
} |
|
110 |
cmdLineClasses = classList.toList(); |
|
111 |
} |
|
112 |
||
113 |
/** |
|
114 |
* Initialize classes information. Those classes are input from |
|
115 |
* command line. |
|
116 |
* |
|
117 |
* @param env the compilation environment |
|
118 |
* @param classes a list of ClassDeclaration |
|
119 |
*/ |
|
120 |
private void setClasses(DocEnv env, List<JCClassDecl> classes) { |
|
22163 | 121 |
ListBuffer<ClassDocImpl> result = new ListBuffer<>(); |
10 | 122 |
for (JCClassDecl def : classes) { |
123 |
//### Do we want modifier check here? |
|
124 |
if (env.shouldDocument(def.sym)) { |
|
125 |
ClassDocImpl cd = env.getClassDoc(def.sym); |
|
126 |
if (cd != null) { |
|
127 |
cd.isIncluded = true; |
|
128 |
result.append(cd); |
|
129 |
} //else System.out.println(" (classdoc is null)");//DEBUG |
|
130 |
} //else System.out.println(" (env.shouldDocument() returned false)");//DEBUG |
|
131 |
} |
|
132 |
cmdLineClasses = result.toList(); |
|
133 |
} |
|
134 |
||
135 |
/** |
|
136 |
* Initialize packages information. |
|
137 |
* |
|
138 |
* @param env the compilation environment |
|
139 |
* @param packages a list of package names (String) |
|
140 |
*/ |
|
141 |
private void setPackages(DocEnv env, List<String> packages) { |
|
22163 | 142 |
ListBuffer<PackageDocImpl> packlist = new ListBuffer<>(); |
10 | 143 |
for (String name : packages) { |
144 |
PackageDocImpl pkg = env.lookupPackage(name); |
|
145 |
if (pkg != null) { |
|
146 |
pkg.isIncluded = true; |
|
147 |
packlist.append(pkg); |
|
148 |
} else { |
|
149 |
env.warning(null, "main.no_source_files_for_package", name); |
|
150 |
} |
|
151 |
} |
|
152 |
cmdLinePackages = packlist.toList(); |
|
153 |
} |
|
154 |
||
155 |
/** |
|
156 |
* Command line options. |
|
157 |
* |
|
158 |
* <pre> |
|
159 |
* For example, given: |
|
160 |
* javadoc -foo this that -bar other ... |
|
161 |
* |
|
162 |
* This method will return: |
|
163 |
* options()[0][0] = "-foo" |
|
164 |
* options()[0][1] = "this" |
|
165 |
* options()[0][2] = "that" |
|
166 |
* options()[1][0] = "-bar" |
|
167 |
* options()[1][1] = "other" |
|
168 |
* </pre> |
|
169 |
* |
|
170 |
* @return an array of arrays of String. |
|
171 |
*/ |
|
172 |
public String[][] options() { |
|
173 |
return options.toArray(new String[options.length()][]); |
|
174 |
} |
|
175 |
||
176 |
/** |
|
177 |
* Packages specified on the command line. |
|
178 |
*/ |
|
179 |
public PackageDoc[] specifiedPackages() { |
|
180 |
return (PackageDoc[])cmdLinePackages |
|
181 |
.toArray(new PackageDocImpl[cmdLinePackages.length()]); |
|
182 |
} |
|
183 |
||
184 |
/** |
|
185 |
* Classes and interfaces specified on the command line. |
|
186 |
*/ |
|
187 |
public ClassDoc[] specifiedClasses() { |
|
22163 | 188 |
ListBuffer<ClassDocImpl> classesToDocument = new ListBuffer<>(); |
10 | 189 |
for (ClassDocImpl cd : cmdLineClasses) { |
190 |
cd.addAllClasses(classesToDocument, true); |
|
191 |
} |
|
192 |
return (ClassDoc[])classesToDocument.toArray(new ClassDocImpl[classesToDocument.length()]); |
|
193 |
} |
|
194 |
||
195 |
/** |
|
196 |
* Return all classes and interfaces (including those inside |
|
197 |
* packages) to be documented. |
|
198 |
*/ |
|
199 |
public ClassDoc[] classes() { |
|
22163 | 200 |
ListBuffer<ClassDocImpl> classesToDocument = new ListBuffer<>(); |
10 | 201 |
for (ClassDocImpl cd : cmdLineClasses) { |
202 |
cd.addAllClasses(classesToDocument, true); |
|
203 |
} |
|
204 |
for (PackageDocImpl pd : cmdLinePackages) { |
|
205 |
pd.addAllClassesTo(classesToDocument); |
|
206 |
} |
|
207 |
return classesToDocument.toArray(new ClassDocImpl[classesToDocument.length()]); |
|
208 |
} |
|
209 |
||
210 |
/** |
|
211 |
* Return a ClassDoc for the specified class/interface name |
|
212 |
* |
|
213 |
* @param qualifiedName qualified class name |
|
214 |
* (i.e. includes package name). |
|
215 |
* |
|
216 |
* @return a ClassDocImpl holding the specified class, null if |
|
217 |
* this class is not referenced. |
|
218 |
*/ |
|
219 |
public ClassDoc classNamed(String qualifiedName) { |
|
220 |
return env.lookupClass(qualifiedName); |
|
221 |
} |
|
222 |
||
223 |
/** |
|
224 |
* Return a PackageDoc for the specified package name |
|
225 |
* |
|
226 |
* @param name package name |
|
227 |
* |
|
228 |
* @return a PackageDoc holding the specified package, null if |
|
229 |
* this package is not referenced. |
|
230 |
*/ |
|
231 |
public PackageDoc packageNamed(String name) { |
|
232 |
return env.lookupPackage(name); |
|
233 |
} |
|
234 |
||
235 |
/** |
|
236 |
* Return the name of this Doc item. |
|
237 |
* |
|
238 |
* @return the string <code>"*RootDocImpl*"</code>. |
|
239 |
*/ |
|
240 |
public String name() { |
|
241 |
return "*RootDocImpl*"; |
|
242 |
} |
|
243 |
||
244 |
/** |
|
245 |
* Return the name of this Doc item. |
|
246 |
* |
|
247 |
* @return the string <code>"*RootDocImpl*"</code>. |
|
248 |
*/ |
|
249 |
public String qualifiedName() { |
|
250 |
return "*RootDocImpl*"; |
|
251 |
} |
|
252 |
||
253 |
/** |
|
254 |
* Return true if this Doc is include in the active set. |
|
255 |
* RootDocImpl isn't even a program entity so it is always false. |
|
256 |
*/ |
|
257 |
public boolean isIncluded() { |
|
258 |
return false; |
|
259 |
} |
|
260 |
||
261 |
/** |
|
262 |
* Print error message, increment error count. |
|
263 |
* |
|
264 |
* @param msg message to print |
|
265 |
*/ |
|
266 |
public void printError(String msg) { |
|
267 |
env.printError(msg); |
|
268 |
} |
|
269 |
||
270 |
/** |
|
271 |
* Print error message, increment error count. |
|
272 |
* |
|
273 |
* @param msg message to print |
|
274 |
*/ |
|
275 |
public void printError(SourcePosition pos, String msg) { |
|
276 |
env.printError(pos, msg); |
|
277 |
} |
|
278 |
||
279 |
/** |
|
280 |
* Print warning message, increment warning count. |
|
281 |
* |
|
282 |
* @param msg message to print |
|
283 |
*/ |
|
284 |
public void printWarning(String msg) { |
|
285 |
env.printWarning(msg); |
|
286 |
} |
|
287 |
||
288 |
/** |
|
289 |
* Print warning message, increment warning count. |
|
290 |
* |
|
291 |
* @param msg message to print |
|
292 |
*/ |
|
293 |
public void printWarning(SourcePosition pos, String msg) { |
|
294 |
env.printWarning(pos, msg); |
|
295 |
} |
|
296 |
||
297 |
/** |
|
298 |
* Print a message. |
|
299 |
* |
|
300 |
* @param msg message to print |
|
301 |
*/ |
|
302 |
public void printNotice(String msg) { |
|
303 |
env.printNotice(msg); |
|
304 |
} |
|
305 |
||
306 |
/** |
|
307 |
* Print a message. |
|
308 |
* |
|
309 |
* @param msg message to print |
|
310 |
*/ |
|
311 |
public void printNotice(SourcePosition pos, String msg) { |
|
312 |
env.printNotice(pos, msg); |
|
313 |
} |
|
314 |
||
315 |
/** |
|
316 |
* Return the path of the overview file and null if it does not exist. |
|
317 |
* @return the path of the overview file and null if it does not exist. |
|
318 |
*/ |
|
1869
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1863
diff
changeset
|
319 |
private JavaFileObject getOverviewPath() { |
10 | 320 |
for (String[] opt : options) { |
321 |
if (opt[0].equals("-overview")) { |
|
1869
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1863
diff
changeset
|
322 |
if (env.fileManager instanceof StandardJavaFileManager) { |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1863
diff
changeset
|
323 |
StandardJavaFileManager fm = (StandardJavaFileManager) env.fileManager; |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1863
diff
changeset
|
324 |
return fm.getJavaFileObjects(opt[1]).iterator().next(); |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1863
diff
changeset
|
325 |
} |
10 | 326 |
} |
327 |
} |
|
328 |
return null; |
|
329 |
} |
|
330 |
||
331 |
/** |
|
332 |
* Do lazy initialization of "documentation" string. |
|
333 |
*/ |
|
8633
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
5520
diff
changeset
|
334 |
@Override |
10 | 335 |
protected String documentation() { |
336 |
if (documentation == null) { |
|
1869
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1863
diff
changeset
|
337 |
JavaFileObject overviewPath = getOverviewPath(); |
10 | 338 |
if (overviewPath == null) { |
339 |
// no doc file to be had |
|
340 |
documentation = ""; |
|
341 |
} else { |
|
342 |
// read from file |
|
343 |
try { |
|
344 |
documentation = readHTMLDocumentation( |
|
1869
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1863
diff
changeset
|
345 |
overviewPath.openInputStream(), |
10 | 346 |
overviewPath); |
347 |
} catch (IOException exc) { |
|
348 |
documentation = ""; |
|
1869
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1863
diff
changeset
|
349 |
env.error(null, "javadoc.File_Read_Error", overviewPath.getName()); |
10 | 350 |
} |
351 |
} |
|
352 |
} |
|
353 |
return documentation; |
|
354 |
} |
|
355 |
||
356 |
/** |
|
357 |
* Return the source position of the entity, or null if |
|
358 |
* no position is available. |
|
359 |
*/ |
|
8633
41311e88ffb7
6964914: javadoc does not output number of warnings using user written doclet
jjg
parents:
5520
diff
changeset
|
360 |
@Override |
10 | 361 |
public SourcePosition position() { |
1869
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1863
diff
changeset
|
362 |
JavaFileObject path; |
10 | 363 |
return ((path = getOverviewPath()) == null) ? |
364 |
null : |
|
365 |
SourcePositionImpl.make(path, Position.NOPOS, null); |
|
366 |
} |
|
1863
e5de9abc0eb1
6786682: Javadoc HTML WCAG 2.0 accessibility issues in standard doclet - HTML tag should have lang attribute
bpatel
parents:
10
diff
changeset
|
367 |
|
e5de9abc0eb1
6786682: Javadoc HTML WCAG 2.0 accessibility issues in standard doclet - HTML tag should have lang attribute
bpatel
parents:
10
diff
changeset
|
368 |
/** |
e5de9abc0eb1
6786682: Javadoc HTML WCAG 2.0 accessibility issues in standard doclet - HTML tag should have lang attribute
bpatel
parents:
10
diff
changeset
|
369 |
* Return the locale provided by the user or the default locale value. |
e5de9abc0eb1
6786682: Javadoc HTML WCAG 2.0 accessibility issues in standard doclet - HTML tag should have lang attribute
bpatel
parents:
10
diff
changeset
|
370 |
*/ |
e5de9abc0eb1
6786682: Javadoc HTML WCAG 2.0 accessibility issues in standard doclet - HTML tag should have lang attribute
bpatel
parents:
10
diff
changeset
|
371 |
public Locale getLocale() { |
e5de9abc0eb1
6786682: Javadoc HTML WCAG 2.0 accessibility issues in standard doclet - HTML tag should have lang attribute
bpatel
parents:
10
diff
changeset
|
372 |
return env.doclocale.locale; |
e5de9abc0eb1
6786682: Javadoc HTML WCAG 2.0 accessibility issues in standard doclet - HTML tag should have lang attribute
bpatel
parents:
10
diff
changeset
|
373 |
} |
14544 | 374 |
|
375 |
/** |
|
376 |
* Return the current file manager. |
|
377 |
*/ |
|
378 |
public JavaFileManager getFileManager() { |
|
379 |
return env.fileManager; |
|
380 |
} |
|
15354 | 381 |
|
29957
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29150
diff
changeset
|
382 |
public void initDocLint(Collection<String> opts, Collection<String> customTagNames, |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29150
diff
changeset
|
383 |
String htmlVersion) { |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29150
diff
changeset
|
384 |
env.initDoclint(opts, customTagNames, htmlVersion); |
15354 | 385 |
} |
386 |
||
43261 | 387 |
public JavaScriptScanner initJavaScriptScanner(boolean allowScriptInComments) { |
388 |
return env.initJavaScriptScanner(allowScriptInComments); |
|
389 |
} |
|
390 |
||
23799
daa645653200
8029143: javadoc standard doclet should add Functional Interface blurb when @FunctionalInterface annotation is present
bpatel
parents:
22163
diff
changeset
|
391 |
public boolean isFunctionalInterface(AnnotationDesc annotationDesc) { |
48054
702043a4cdeb
8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents:
47216
diff
changeset
|
392 |
return Feature.LAMBDA.allowedInSource(env.source) |
29150 | 393 |
&& annotationDesc.annotationType().qualifiedName().equals( |
394 |
env.syms.functionalInterfaceType.toString()); |
|
23799
daa645653200
8029143: javadoc standard doclet should add Functional Interface blurb when @FunctionalInterface annotation is present
bpatel
parents:
22163
diff
changeset
|
395 |
} |
daa645653200
8029143: javadoc standard doclet should add Functional Interface blurb when @FunctionalInterface annotation is present
bpatel
parents:
22163
diff
changeset
|
396 |
|
15354 | 397 |
public boolean showTagMessages() { |
398 |
return env.showTagMessages(); |
|
399 |
} |
|
10 | 400 |
} |