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