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