author | jjg |
Fri, 27 May 2016 13:06:58 -0700 | |
changeset 38617 | d93a7f64e231 |
parent 37938 | 42baa89d2156 |
child 43261 | d377e97291d8 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
29957
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
2 |
* Copyright (c) 2000, 2015, 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 |
|
1869
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1264
diff
changeset
|
28 |
import java.lang.reflect.Modifier; |
10 | 29 |
import java.util.*; |
14802 | 30 |
|
1869
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1264
diff
changeset
|
31 |
import javax.tools.JavaFileManager; |
10 | 32 |
|
33 |
import com.sun.javadoc.*; |
|
31752 | 34 |
import com.sun.source.tree.CompilationUnitTree; |
15354 | 35 |
import com.sun.source.util.JavacTask; |
14802 | 36 |
import com.sun.source.util.TreePath; |
15354 | 37 |
import com.sun.tools.doclint.DocLint; |
38 |
import com.sun.tools.javac.api.BasicJavacTask; |
|
10 | 39 |
import com.sun.tools.javac.code.*; |
40 |
import com.sun.tools.javac.code.Symbol.*; |
|
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
24069
diff
changeset
|
41 |
import com.sun.tools.javac.code.Symbol.ClassSymbol; |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
24069
diff
changeset
|
42 |
import com.sun.tools.javac.code.Symbol.CompletionFailure; |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
24069
diff
changeset
|
43 |
import com.sun.tools.javac.code.Symbol.MethodSymbol; |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
24069
diff
changeset
|
44 |
import com.sun.tools.javac.code.Symbol.PackageSymbol; |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
24069
diff
changeset
|
45 |
import com.sun.tools.javac.code.Symbol.VarSymbol; |
10 | 46 |
import com.sun.tools.javac.code.Type.ClassType; |
47 |
import com.sun.tools.javac.comp.Check; |
|
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
24069
diff
changeset
|
48 |
import com.sun.tools.javac.comp.Enter; |
21891
42435b2c96cf
8027977: javadoc dies on NumberFormat/DateFormat subclass
bpatel
parents:
21500
diff
changeset
|
49 |
import com.sun.tools.javac.file.JavacFileManager; |
14802 | 50 |
import com.sun.tools.javac.tree.JCTree; |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
24069
diff
changeset
|
51 |
import com.sun.tools.javac.tree.JCTree.JCClassDecl; |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
24069
diff
changeset
|
52 |
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
24069
diff
changeset
|
53 |
import com.sun.tools.javac.tree.JCTree.JCPackageDecl; |
10 | 54 |
import com.sun.tools.javac.util.Context; |
36526 | 55 |
import com.sun.tools.javac.util.Convert; |
56 |
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
|
57 |
import com.sun.tools.javac.util.Names; |
10 | 58 |
|
59 |
/** |
|
60 |
* Holds the environment for a run of javadoc. |
|
61 |
* Holds only the information needed throughout the |
|
62 |
* run and not the compiler info that could be GC'ed |
|
63 |
* or ported. |
|
64 |
* |
|
14260
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
10189
diff
changeset
|
65 |
* <p><b>This is NOT part of any supported API. |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
10189
diff
changeset
|
66 |
* 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:
10189
diff
changeset
|
67 |
* This code and its internal interfaces are subject to change or |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
10189
diff
changeset
|
68 |
* deletion without notice.</b> |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
10189
diff
changeset
|
69 |
* |
10 | 70 |
* @since 1.4 |
71 |
* @author Robert Field |
|
72 |
* @author Neal Gafter (rewrite) |
|
73 |
* @author Scott Seligman (generics) |
|
74 |
*/ |
|
38617 | 75 |
@Deprecated |
10 | 76 |
public class DocEnv { |
22163 | 77 |
protected static final Context.Key<DocEnv> docEnvKey = new Context.Key<>(); |
10 | 78 |
|
79 |
public static DocEnv instance(Context context) { |
|
80 |
DocEnv instance = context.get(docEnvKey); |
|
81 |
if (instance == null) |
|
82 |
instance = new DocEnv(context); |
|
83 |
return instance; |
|
84 |
} |
|
85 |
||
86 |
DocLocale doclocale; |
|
87 |
||
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
24069
diff
changeset
|
88 |
private final Messager messager; |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
24069
diff
changeset
|
89 |
|
10 | 90 |
/** Predefined symbols known to the compiler. */ |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
24069
diff
changeset
|
91 |
final Symtab syms; |
10 | 92 |
|
93 |
/** Referenced directly in RootDocImpl. */ |
|
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
24069
diff
changeset
|
94 |
private final ClassFinder finder; |
10 | 95 |
|
96 |
/** Javadoc's own version of the compiler's enter phase. */ |
|
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
24069
diff
changeset
|
97 |
final Enter enter; |
10 | 98 |
|
99 |
/** The name table. */ |
|
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
24069
diff
changeset
|
100 |
private Names names; |
10 | 101 |
|
102 |
/** The encoding name. */ |
|
103 |
private String encoding; |
|
104 |
||
105 |
final Symbol externalizableSym; |
|
106 |
||
107 |
/** Access filter (public, protected, ...). */ |
|
10189
57268b86d4da
7059905: (javadoc) promote method visibility for netbeans usage
ksrini
parents:
7681
diff
changeset
|
108 |
protected ModifierFilter showAccess; |
10 | 109 |
|
110 |
/** True if we are using a sentence BreakIterator. */ |
|
111 |
boolean breakiterator; |
|
112 |
||
113 |
/** |
|
114 |
* True if we do not want to print any notifications at all. |
|
115 |
*/ |
|
116 |
boolean quiet = false; |
|
117 |
||
118 |
Check chk; |
|
119 |
Types types; |
|
1869
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1264
diff
changeset
|
120 |
JavaFileManager fileManager; |
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14260
diff
changeset
|
121 |
Context context; |
15354 | 122 |
DocLint doclint; |
10 | 123 |
|
22163 | 124 |
WeakHashMap<JCTree, TreePath> treePaths = new WeakHashMap<>(); |
14802 | 125 |
|
10 | 126 |
/** Allow documenting from class files? */ |
127 |
boolean docClasses = false; |
|
128 |
||
129 |
/** Does the doclet only expect pre-1.5 doclet API? */ |
|
10189
57268b86d4da
7059905: (javadoc) promote method visibility for netbeans usage
ksrini
parents:
7681
diff
changeset
|
130 |
protected boolean legacyDoclet = true; |
10 | 131 |
|
132 |
/** |
|
133 |
* Set this to true if you would like to not emit any errors, warnings and |
|
134 |
* notices. |
|
135 |
*/ |
|
136 |
private boolean silent = false; |
|
137 |
||
138 |
/** |
|
19912
4b1a79163f9c
8022738: doclet should only generate functional interface text if source >= 8
bpatel
parents:
16799
diff
changeset
|
139 |
* The source language version. |
4b1a79163f9c
8022738: doclet should only generate functional interface text if source >= 8
bpatel
parents:
16799
diff
changeset
|
140 |
*/ |
4b1a79163f9c
8022738: doclet should only generate functional interface text if source >= 8
bpatel
parents:
16799
diff
changeset
|
141 |
protected Source source; |
4b1a79163f9c
8022738: doclet should only generate functional interface text if source >= 8
bpatel
parents:
16799
diff
changeset
|
142 |
|
4b1a79163f9c
8022738: doclet should only generate functional interface text if source >= 8
bpatel
parents:
16799
diff
changeset
|
143 |
/** |
10 | 144 |
* Constructor |
145 |
* |
|
146 |
* @param context Context for this javadoc instance. |
|
147 |
*/ |
|
10189
57268b86d4da
7059905: (javadoc) promote method visibility for netbeans usage
ksrini
parents:
7681
diff
changeset
|
148 |
protected DocEnv(Context context) { |
10 | 149 |
context.put(docEnvKey, this); |
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14260
diff
changeset
|
150 |
this.context = context; |
10 | 151 |
|
152 |
messager = Messager.instance0(context); |
|
153 |
syms = Symtab.instance(context); |
|
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
24069
diff
changeset
|
154 |
finder = JavadocClassFinder.instance(context); |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
24069
diff
changeset
|
155 |
enter = JavadocEnter.instance(context); |
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
156 |
names = Names.instance(context); |
36526 | 157 |
externalizableSym = syms.enterClass(syms.java_base, names.fromString("java.io.Externalizable")); |
10 | 158 |
chk = Check.instance(context); |
159 |
types = Types.instance(context); |
|
1869
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1264
diff
changeset
|
160 |
fileManager = context.get(JavaFileManager.class); |
21891
42435b2c96cf
8027977: javadoc dies on NumberFormat/DateFormat subclass
bpatel
parents:
21500
diff
changeset
|
161 |
if (fileManager instanceof JavacFileManager) { |
42435b2c96cf
8027977: javadoc dies on NumberFormat/DateFormat subclass
bpatel
parents:
21500
diff
changeset
|
162 |
((JavacFileManager)fileManager).setSymbolFileEnabled(false); |
42435b2c96cf
8027977: javadoc dies on NumberFormat/DateFormat subclass
bpatel
parents:
21500
diff
changeset
|
163 |
} |
10 | 164 |
|
165 |
// Default. Should normally be reset with setLocale. |
|
166 |
this.doclocale = new DocLocale(this, "", breakiterator); |
|
19912
4b1a79163f9c
8022738: doclet should only generate functional interface text if source >= 8
bpatel
parents:
16799
diff
changeset
|
167 |
source = Source.instance(context); |
10 | 168 |
} |
169 |
||
170 |
public void setSilent(boolean silent) { |
|
171 |
this.silent = silent; |
|
172 |
} |
|
173 |
||
174 |
/** |
|
175 |
* Look up ClassDoc by qualified name. |
|
176 |
*/ |
|
177 |
public ClassDocImpl lookupClass(String name) { |
|
178 |
ClassSymbol c = getClassSymbol(name); |
|
179 |
if (c != null) { |
|
180 |
return getClassDoc(c); |
|
181 |
} else { |
|
182 |
return null; |
|
183 |
} |
|
184 |
} |
|
185 |
||
186 |
/** |
|
187 |
* Load ClassDoc by qualified name. |
|
188 |
*/ |
|
189 |
public ClassDocImpl loadClass(String name) { |
|
190 |
try { |
|
36526 | 191 |
Name nameImpl = names.fromString(name); |
192 |
ModuleSymbol mod = syms.inferModule(Convert.packagePart(nameImpl)); |
|
193 |
ClassSymbol c = finder.loadClass(mod != null ? mod : syms.errModule, nameImpl); |
|
10 | 194 |
return getClassDoc(c); |
195 |
} catch (CompletionFailure ex) { |
|
196 |
chk.completionError(null, ex); |
|
197 |
return null; |
|
198 |
} |
|
199 |
} |
|
200 |
||
201 |
/** |
|
202 |
* Look up PackageDoc by qualified name. |
|
203 |
*/ |
|
204 |
public PackageDocImpl lookupPackage(String name) { |
|
205 |
//### Jing alleges that class check is needed |
|
206 |
//### to avoid a compiler bug. Most likely |
|
207 |
//### instead a dummy created for error recovery. |
|
208 |
//### Should investigate this. |
|
36526 | 209 |
Name nameImpl = names.fromString(name); |
210 |
ModuleSymbol mod = syms.inferModule(nameImpl); |
|
211 |
PackageSymbol p = mod != null ? syms.getPackage(mod, nameImpl) : null; |
|
10 | 212 |
ClassSymbol c = getClassSymbol(name); |
213 |
if (p != null && c == null) { |
|
214 |
return getPackageDoc(p); |
|
215 |
} else { |
|
216 |
return null; |
|
217 |
} |
|
218 |
} |
|
219 |
// where |
|
220 |
/** Retrieve class symbol by fully-qualified name. |
|
221 |
*/ |
|
222 |
ClassSymbol getClassSymbol(String name) { |
|
223 |
// Name may contain nested class qualification. |
|
224 |
// Generate candidate flatnames with successively shorter |
|
225 |
// package qualifiers and longer nested class qualifiers. |
|
226 |
int nameLen = name.length(); |
|
227 |
char[] nameChars = name.toCharArray(); |
|
228 |
int idx = name.length(); |
|
229 |
for (;;) { |
|
36526 | 230 |
Name nameImpl = names.fromChars(nameChars, 0, nameLen); |
231 |
ModuleSymbol mod = syms.inferModule(Convert.packagePart(nameImpl)); |
|
232 |
ClassSymbol s = mod != null ? syms.getClass(mod, nameImpl) : null; |
|
10 | 233 |
if (s != null) |
234 |
return s; // found it! |
|
235 |
idx = name.substring(0, idx).lastIndexOf('.'); |
|
236 |
if (idx < 0) break; |
|
237 |
nameChars[idx] = '$'; |
|
238 |
} |
|
239 |
return null; |
|
240 |
} |
|
241 |
||
242 |
/** |
|
243 |
* Set the locale. |
|
244 |
*/ |
|
245 |
public void setLocale(String localeName) { |
|
246 |
// create locale specifics |
|
247 |
doclocale = new DocLocale(this, localeName, breakiterator); |
|
14543 | 248 |
// update Messager if locale has changed. |
249 |
messager.setLocale(doclocale.locale); |
|
10 | 250 |
} |
251 |
||
252 |
/** Check whether this member should be documented. */ |
|
253 |
public boolean shouldDocument(VarSymbol sym) { |
|
254 |
long mod = sym.flags(); |
|
255 |
||
256 |
if ((mod & Flags.SYNTHETIC) != 0) { |
|
257 |
return false; |
|
258 |
} |
|
259 |
||
260 |
return showAccess.checkModifier(translateModifiers(mod)); |
|
261 |
} |
|
262 |
||
263 |
/** Check whether this member should be documented. */ |
|
264 |
public boolean shouldDocument(MethodSymbol sym) { |
|
265 |
long mod = sym.flags(); |
|
266 |
||
267 |
if ((mod & Flags.SYNTHETIC) != 0) { |
|
268 |
return false; |
|
269 |
} |
|
270 |
||
271 |
return showAccess.checkModifier(translateModifiers(mod)); |
|
272 |
} |
|
273 |
||
274 |
/** check whether this class should be documented. */ |
|
275 |
public boolean shouldDocument(ClassSymbol sym) { |
|
276 |
return |
|
277 |
(sym.flags_field&Flags.SYNTHETIC) == 0 && // no synthetics |
|
278 |
(docClasses || getClassDoc(sym).tree != null) && |
|
279 |
isVisible(sym); |
|
280 |
} |
|
281 |
||
282 |
//### Comment below is inaccurate wrt modifier filter testing |
|
283 |
/** |
|
284 |
* Check the visibility if this is an nested class. |
|
285 |
* if this is not a nested class, return true. |
|
286 |
* if this is an static visible nested class, |
|
287 |
* return true. |
|
288 |
* if this is an visible nested class |
|
289 |
* if the outer class is visible return true. |
|
290 |
* else return false. |
|
291 |
* IMPORTANT: This also allows, static nested classes |
|
292 |
* to be defined inside an nested class, which is not |
|
293 |
* allowed by the compiler. So such an test case will |
|
294 |
* not reach upto this method itself, but if compiler |
|
295 |
* allows it, then that will go through. |
|
296 |
*/ |
|
297 |
protected boolean isVisible(ClassSymbol sym) { |
|
298 |
long mod = sym.flags_field; |
|
299 |
if (!showAccess.checkModifier(translateModifiers(mod))) { |
|
300 |
return false; |
|
301 |
} |
|
302 |
ClassSymbol encl = sym.owner.enclClass(); |
|
303 |
return (encl == null || (mod & Flags.STATIC) != 0 || isVisible(encl)); |
|
304 |
} |
|
305 |
||
306 |
//---------------- print forwarders ----------------// |
|
307 |
||
308 |
/** |
|
309 |
* Print error message, increment error count. |
|
310 |
* |
|
311 |
* @param msg message to print. |
|
312 |
*/ |
|
313 |
public void printError(String msg) { |
|
314 |
if (silent) |
|
315 |
return; |
|
316 |
messager.printError(msg); |
|
317 |
} |
|
318 |
||
319 |
/** |
|
320 |
* Print error message, increment error count. |
|
321 |
* |
|
322 |
* @param key selects message from resource |
|
323 |
*/ |
|
324 |
public void error(DocImpl doc, String key) { |
|
325 |
if (silent) |
|
326 |
return; |
|
327 |
messager.error(doc==null ? null : doc.position(), key); |
|
328 |
} |
|
329 |
||
330 |
/** |
|
331 |
* Print error message, increment error count. |
|
332 |
* |
|
333 |
* @param key selects message from resource |
|
334 |
*/ |
|
335 |
public void error(SourcePosition pos, String key) { |
|
336 |
if (silent) |
|
337 |
return; |
|
338 |
messager.error(pos, key); |
|
339 |
} |
|
340 |
||
341 |
/** |
|
342 |
* Print error message, increment error count. |
|
343 |
* |
|
344 |
* @param msg message to print. |
|
345 |
*/ |
|
346 |
public void printError(SourcePosition pos, String msg) { |
|
347 |
if (silent) |
|
348 |
return; |
|
349 |
messager.printError(pos, msg); |
|
350 |
} |
|
351 |
||
352 |
/** |
|
353 |
* Print error message, increment error count. |
|
354 |
* |
|
355 |
* @param key selects message from resource |
|
356 |
* @param a1 first argument |
|
357 |
*/ |
|
358 |
public void error(DocImpl doc, String key, String a1) { |
|
359 |
if (silent) |
|
360 |
return; |
|
361 |
messager.error(doc==null ? null : doc.position(), key, a1); |
|
362 |
} |
|
363 |
||
364 |
/** |
|
365 |
* Print error message, increment error count. |
|
366 |
* |
|
367 |
* @param key selects message from resource |
|
368 |
* @param a1 first argument |
|
369 |
* @param a2 second argument |
|
370 |
*/ |
|
371 |
public void error(DocImpl doc, String key, String a1, String a2) { |
|
372 |
if (silent) |
|
373 |
return; |
|
374 |
messager.error(doc==null ? null : doc.position(), key, a1, a2); |
|
375 |
} |
|
376 |
||
377 |
/** |
|
378 |
* Print error message, increment error count. |
|
379 |
* |
|
380 |
* @param key selects message from resource |
|
381 |
* @param a1 first argument |
|
382 |
* @param a2 second argument |
|
383 |
* @param a3 third argument |
|
384 |
*/ |
|
385 |
public void error(DocImpl doc, String key, String a1, String a2, String a3) { |
|
386 |
if (silent) |
|
387 |
return; |
|
388 |
messager.error(doc==null ? null : doc.position(), key, a1, a2, a3); |
|
389 |
} |
|
390 |
||
391 |
/** |
|
392 |
* Print warning message, increment warning count. |
|
393 |
* |
|
394 |
* @param msg message to print. |
|
395 |
*/ |
|
396 |
public void printWarning(String msg) { |
|
397 |
if (silent) |
|
398 |
return; |
|
399 |
messager.printWarning(msg); |
|
400 |
} |
|
401 |
||
402 |
/** |
|
403 |
* Print warning message, increment warning count. |
|
404 |
* |
|
405 |
* @param key selects message from resource |
|
406 |
*/ |
|
407 |
public void warning(DocImpl doc, String key) { |
|
408 |
if (silent) |
|
409 |
return; |
|
410 |
messager.warning(doc==null ? null : doc.position(), key); |
|
411 |
} |
|
412 |
||
413 |
/** |
|
414 |
* Print warning message, increment warning count. |
|
415 |
* |
|
416 |
* @param msg message to print. |
|
417 |
*/ |
|
418 |
public void printWarning(SourcePosition pos, String msg) { |
|
419 |
if (silent) |
|
420 |
return; |
|
421 |
messager.printWarning(pos, msg); |
|
422 |
} |
|
423 |
||
424 |
/** |
|
425 |
* Print warning message, increment warning count. |
|
426 |
* |
|
427 |
* @param key selects message from resource |
|
428 |
* @param a1 first argument |
|
429 |
*/ |
|
430 |
public void warning(DocImpl doc, String key, String a1) { |
|
431 |
if (silent) |
|
432 |
return; |
|
15354 | 433 |
// suppress messages that have (probably) been covered by doclint |
434 |
if (doclint != null && doc != null && key.startsWith("tag")) |
|
435 |
return; |
|
10 | 436 |
messager.warning(doc==null ? null : doc.position(), key, a1); |
437 |
} |
|
438 |
||
439 |
/** |
|
440 |
* Print warning message, increment warning count. |
|
441 |
* |
|
442 |
* @param key selects message from resource |
|
443 |
* @param a1 first argument |
|
444 |
* @param a2 second argument |
|
445 |
*/ |
|
446 |
public void warning(DocImpl doc, String key, String a1, String a2) { |
|
447 |
if (silent) |
|
448 |
return; |
|
449 |
messager.warning(doc==null ? null : doc.position(), key, a1, a2); |
|
450 |
} |
|
451 |
||
452 |
/** |
|
453 |
* Print warning message, increment warning count. |
|
454 |
* |
|
455 |
* @param key selects message from resource |
|
456 |
* @param a1 first argument |
|
457 |
* @param a2 second argument |
|
458 |
* @param a3 third argument |
|
459 |
*/ |
|
460 |
public void warning(DocImpl doc, String key, String a1, String a2, String a3) { |
|
461 |
if (silent) |
|
462 |
return; |
|
463 |
messager.warning(doc==null ? null : doc.position(), key, a1, a2, a3); |
|
464 |
} |
|
465 |
||
466 |
/** |
|
467 |
* Print warning message, increment warning count. |
|
468 |
* |
|
469 |
* @param key selects message from resource |
|
470 |
* @param a1 first argument |
|
471 |
* @param a2 second argument |
|
472 |
* @param a3 third argument |
|
473 |
*/ |
|
474 |
public void warning(DocImpl doc, String key, String a1, String a2, String a3, |
|
475 |
String a4) { |
|
476 |
if (silent) |
|
477 |
return; |
|
478 |
messager.warning(doc==null ? null : doc.position(), key, a1, a2, a3, a4); |
|
479 |
} |
|
480 |
||
481 |
/** |
|
482 |
* Print a message. |
|
483 |
* |
|
484 |
* @param msg message to print. |
|
485 |
*/ |
|
486 |
public void printNotice(String msg) { |
|
487 |
if (silent || quiet) |
|
488 |
return; |
|
489 |
messager.printNotice(msg); |
|
490 |
} |
|
491 |
||
492 |
||
493 |
/** |
|
494 |
* Print a message. |
|
495 |
* |
|
496 |
* @param key selects message from resource |
|
497 |
*/ |
|
498 |
public void notice(String key) { |
|
499 |
if (silent || quiet) |
|
500 |
return; |
|
501 |
messager.notice(key); |
|
502 |
} |
|
503 |
||
504 |
/** |
|
505 |
* Print a message. |
|
506 |
* |
|
507 |
* @param msg message to print. |
|
508 |
*/ |
|
509 |
public void printNotice(SourcePosition pos, String msg) { |
|
510 |
if (silent || quiet) |
|
511 |
return; |
|
512 |
messager.printNotice(pos, msg); |
|
513 |
} |
|
514 |
||
515 |
/** |
|
516 |
* Print a message. |
|
517 |
* |
|
518 |
* @param key selects message from resource |
|
519 |
* @param a1 first argument |
|
520 |
*/ |
|
521 |
public void notice(String key, String a1) { |
|
522 |
if (silent || quiet) |
|
523 |
return; |
|
524 |
messager.notice(key, a1); |
|
525 |
} |
|
526 |
||
527 |
/** |
|
528 |
* Print a message. |
|
529 |
* |
|
530 |
* @param key selects message from resource |
|
531 |
* @param a1 first argument |
|
532 |
* @param a2 second argument |
|
533 |
*/ |
|
534 |
public void notice(String key, String a1, String a2) { |
|
535 |
if (silent || quiet) |
|
536 |
return; |
|
537 |
messager.notice(key, a1, a2); |
|
538 |
} |
|
539 |
||
540 |
/** |
|
541 |
* Print a message. |
|
542 |
* |
|
543 |
* @param key selects message from resource |
|
544 |
* @param a1 first argument |
|
545 |
* @param a2 second argument |
|
546 |
* @param a3 third argument |
|
547 |
*/ |
|
548 |
public void notice(String key, String a1, String a2, String a3) { |
|
549 |
if (silent || quiet) |
|
550 |
return; |
|
551 |
messager.notice(key, a1, a2, a3); |
|
552 |
} |
|
553 |
||
554 |
/** |
|
555 |
* Exit, reporting errors and warnings. |
|
556 |
*/ |
|
557 |
public void exit() { |
|
558 |
// Messager should be replaced by a more general |
|
559 |
// compilation environment. This can probably |
|
560 |
// subsume DocEnv as well. |
|
561 |
messager.exit(); |
|
562 |
} |
|
563 |
||
22163 | 564 |
protected Map<PackageSymbol, PackageDocImpl> packageMap = new HashMap<>(); |
10 | 565 |
/** |
566 |
* Return the PackageDoc of this package symbol. |
|
567 |
*/ |
|
568 |
public PackageDocImpl getPackageDoc(PackageSymbol pack) { |
|
569 |
PackageDocImpl result = packageMap.get(pack); |
|
570 |
if (result != null) return result; |
|
571 |
result = new PackageDocImpl(this, pack); |
|
572 |
packageMap.put(pack, result); |
|
573 |
return result; |
|
574 |
} |
|
575 |
||
576 |
/** |
|
577 |
* Create the PackageDoc (or a subtype) for a package symbol. |
|
578 |
*/ |
|
14802 | 579 |
void makePackageDoc(PackageSymbol pack, TreePath treePath) { |
10 | 580 |
PackageDocImpl result = packageMap.get(pack); |
581 |
if (result != null) { |
|
14802 | 582 |
if (treePath != null) result.setTreePath(treePath); |
10 | 583 |
} else { |
14802 | 584 |
result = new PackageDocImpl(this, pack, treePath); |
10 | 585 |
packageMap.put(pack, result); |
586 |
} |
|
587 |
} |
|
588 |
||
589 |
||
22163 | 590 |
protected Map<ClassSymbol, ClassDocImpl> classMap = new HashMap<>(); |
10 | 591 |
/** |
592 |
* Return the ClassDoc (or a subtype) of this class symbol. |
|
593 |
*/ |
|
10189
57268b86d4da
7059905: (javadoc) promote method visibility for netbeans usage
ksrini
parents:
7681
diff
changeset
|
594 |
public ClassDocImpl getClassDoc(ClassSymbol clazz) { |
10 | 595 |
ClassDocImpl result = classMap.get(clazz); |
596 |
if (result != null) return result; |
|
597 |
if (isAnnotationType(clazz)) { |
|
598 |
result = new AnnotationTypeDocImpl(this, clazz); |
|
599 |
} else { |
|
600 |
result = new ClassDocImpl(this, clazz); |
|
601 |
} |
|
602 |
classMap.put(clazz, result); |
|
603 |
return result; |
|
604 |
} |
|
605 |
||
606 |
/** |
|
607 |
* Create the ClassDoc (or a subtype) for a class symbol. |
|
608 |
*/ |
|
14802 | 609 |
protected void makeClassDoc(ClassSymbol clazz, TreePath treePath) { |
10 | 610 |
ClassDocImpl result = classMap.get(clazz); |
611 |
if (result != null) { |
|
14802 | 612 |
if (treePath != null) result.setTreePath(treePath); |
10 | 613 |
return; |
614 |
} |
|
14802 | 615 |
if (isAnnotationType((JCClassDecl) treePath.getLeaf())) { // flags of clazz may not yet be set |
616 |
result = new AnnotationTypeDocImpl(this, clazz, treePath); |
|
10 | 617 |
} else { |
14802 | 618 |
result = new ClassDocImpl(this, clazz, treePath); |
10 | 619 |
} |
620 |
classMap.put(clazz, result); |
|
621 |
} |
|
622 |
||
10189
57268b86d4da
7059905: (javadoc) promote method visibility for netbeans usage
ksrini
parents:
7681
diff
changeset
|
623 |
protected static boolean isAnnotationType(ClassSymbol clazz) { |
10 | 624 |
return ClassDocImpl.isAnnotationType(clazz); |
625 |
} |
|
626 |
||
10189
57268b86d4da
7059905: (javadoc) promote method visibility for netbeans usage
ksrini
parents:
7681
diff
changeset
|
627 |
protected static boolean isAnnotationType(JCClassDecl tree) { |
10 | 628 |
return (tree.mods.flags & Flags.ANNOTATION) != 0; |
629 |
} |
|
630 |
||
22163 | 631 |
protected Map<VarSymbol, FieldDocImpl> fieldMap = new HashMap<>(); |
10 | 632 |
/** |
633 |
* Return the FieldDoc of this var symbol. |
|
634 |
*/ |
|
10189
57268b86d4da
7059905: (javadoc) promote method visibility for netbeans usage
ksrini
parents:
7681
diff
changeset
|
635 |
public FieldDocImpl getFieldDoc(VarSymbol var) { |
10 | 636 |
FieldDocImpl result = fieldMap.get(var); |
637 |
if (result != null) return result; |
|
638 |
result = new FieldDocImpl(this, var); |
|
639 |
fieldMap.put(var, result); |
|
640 |
return result; |
|
641 |
} |
|
642 |
/** |
|
643 |
* Create a FieldDoc for a var symbol. |
|
644 |
*/ |
|
14802 | 645 |
protected void makeFieldDoc(VarSymbol var, TreePath treePath) { |
10 | 646 |
FieldDocImpl result = fieldMap.get(var); |
647 |
if (result != null) { |
|
14802 | 648 |
if (treePath != null) result.setTreePath(treePath); |
10 | 649 |
} else { |
14802 | 650 |
result = new FieldDocImpl(this, var, treePath); |
10 | 651 |
fieldMap.put(var, result); |
652 |
} |
|
653 |
} |
|
654 |
||
22163 | 655 |
protected Map<MethodSymbol, ExecutableMemberDocImpl> methodMap = new HashMap<>(); |
10 | 656 |
/** |
657 |
* Create a MethodDoc for this MethodSymbol. |
|
658 |
* Should be called only on symbols representing methods. |
|
659 |
*/ |
|
14802 | 660 |
protected void makeMethodDoc(MethodSymbol meth, TreePath treePath) { |
10 | 661 |
MethodDocImpl result = (MethodDocImpl)methodMap.get(meth); |
662 |
if (result != null) { |
|
14802 | 663 |
if (treePath != null) result.setTreePath(treePath); |
10 | 664 |
} else { |
14802 | 665 |
result = new MethodDocImpl(this, meth, treePath); |
10 | 666 |
methodMap.put(meth, result); |
667 |
} |
|
668 |
} |
|
669 |
||
670 |
/** |
|
671 |
* Return the MethodDoc for a MethodSymbol. |
|
672 |
* Should be called only on symbols representing methods. |
|
673 |
*/ |
|
674 |
public MethodDocImpl getMethodDoc(MethodSymbol meth) { |
|
7071
8bcda461a06a
6551367: javadoc throws ClassCastException when an @link tries to reference constructor.
sundar
parents:
5520
diff
changeset
|
675 |
assert !meth.isConstructor() : "not expecting a constructor symbol"; |
10 | 676 |
MethodDocImpl result = (MethodDocImpl)methodMap.get(meth); |
677 |
if (result != null) return result; |
|
678 |
result = new MethodDocImpl(this, meth); |
|
679 |
methodMap.put(meth, result); |
|
680 |
return result; |
|
681 |
} |
|
682 |
||
683 |
/** |
|
684 |
* Create the ConstructorDoc for a MethodSymbol. |
|
685 |
* Should be called only on symbols representing constructors. |
|
686 |
*/ |
|
14802 | 687 |
protected void makeConstructorDoc(MethodSymbol meth, TreePath treePath) { |
10 | 688 |
ConstructorDocImpl result = (ConstructorDocImpl)methodMap.get(meth); |
689 |
if (result != null) { |
|
14802 | 690 |
if (treePath != null) result.setTreePath(treePath); |
10 | 691 |
} else { |
14802 | 692 |
result = new ConstructorDocImpl(this, meth, treePath); |
10 | 693 |
methodMap.put(meth, result); |
694 |
} |
|
695 |
} |
|
696 |
||
697 |
/** |
|
698 |
* Return the ConstructorDoc for a MethodSymbol. |
|
699 |
* Should be called only on symbols representing constructors. |
|
700 |
*/ |
|
701 |
public ConstructorDocImpl getConstructorDoc(MethodSymbol meth) { |
|
7071
8bcda461a06a
6551367: javadoc throws ClassCastException when an @link tries to reference constructor.
sundar
parents:
5520
diff
changeset
|
702 |
assert meth.isConstructor() : "expecting a constructor symbol"; |
10 | 703 |
ConstructorDocImpl result = (ConstructorDocImpl)methodMap.get(meth); |
704 |
if (result != null) return result; |
|
705 |
result = new ConstructorDocImpl(this, meth); |
|
706 |
methodMap.put(meth, result); |
|
707 |
return result; |
|
708 |
} |
|
709 |
||
710 |
/** |
|
711 |
* Create the AnnotationTypeElementDoc for a MethodSymbol. |
|
712 |
* Should be called only on symbols representing annotation type elements. |
|
713 |
*/ |
|
14802 | 714 |
protected void makeAnnotationTypeElementDoc(MethodSymbol meth, TreePath treePath) { |
10 | 715 |
AnnotationTypeElementDocImpl result = |
716 |
(AnnotationTypeElementDocImpl)methodMap.get(meth); |
|
717 |
if (result != null) { |
|
14802 | 718 |
if (treePath != null) result.setTreePath(treePath); |
10 | 719 |
} else { |
720 |
result = |
|
14802 | 721 |
new AnnotationTypeElementDocImpl(this, meth, treePath); |
10 | 722 |
methodMap.put(meth, result); |
723 |
} |
|
724 |
} |
|
725 |
||
726 |
/** |
|
727 |
* Return the AnnotationTypeElementDoc for a MethodSymbol. |
|
728 |
* Should be called only on symbols representing annotation type elements. |
|
729 |
*/ |
|
730 |
public AnnotationTypeElementDocImpl getAnnotationTypeElementDoc( |
|
731 |
MethodSymbol meth) { |
|
732 |
||
733 |
AnnotationTypeElementDocImpl result = |
|
734 |
(AnnotationTypeElementDocImpl)methodMap.get(meth); |
|
735 |
if (result != null) return result; |
|
736 |
result = new AnnotationTypeElementDocImpl(this, meth); |
|
737 |
methodMap.put(meth, result); |
|
738 |
return result; |
|
739 |
} |
|
740 |
||
741 |
// private Map<ClassType, ParameterizedTypeImpl> parameterizedTypeMap = |
|
742 |
// new HashMap<ClassType, ParameterizedTypeImpl>(); |
|
743 |
/** |
|
744 |
* Return the ParameterizedType of this instantiation. |
|
745 |
// * ### Could use Type.sameTypeAs() instead of equality matching in hashmap |
|
746 |
// * ### to avoid some duplication. |
|
747 |
*/ |
|
748 |
ParameterizedTypeImpl getParameterizedType(ClassType t) { |
|
749 |
return new ParameterizedTypeImpl(this, t); |
|
750 |
// ParameterizedTypeImpl result = parameterizedTypeMap.get(t); |
|
751 |
// if (result != null) return result; |
|
752 |
// result = new ParameterizedTypeImpl(this, t); |
|
753 |
// parameterizedTypeMap.put(t, result); |
|
754 |
// return result; |
|
755 |
} |
|
756 |
||
14802 | 757 |
TreePath getTreePath(JCCompilationUnit tree) { |
758 |
TreePath p = treePaths.get(tree); |
|
759 |
if (p == null) |
|
760 |
treePaths.put(tree, p = new TreePath(tree)); |
|
761 |
return p; |
|
762 |
} |
|
763 |
||
24069 | 764 |
TreePath getTreePath(JCCompilationUnit toplevel, JCPackageDecl tree) { |
765 |
TreePath p = treePaths.get(tree); |
|
766 |
if (p == null) |
|
767 |
treePaths.put(tree, p = new TreePath(getTreePath(toplevel), tree)); |
|
768 |
return p; |
|
769 |
} |
|
770 |
||
15354 | 771 |
TreePath getTreePath(JCCompilationUnit toplevel, JCClassDecl tree) { |
772 |
TreePath p = treePaths.get(tree); |
|
773 |
if (p == null) |
|
774 |
treePaths.put(tree, p = new TreePath(getTreePath(toplevel), tree)); |
|
775 |
return p; |
|
776 |
} |
|
777 |
||
778 |
TreePath getTreePath(JCCompilationUnit toplevel, JCClassDecl cdecl, JCTree tree) { |
|
779 |
return new TreePath(getTreePath(toplevel, cdecl), tree); |
|
14802 | 780 |
} |
781 |
||
10 | 782 |
/** |
783 |
* Set the encoding. |
|
784 |
*/ |
|
785 |
public void setEncoding(String encoding) { |
|
786 |
this.encoding = encoding; |
|
787 |
} |
|
788 |
||
789 |
/** |
|
790 |
* Get the encoding. |
|
791 |
*/ |
|
792 |
public String getEncoding() { |
|
793 |
return encoding; |
|
794 |
} |
|
795 |
||
796 |
/** |
|
797 |
* Convert modifier bits from private coding used by |
|
798 |
* the compiler to that of java.lang.reflect.Modifier. |
|
799 |
*/ |
|
800 |
static int translateModifiers(long flags) { |
|
801 |
int result = 0; |
|
802 |
if ((flags & Flags.ABSTRACT) != 0) |
|
803 |
result |= Modifier.ABSTRACT; |
|
804 |
if ((flags & Flags.FINAL) != 0) |
|
805 |
result |= Modifier.FINAL; |
|
806 |
if ((flags & Flags.INTERFACE) != 0) |
|
807 |
result |= Modifier.INTERFACE; |
|
808 |
if ((flags & Flags.NATIVE) != 0) |
|
809 |
result |= Modifier.NATIVE; |
|
810 |
if ((flags & Flags.PRIVATE) != 0) |
|
811 |
result |= Modifier.PRIVATE; |
|
812 |
if ((flags & Flags.PROTECTED) != 0) |
|
813 |
result |= Modifier.PROTECTED; |
|
814 |
if ((flags & Flags.PUBLIC) != 0) |
|
815 |
result |= Modifier.PUBLIC; |
|
816 |
if ((flags & Flags.STATIC) != 0) |
|
817 |
result |= Modifier.STATIC; |
|
818 |
if ((flags & Flags.SYNCHRONIZED) != 0) |
|
819 |
result |= Modifier.SYNCHRONIZED; |
|
820 |
if ((flags & Flags.TRANSIENT) != 0) |
|
821 |
result |= Modifier.TRANSIENT; |
|
822 |
if ((flags & Flags.VOLATILE) != 0) |
|
823 |
result |= Modifier.VOLATILE; |
|
824 |
return result; |
|
825 |
} |
|
15354 | 826 |
|
29957
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
827 |
void initDoclint(Collection<String> opts, Collection<String> customTagNames, String htmlVersion) { |
22163 | 828 |
ArrayList<String> doclintOpts = new ArrayList<>(); |
31752 | 829 |
boolean msgOptionSeen = false; |
15354 | 830 |
|
31752 | 831 |
for (String opt : opts) { |
832 |
if (opt.startsWith(DocLint.XMSGS_OPTION)) { |
|
833 |
if (opt.equals(DocLint.XMSGS_CUSTOM_PREFIX + "none")) |
|
834 |
return; |
|
835 |
msgOptionSeen = true; |
|
836 |
} |
|
837 |
doclintOpts.add(opt); |
|
15354 | 838 |
} |
839 |
||
31752 | 840 |
if (!msgOptionSeen) { |
15713 | 841 |
doclintOpts.add(DocLint.XMSGS_OPTION); |
15354 | 842 |
} |
843 |
||
21500
475e59d3b40c
8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents:
19912
diff
changeset
|
844 |
String sep = ""; |
475e59d3b40c
8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents:
19912
diff
changeset
|
845 |
StringBuilder customTags = new StringBuilder(); |
475e59d3b40c
8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents:
19912
diff
changeset
|
846 |
for (String customTag : customTagNames) { |
475e59d3b40c
8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents:
19912
diff
changeset
|
847 |
customTags.append(sep); |
475e59d3b40c
8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents:
19912
diff
changeset
|
848 |
customTags.append(customTag); |
29427
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
25874
diff
changeset
|
849 |
sep = DocLint.SEPARATOR; |
21500
475e59d3b40c
8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents:
19912
diff
changeset
|
850 |
} |
475e59d3b40c
8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents:
19912
diff
changeset
|
851 |
doclintOpts.add(DocLint.XCUSTOM_TAGS_PREFIX + customTags.toString()); |
29957
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
852 |
doclintOpts.add(DocLint.XHTML_VERSION_PREFIX + htmlVersion); |
21500
475e59d3b40c
8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents:
19912
diff
changeset
|
853 |
|
15354 | 854 |
JavacTask t = BasicJavacTask.instance(context); |
855 |
doclint = new DocLint(); |
|
16799
fbe4d27b8791
8006346: doclint should make allowance for headers generated by standard doclet
jjg
parents:
15713
diff
changeset
|
856 |
// standard doclet normally generates H1, H2 |
fbe4d27b8791
8006346: doclint should make allowance for headers generated by standard doclet
jjg
parents:
15713
diff
changeset
|
857 |
doclintOpts.add(DocLint.XIMPLICIT_HEADERS + "2"); |
15354 | 858 |
doclint.init(t, doclintOpts.toArray(new String[doclintOpts.size()]), false); |
859 |
} |
|
860 |
||
861 |
boolean showTagMessages() { |
|
862 |
return (doclint == null); |
|
863 |
} |
|
31752 | 864 |
|
865 |
Map<CompilationUnitTree, Boolean> shouldCheck = new HashMap<>(); |
|
866 |
||
867 |
boolean shouldCheck(CompilationUnitTree unit) { |
|
868 |
return shouldCheck.computeIfAbsent(unit, doclint :: shouldCheck); |
|
869 |
} |
|
10 | 870 |
} |