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