author | ksrini |
Thu, 30 Nov 2017 04:43:09 -0800 | |
changeset 48028 | 9e022f580a9d |
parent 47216 | 71c04702a3d5 |
child 48344 | 89f6aa26fd6c |
permissions | -rw-r--r-- |
15553 | 1 |
/* |
46184
f1325703ea85
8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents:
42831
diff
changeset
|
2 |
* Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved. |
15553 | 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 |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
23 |
||
24904 | 24 |
/* @test |
25291 | 25 |
* @bug 8043484 8007307 |
24904 | 26 |
* @summary Make sure DPrinter.java compiles |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
29842
diff
changeset
|
27 |
* @modules jdk.compiler/com.sun.tools.javac.api |
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
29842
diff
changeset
|
28 |
* jdk.compiler/com.sun.tools.javac.code |
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
29842
diff
changeset
|
29 |
* jdk.compiler/com.sun.tools.javac.tree |
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
29842
diff
changeset
|
30 |
* jdk.compiler/com.sun.tools.javac.util |
24904 | 31 |
* @compile DPrinter.java |
32 |
*/ |
|
33 |
||
15553 | 34 |
import java.io.File; |
35 |
import java.io.IOException; |
|
36 |
import java.io.PrintWriter; |
|
37 |
import java.lang.reflect.Field; |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
38 |
import java.lang.reflect.Method; |
15553 | 39 |
import java.util.ArrayList; |
40 |
import java.util.Arrays; |
|
41 |
import java.util.Collection; |
|
42 |
import java.util.EnumSet; |
|
43 |
import java.util.HashMap; |
|
44 |
import java.util.List; |
|
45 |
import java.util.Locale; |
|
46 |
import java.util.Map; |
|
47 |
import java.util.Set; |
|
48 |
||
49 |
import javax.lang.model.element.Name; |
|
50 |
import javax.lang.model.element.TypeElement; |
|
51 |
import javax.tools.FileObject; |
|
52 |
import javax.tools.JavaCompiler; |
|
53 |
import javax.tools.JavaFileObject; |
|
54 |
import javax.tools.StandardJavaFileManager; |
|
55 |
import javax.tools.StandardLocation; |
|
56 |
import javax.tools.ToolProvider; |
|
57 |
||
25291 | 58 |
import com.sun.source.doctree.*; |
15553 | 59 |
import com.sun.source.util.JavacTask; |
60 |
import com.sun.source.util.TaskEvent; |
|
61 |
import com.sun.source.util.TaskListener; |
|
62 |
import com.sun.source.util.Trees; |
|
63 |
import com.sun.tools.javac.api.JavacTrees; |
|
19928
adce50c2b76c
8022260: Rename javac.code.Annotations to javac.code.SymbolMetadata
jfranck
parents:
18010
diff
changeset
|
64 |
import com.sun.tools.javac.code.SymbolMetadata; |
15553 | 65 |
import com.sun.tools.javac.code.Attribute; |
66 |
import com.sun.tools.javac.code.Flags; |
|
67 |
import com.sun.tools.javac.code.Kinds; |
|
68 |
import com.sun.tools.javac.code.Printer; |
|
69 |
import com.sun.tools.javac.code.Scope; |
|
70 |
import com.sun.tools.javac.code.Scope.CompoundScope; |
|
71 |
import com.sun.tools.javac.code.Symbol; |
|
72 |
import com.sun.tools.javac.code.Symbol.*; |
|
73 |
import com.sun.tools.javac.code.Type; |
|
74 |
import com.sun.tools.javac.code.Type.*; |
|
75 |
import com.sun.tools.javac.code.TypeTag; |
|
76 |
import com.sun.tools.javac.tree.JCTree; |
|
77 |
import com.sun.tools.javac.tree.JCTree.*; |
|
78 |
import com.sun.tools.javac.tree.Pretty; |
|
79 |
import com.sun.tools.javac.tree.TreeInfo; |
|
80 |
import com.sun.tools.javac.tree.TreeScanner; |
|
81 |
import com.sun.tools.javac.util.Assert; |
|
82 |
import com.sun.tools.javac.util.Context; |
|
25291 | 83 |
import com.sun.tools.javac.util.Convert; |
15553 | 84 |
import com.sun.tools.javac.util.Log; |
85 |
||
86 |
||
87 |
/** |
|
88 |
* Debug printer for javac internals, for when toString() just isn't enough. |
|
89 |
* |
|
90 |
* <p> |
|
91 |
* The printer provides an API to generate structured views of javac objects, |
|
92 |
* such as AST nodes, symbol, types and annotations. Various aspects of the |
|
93 |
* output can be configured, such as whether to show nulls, empty lists, or |
|
94 |
* a compressed representation of the source code. Visitors are used to walk |
|
95 |
* object hierarchies, and can be replaced with custom visitors if the default |
|
96 |
* visitors are not flexible enough. |
|
97 |
* |
|
98 |
* <p> |
|
99 |
* In general, nodes are printed with an initial line identifying the node |
|
100 |
* followed by indented lines for the child nodes. Currently, graphs are |
|
101 |
* represented by printing a spanning subtree. |
|
102 |
* |
|
103 |
* <p> |
|
104 |
* The printer can be accessed via a simple command-line utility, |
|
105 |
* which makes it easy to see the internal representation of source code, |
|
106 |
* such as simple test programs, during the compilation pipeline. |
|
107 |
* |
|
108 |
* <p><b>This is NOT part of any supported API. |
|
109 |
* If you write code that depends on this, you do so at your own risk. |
|
110 |
* This code and its internal interfaces are subject to change or |
|
111 |
* deletion without notice.</b> |
|
112 |
*/ |
|
113 |
||
114 |
public class DPrinter { |
|
115 |
protected final PrintWriter out; |
|
116 |
protected final Trees trees; |
|
117 |
protected Printer printer; |
|
118 |
protected boolean showEmptyItems = true; |
|
119 |
protected boolean showNulls = true; |
|
120 |
protected boolean showPositions = false; |
|
121 |
protected boolean showSrc; |
|
122 |
protected boolean showTreeSymbols; |
|
123 |
protected boolean showTreeTypes; |
|
124 |
protected int maxSrcLength = 32; |
|
125 |
protected Locale locale = Locale.getDefault(); |
|
126 |
protected static final String NULL = "#null"; |
|
127 |
||
128 |
// <editor-fold defaultstate="collapsed" desc="Configuration"> |
|
129 |
||
130 |
public static DPrinter instance(Context context) { |
|
131 |
DPrinter dp = context.get(DPrinter.class); |
|
132 |
if (dp == null) { |
|
133 |
dp = new DPrinter(context); |
|
134 |
} |
|
135 |
return dp; |
|
136 |
||
137 |
} |
|
138 |
||
139 |
protected DPrinter(Context context) { |
|
140 |
context.put(DPrinter.class, this); |
|
40232
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
37009
diff
changeset
|
141 |
out = context.get(Log.logKey).getWriter(Log.WriterKind.STDERR); |
15553 | 142 |
trees = JavacTrees.instance(context); |
143 |
} |
|
144 |
||
145 |
public DPrinter(PrintWriter out, Trees trees) { |
|
146 |
this.out = out; |
|
147 |
this.trees = trees; |
|
148 |
} |
|
149 |
||
150 |
public DPrinter emptyItems(boolean showEmptyItems) { |
|
151 |
this.showEmptyItems = showEmptyItems; |
|
152 |
return this; |
|
153 |
} |
|
154 |
||
155 |
public DPrinter nulls(boolean showNulls) { |
|
156 |
this.showNulls = showNulls; |
|
157 |
return this; |
|
158 |
} |
|
159 |
||
160 |
public DPrinter positions(boolean showPositions) { |
|
161 |
this.showPositions = showPositions; |
|
162 |
return this; |
|
163 |
} |
|
164 |
||
165 |
public DPrinter source(boolean showSrc) { |
|
166 |
this.showSrc = showSrc; |
|
167 |
return this; |
|
168 |
} |
|
169 |
||
170 |
public DPrinter source(int maxSrcLength) { |
|
171 |
this.showSrc = true; |
|
172 |
this.maxSrcLength = maxSrcLength; |
|
173 |
return this; |
|
174 |
} |
|
175 |
||
176 |
public DPrinter treeSymbols(boolean showTreeSymbols) { |
|
177 |
this.showTreeSymbols = showTreeSymbols; |
|
178 |
return this; |
|
179 |
} |
|
180 |
||
181 |
public DPrinter treeTypes(boolean showTreeTypes) { |
|
182 |
this.showTreeTypes = showTreeTypes; |
|
183 |
return this; |
|
184 |
} |
|
185 |
||
186 |
public DPrinter typeSymbolPrinter(Printer p) { |
|
187 |
printer = p; |
|
188 |
return this; |
|
189 |
} |
|
190 |
||
191 |
// </editor-fold> |
|
192 |
||
193 |
// <editor-fold defaultstate="collapsed" desc="Printing"> |
|
194 |
||
195 |
protected enum Details { |
|
196 |
/** A one-line non-recursive summary */ |
|
197 |
SUMMARY, |
|
198 |
/** Multi-line, possibly recursive. */ |
|
199 |
FULL |
|
200 |
}; |
|
201 |
||
19928
adce50c2b76c
8022260: Rename javac.code.Annotations to javac.code.SymbolMetadata
jfranck
parents:
18010
diff
changeset
|
202 |
public void printAnnotations(String label, SymbolMetadata annotations) { |
15553 | 203 |
printAnnotations(label, annotations, Details.FULL); |
204 |
} |
|
205 |
||
19928
adce50c2b76c
8022260: Rename javac.code.Annotations to javac.code.SymbolMetadata
jfranck
parents:
18010
diff
changeset
|
206 |
protected void printAnnotations(String label, SymbolMetadata annotations, Details details) { |
15553 | 207 |
if (annotations == null) { |
208 |
printNull(label); |
|
209 |
} else { |
|
210 |
// no SUMMARY format currently available to use |
|
211 |
||
212 |
// use reflection to get at private fields |
|
19928
adce50c2b76c
8022260: Rename javac.code.Annotations to javac.code.SymbolMetadata
jfranck
parents:
18010
diff
changeset
|
213 |
Object DECL_NOT_STARTED = getField(null, SymbolMetadata.class, "DECL_NOT_STARTED"); |
adce50c2b76c
8022260: Rename javac.code.Annotations to javac.code.SymbolMetadata
jfranck
parents:
18010
diff
changeset
|
214 |
Object DECL_IN_PROGRESS = getField(null, SymbolMetadata.class, "DECL_IN_PROGRESS"); |
adce50c2b76c
8022260: Rename javac.code.Annotations to javac.code.SymbolMetadata
jfranck
parents:
18010
diff
changeset
|
215 |
Object attributes = getField(annotations, SymbolMetadata.class, "attributes"); |
adce50c2b76c
8022260: Rename javac.code.Annotations to javac.code.SymbolMetadata
jfranck
parents:
18010
diff
changeset
|
216 |
Object type_attributes = getField(annotations, SymbolMetadata.class, "type_attributes"); |
15553 | 217 |
|
218 |
if (!showEmptyItems) { |
|
219 |
if (attributes instanceof List && ((List) attributes).isEmpty() |
|
220 |
&& attributes != DECL_NOT_STARTED |
|
221 |
&& attributes != DECL_IN_PROGRESS |
|
222 |
&& type_attributes instanceof List && ((List) type_attributes).isEmpty()) |
|
223 |
return; |
|
224 |
} |
|
225 |
||
15560
d0509841a622
8007306: DPrinter: improve display of impl-class, internal tag/kind, and external tag/kind
jjg
parents:
15553
diff
changeset
|
226 |
printString(label, hashString(annotations)); |
15553 | 227 |
|
228 |
indent(+1); |
|
229 |
if (attributes == DECL_NOT_STARTED) |
|
230 |
printString("attributes", "DECL_NOT_STARTED"); |
|
231 |
else if (attributes == DECL_IN_PROGRESS) |
|
232 |
printString("attributes", "DECL_IN_PROGRESS"); |
|
233 |
else if (attributes instanceof List) |
|
234 |
printList("attributes", (List) attributes); |
|
235 |
else |
|
236 |
printObject("attributes", attributes, Details.SUMMARY); |
|
237 |
||
238 |
if (attributes instanceof List) |
|
239 |
printList("type_attributes", (List) type_attributes); |
|
240 |
else |
|
241 |
printObject("type_attributes", type_attributes, Details.SUMMARY); |
|
242 |
indent(-1); |
|
243 |
} |
|
244 |
} |
|
245 |
||
246 |
public void printAttribute(String label, Attribute attr) { |
|
247 |
if (attr == null) { |
|
248 |
printNull(label); |
|
249 |
} else { |
|
250 |
printString(label, attr.getClass().getSimpleName()); |
|
251 |
||
252 |
indent(+1); |
|
253 |
attr.accept(attrVisitor); |
|
254 |
indent(-1); |
|
255 |
} |
|
256 |
} |
|
257 |
||
25291 | 258 |
public void printDocTree(String label, DocTree tree) { |
259 |
if (tree == null) { |
|
260 |
printNull(label); |
|
261 |
} else { |
|
262 |
indent(); |
|
263 |
out.print(label); |
|
264 |
out.println(": " + tree.getClass().getSimpleName() + "," + tree.getKind()); |
|
265 |
||
266 |
indent(+1); |
|
267 |
tree.accept(docTreeVisitor, null); |
|
268 |
indent(-1); |
|
269 |
} |
|
270 |
} |
|
271 |
||
15553 | 272 |
public void printFileObject(String label, FileObject fo) { |
273 |
if (fo == null) { |
|
274 |
printNull(label); |
|
275 |
} else { |
|
276 |
printString(label, fo.getName()); |
|
277 |
} |
|
278 |
} |
|
279 |
||
280 |
protected <T> void printImplClass(T item, Class<? extends T> stdImplClass) { |
|
281 |
if (item.getClass() != stdImplClass) |
|
282 |
printString("impl", item.getClass().getName()); |
|
283 |
} |
|
284 |
||
285 |
public void printInt(String label, int i) { |
|
286 |
printString(label, String.valueOf(i)); |
|
287 |
} |
|
288 |
||
25291 | 289 |
public void printLimitedEscapedString(String label, String text) { |
290 |
String s = Convert.quote(text); |
|
291 |
if (s.length() > maxSrcLength) { |
|
292 |
String trim = "[...]"; |
|
293 |
int head = (maxSrcLength - trim.length()) * 2 / 3; |
|
294 |
int tail = maxSrcLength - trim.length() - head; |
|
295 |
s = s.substring(0, head) + trim + s.substring(s.length() - tail); |
|
296 |
} |
|
297 |
printString(label, s); |
|
298 |
} |
|
299 |
||
15553 | 300 |
public void printList(String label, List<?> list) { |
301 |
if (list == null) { |
|
302 |
printNull(label); |
|
303 |
} else if (!list.isEmpty() || showEmptyItems) { |
|
304 |
printString(label, "[" + list.size() + "]"); |
|
305 |
||
306 |
indent(+1); |
|
307 |
int i = 0; |
|
308 |
for (Object item: list) { |
|
309 |
printObject(String.valueOf(i++), item, Details.FULL); |
|
310 |
} |
|
311 |
indent(-1); |
|
312 |
} |
|
313 |
} |
|
314 |
||
315 |
public void printName(String label, Name name) { |
|
316 |
if (name == null) { |
|
317 |
printNull(label); |
|
318 |
} else { |
|
319 |
printString(label, name.toString()); |
|
320 |
} |
|
321 |
} |
|
322 |
||
323 |
public void printNull(String label) { |
|
324 |
if (showNulls) |
|
325 |
printString(label, NULL); |
|
326 |
} |
|
327 |
||
328 |
protected void printObject(String label, Object item, Details details) { |
|
329 |
if (item == null) { |
|
330 |
printNull(label); |
|
331 |
} else if (item instanceof Attribute) { |
|
332 |
printAttribute(label, (Attribute) item); |
|
333 |
} else if (item instanceof Symbol) { |
|
334 |
printSymbol(label, (Symbol) item, details); |
|
335 |
} else if (item instanceof Type) { |
|
336 |
printType(label, (Type) item, details); |
|
337 |
} else if (item instanceof JCTree) { |
|
338 |
printTree(label, (JCTree) item); |
|
25291 | 339 |
} else if (item instanceof DocTree) { |
340 |
printDocTree(label, (DocTree) item); |
|
15553 | 341 |
} else if (item instanceof List) { |
342 |
printList(label, (List) item); |
|
343 |
} else if (item instanceof Name) { |
|
344 |
printName(label, (Name) item); |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
345 |
} else if (item instanceof Scope) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
346 |
printScope(label, (Scope) item); |
15553 | 347 |
} else { |
348 |
printString(label, String.valueOf(item)); |
|
349 |
} |
|
350 |
} |
|
351 |
||
352 |
public void printScope(String label, Scope scope) { |
|
353 |
printScope(label, scope, Details.FULL); |
|
354 |
} |
|
355 |
||
356 |
public void printScope(String label, Scope scope, Details details) { |
|
357 |
if (scope == null) { |
|
358 |
printNull(label); |
|
359 |
} else { |
|
360 |
switch (details) { |
|
361 |
case SUMMARY: { |
|
362 |
indent(); |
|
363 |
out.print(label); |
|
364 |
out.print(": ["); |
|
365 |
String sep = ""; |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
366 |
for (Symbol sym: scope.getSymbols()) { |
15553 | 367 |
out.print(sep); |
368 |
out.print(sym.name); |
|
369 |
sep = ","; |
|
370 |
} |
|
371 |
out.println("]"); |
|
372 |
break; |
|
373 |
} |
|
374 |
||
375 |
case FULL: { |
|
376 |
indent(); |
|
377 |
out.println(label); |
|
378 |
||
379 |
indent(+1); |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
380 |
printFullScopeImpl(scope); |
15553 | 381 |
indent(-1); |
382 |
break; |
|
383 |
} |
|
384 |
} |
|
385 |
} |
|
386 |
} |
|
387 |
||
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
388 |
void printFullScopeImpl(Scope scope) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
389 |
indent(); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
390 |
out.println(scope.getClass().getName()); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
391 |
printSymbol("owner", scope.owner, Details.SUMMARY); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
392 |
if (SCOPE_IMPL_CLASS.equals(scope.getClass().getName())) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
393 |
printScope("next", (Scope) getField(scope, scope.getClass(), "next"), Details.SUMMARY); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
394 |
printObject("shared", getField(scope, scope.getClass(), "shared"), Details.SUMMARY); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
395 |
Object[] table = (Object[]) getField(scope, scope.getClass(), "table"); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
396 |
for (int i = 0; i < table.length; i++) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
397 |
if (i > 0) |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
398 |
out.print(", "); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
399 |
else |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
400 |
indent(); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
401 |
out.print(i + ":" + entryToString(table[i], table, false)); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
402 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
403 |
out.println(); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
404 |
} else if (FILTER_SCOPE_CLASS.equals(scope.getClass().getName())) { |
27857 | 405 |
printScope("origin", |
406 |
(Scope) getField(scope, scope.getClass(), "origin"), Details.FULL); |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
407 |
} else if (scope instanceof CompoundScope) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
408 |
printList("delegates", (List<?>) getField(scope, CompoundScope.class, "subScopes")); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
409 |
} else { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
410 |
for (Symbol sym : scope.getSymbols()) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
411 |
printSymbol(sym.name.toString(), sym, Details.SUMMARY); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
412 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
413 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
414 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
415 |
//where: |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
416 |
static final String SCOPE_IMPL_CLASS = "com.sun.tools.javac.code.Scope$ScopeImpl"; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
417 |
static final String FILTER_SCOPE_CLASS = "com.sun.tools.javac.code.Scope$FilterImportScope"; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
418 |
|
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
419 |
/** |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
420 |
* Create a string showing the contents of an entry, using the table |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
421 |
* to help identify cross-references to other entries in the table. |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
422 |
* @param e the entry to be shown |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
423 |
* @param table the table containing the other entries |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
424 |
*/ |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
425 |
String entryToString(Object e, Object[] table, boolean ref) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
426 |
if (e == null) |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
427 |
return "null"; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
428 |
Symbol sym = (Symbol) getField(e, e.getClass(), "sym"); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
429 |
if (sym == null) |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
430 |
return "sent"; // sentinel |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
431 |
if (ref) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
432 |
int index = indexOf(table, e); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
433 |
if (index != -1) |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
434 |
return String.valueOf(index); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
435 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
436 |
Scope scope = (Scope) getField(e, e.getClass(), "scope"); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
437 |
return "(" + sym.name + ":" + sym |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
438 |
+ ",shdw:" + entryToString(callMethod(e, e.getClass(), "next"), table, true) |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
439 |
+ ",sibl:" + entryToString(getField(e, e.getClass(), "sibling"), table, true) |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
440 |
+ ((sym.owner != scope.owner) |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
441 |
? (",BOGUS[" + sym.owner + "," + scope.owner + "]") |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
442 |
: "") |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
443 |
+ ")"; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
444 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
445 |
|
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
446 |
<T> int indexOf(T[] array, T item) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
447 |
for (int i = 0; i < array.length; i++) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
448 |
if (array[i] == item) |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
449 |
return i; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
450 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
451 |
return -1; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
452 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
453 |
|
15553 | 454 |
public void printSource(String label, JCTree tree) { |
455 |
printString(label, Pretty.toSimpleString(tree, maxSrcLength)); |
|
456 |
} |
|
457 |
||
458 |
public void printString(String label, String text) { |
|
459 |
indent(); |
|
460 |
out.print(label); |
|
461 |
out.print(": "); |
|
462 |
out.print(text); |
|
463 |
out.println(); |
|
464 |
} |
|
465 |
||
466 |
public void printSymbol(String label, Symbol symbol) { |
|
467 |
printSymbol(label, symbol, Details.FULL); |
|
468 |
} |
|
469 |
||
470 |
protected void printSymbol(String label, Symbol sym, Details details) { |
|
471 |
if (sym == null) { |
|
472 |
printNull(label); |
|
473 |
} else { |
|
474 |
switch (details) { |
|
475 |
case SUMMARY: |
|
476 |
printString(label, toString(sym)); |
|
477 |
break; |
|
478 |
||
479 |
case FULL: |
|
480 |
indent(); |
|
481 |
out.print(label); |
|
15560
d0509841a622
8007306: DPrinter: improve display of impl-class, internal tag/kind, and external tag/kind
jjg
parents:
15553
diff
changeset
|
482 |
out.println(": " + |
d0509841a622
8007306: DPrinter: improve display of impl-class, internal tag/kind, and external tag/kind
jjg
parents:
15553
diff
changeset
|
483 |
info(sym.getClass(), |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27857
diff
changeset
|
484 |
String.format("0x%x--%s", sym.kind.ordinal(), Kinds.kindName(sym)), |
15560
d0509841a622
8007306: DPrinter: improve display of impl-class, internal tag/kind, and external tag/kind
jjg
parents:
15553
diff
changeset
|
485 |
sym.getKind()) |
15553 | 486 |
+ " " + sym.name |
15560
d0509841a622
8007306: DPrinter: improve display of impl-class, internal tag/kind, and external tag/kind
jjg
parents:
15553
diff
changeset
|
487 |
+ " " + hashString(sym)); |
15553 | 488 |
|
489 |
indent(+1); |
|
490 |
if (showSrc) { |
|
491 |
JCTree tree = (JCTree) trees.getTree(sym); |
|
492 |
if (tree != null) |
|
493 |
printSource("src", tree); |
|
494 |
} |
|
495 |
printString("flags", String.format("0x%x--%s", |
|
496 |
sym.flags_field, Flags.toString(sym.flags_field))); |
|
497 |
printObject("completer", sym.completer, Details.SUMMARY); // what if too long? |
|
498 |
printSymbol("owner", sym.owner, Details.SUMMARY); |
|
499 |
printType("type", sym.type, Details.SUMMARY); |
|
500 |
printType("erasure", sym.erasure_field, Details.SUMMARY); |
|
15560
d0509841a622
8007306: DPrinter: improve display of impl-class, internal tag/kind, and external tag/kind
jjg
parents:
15553
diff
changeset
|
501 |
sym.accept(symVisitor, null); |
24904 | 502 |
printAnnotations("annotations", sym.getMetadata(), Details.SUMMARY); |
15553 | 503 |
indent(-1); |
504 |
} |
|
505 |
} |
|
506 |
} |
|
507 |
||
508 |
protected String toString(Symbol sym) { |
|
509 |
return (printer != null) ? printer.visit(sym, locale) : String.valueOf(sym); |
|
510 |
} |
|
511 |
||
512 |
protected void printTree(String label, JCTree tree) { |
|
513 |
if (tree == null) { |
|
514 |
printNull(label); |
|
515 |
} else { |
|
516 |
indent(); |
|
15560
d0509841a622
8007306: DPrinter: improve display of impl-class, internal tag/kind, and external tag/kind
jjg
parents:
15553
diff
changeset
|
517 |
String ext; |
d0509841a622
8007306: DPrinter: improve display of impl-class, internal tag/kind, and external tag/kind
jjg
parents:
15553
diff
changeset
|
518 |
try { |
d0509841a622
8007306: DPrinter: improve display of impl-class, internal tag/kind, and external tag/kind
jjg
parents:
15553
diff
changeset
|
519 |
ext = tree.getKind().name(); |
d0509841a622
8007306: DPrinter: improve display of impl-class, internal tag/kind, and external tag/kind
jjg
parents:
15553
diff
changeset
|
520 |
} catch (Throwable t) { |
d0509841a622
8007306: DPrinter: improve display of impl-class, internal tag/kind, and external tag/kind
jjg
parents:
15553
diff
changeset
|
521 |
ext = "n/a"; |
d0509841a622
8007306: DPrinter: improve display of impl-class, internal tag/kind, and external tag/kind
jjg
parents:
15553
diff
changeset
|
522 |
} |
d0509841a622
8007306: DPrinter: improve display of impl-class, internal tag/kind, and external tag/kind
jjg
parents:
15553
diff
changeset
|
523 |
out.print(label + ": " + info(tree.getClass(), tree.getTag(), ext)); |
15553 | 524 |
if (showPositions) { |
525 |
// We can always get start position, but to get end position |
|
526 |
// and/or line+offset, we would need a JCCompilationUnit |
|
527 |
out.print(" pos:" + tree.pos); |
|
528 |
} |
|
529 |
if (showTreeTypes && tree.type != null) |
|
530 |
out.print(" type:" + toString(tree.type)); |
|
531 |
Symbol sym; |
|
532 |
if (showTreeSymbols && (sym = TreeInfo.symbolFor(tree)) != null) |
|
533 |
out.print(" sym:" + toString(sym)); |
|
534 |
out.println(); |
|
535 |
||
536 |
indent(+1); |
|
537 |
if (showSrc) { |
|
538 |
indent(); |
|
539 |
out.println("src: " + Pretty.toSimpleString(tree, maxSrcLength)); |
|
540 |
} |
|
541 |
tree.accept(treeVisitor); |
|
542 |
indent(-1); |
|
543 |
} |
|
544 |
} |
|
545 |
||
546 |
public void printType(String label, Type type) { |
|
547 |
printType(label, type, Details.FULL); |
|
548 |
} |
|
549 |
||
550 |
protected void printType(String label, Type type, Details details) { |
|
551 |
if (type == null) |
|
552 |
printNull(label); |
|
553 |
else { |
|
554 |
switch (details) { |
|
555 |
case SUMMARY: |
|
556 |
printString(label, toString(type)); |
|
557 |
break; |
|
558 |
||
559 |
case FULL: |
|
560 |
indent(); |
|
561 |
out.print(label); |
|
15560
d0509841a622
8007306: DPrinter: improve display of impl-class, internal tag/kind, and external tag/kind
jjg
parents:
15553
diff
changeset
|
562 |
out.println(": " + info(type.getClass(), type.getTag(), type.getKind()) |
d0509841a622
8007306: DPrinter: improve display of impl-class, internal tag/kind, and external tag/kind
jjg
parents:
15553
diff
changeset
|
563 |
+ " " + hashString(type)); |
15553 | 564 |
|
565 |
indent(+1); |
|
566 |
printSymbol("tsym", type.tsym, Details.SUMMARY); |
|
567 |
printObject("constValue", type.constValue(), Details.SUMMARY); |
|
17578 | 568 |
printObject("annotations", type.getAnnotationMirrors(), Details.SUMMARY); |
15560
d0509841a622
8007306: DPrinter: improve display of impl-class, internal tag/kind, and external tag/kind
jjg
parents:
15553
diff
changeset
|
569 |
type.accept(typeVisitor, null); |
15553 | 570 |
indent(-1); |
571 |
} |
|
572 |
} |
|
573 |
} |
|
574 |
||
575 |
protected String toString(Type type) { |
|
576 |
return (printer != null) ? printer.visit(type, locale) : String.valueOf(type); |
|
577 |
} |
|
578 |
||
15560
d0509841a622
8007306: DPrinter: improve display of impl-class, internal tag/kind, and external tag/kind
jjg
parents:
15553
diff
changeset
|
579 |
protected String hashString(Object obj) { |
d0509841a622
8007306: DPrinter: improve display of impl-class, internal tag/kind, and external tag/kind
jjg
parents:
15553
diff
changeset
|
580 |
return String.format("#%x", obj.hashCode()); |
d0509841a622
8007306: DPrinter: improve display of impl-class, internal tag/kind, and external tag/kind
jjg
parents:
15553
diff
changeset
|
581 |
} |
d0509841a622
8007306: DPrinter: improve display of impl-class, internal tag/kind, and external tag/kind
jjg
parents:
15553
diff
changeset
|
582 |
|
d0509841a622
8007306: DPrinter: improve display of impl-class, internal tag/kind, and external tag/kind
jjg
parents:
15553
diff
changeset
|
583 |
protected String info(Class<?> clazz, Object internal, Object external) { |
d0509841a622
8007306: DPrinter: improve display of impl-class, internal tag/kind, and external tag/kind
jjg
parents:
15553
diff
changeset
|
584 |
return String.format("%s,%s,%s", clazz.getSimpleName(), internal, external); |
d0509841a622
8007306: DPrinter: improve display of impl-class, internal tag/kind, and external tag/kind
jjg
parents:
15553
diff
changeset
|
585 |
} |
d0509841a622
8007306: DPrinter: improve display of impl-class, internal tag/kind, and external tag/kind
jjg
parents:
15553
diff
changeset
|
586 |
|
15553 | 587 |
private int indent = 0; |
588 |
||
589 |
protected void indent() { |
|
590 |
for (int i = 0; i < indent; i++) { |
|
591 |
out.print(" "); |
|
592 |
} |
|
593 |
} |
|
594 |
||
595 |
protected void indent(int n) { |
|
596 |
indent += n; |
|
597 |
} |
|
598 |
||
599 |
protected Object getField(Object o, Class<?> clazz, String name) { |
|
600 |
try { |
|
601 |
Field f = clazz.getDeclaredField(name); |
|
602 |
boolean prev = f.isAccessible(); |
|
603 |
f.setAccessible(true); |
|
604 |
try { |
|
605 |
return f.get(o); |
|
606 |
} finally { |
|
607 |
f.setAccessible(prev); |
|
608 |
} |
|
609 |
} catch (ReflectiveOperationException e) { |
|
610 |
return e; |
|
611 |
} catch (SecurityException e) { |
|
612 |
return e; |
|
613 |
} |
|
614 |
} |
|
615 |
||
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
616 |
protected Object callMethod(Object o, Class<?> clazz, String name) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
617 |
try { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
618 |
Method m = clazz.getDeclaredMethod(name); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
619 |
boolean prev = m.isAccessible(); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
620 |
m.setAccessible(true); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
621 |
try { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
622 |
return m.invoke(o); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
623 |
} finally { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
624 |
m.setAccessible(prev); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
625 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
626 |
} catch (ReflectiveOperationException e) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
627 |
return e; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
628 |
} catch (SecurityException e) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
629 |
return e; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
630 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
631 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25291
diff
changeset
|
632 |
|
15553 | 633 |
// </editor-fold> |
634 |
||
635 |
// <editor-fold defaultstate="collapsed" desc="JCTree visitor methods"> |
|
636 |
||
637 |
protected JCTree.Visitor treeVisitor = new TreeVisitor(); |
|
638 |
||
639 |
/** |
|
640 |
* Default visitor class for JCTree (AST) objects. |
|
641 |
*/ |
|
642 |
public class TreeVisitor extends JCTree.Visitor { |
|
643 |
@Override |
|
644 |
public void visitTopLevel(JCCompilationUnit tree) { |
|
24904 | 645 |
printList("packageAnnotations", tree.getPackageAnnotations()); |
646 |
printList("defs", tree.defs); |
|
647 |
} |
|
648 |
||
649 |
@Override |
|
650 |
public void visitPackageDef(JCPackageDecl tree) { |
|
15553 | 651 |
printTree("pid", tree.pid); |
652 |
} |
|
653 |
||
654 |
@Override |
|
655 |
public void visitImport(JCImport tree) { |
|
656 |
printTree("qualid", tree.qualid); |
|
657 |
} |
|
658 |
||
659 |
@Override |
|
660 |
public void visitClassDef(JCClassDecl tree) { |
|
661 |
printName("name", tree.name); |
|
662 |
printTree("mods", tree.mods); |
|
663 |
printList("typarams", tree.typarams); |
|
664 |
printTree("extending", tree.extending); |
|
665 |
printList("implementing", tree.implementing); |
|
666 |
printList("defs", tree.defs); |
|
667 |
} |
|
668 |
||
669 |
@Override |
|
670 |
public void visitMethodDef(JCMethodDecl tree) { |
|
671 |
printName("name", tree.name); |
|
672 |
printTree("mods", tree.mods); |
|
673 |
printTree("restype", tree.restype); |
|
674 |
printList("typarams", tree.typarams); |
|
675 |
printTree("recvparam", tree.recvparam); |
|
676 |
printList("params", tree.params); |
|
677 |
printList("thrown", tree.thrown); |
|
678 |
printTree("defaultValue", tree.defaultValue); |
|
679 |
printTree("body", tree.body); |
|
680 |
} |
|
681 |
||
682 |
@Override |
|
683 |
public void visitVarDef(JCVariableDecl tree) { |
|
684 |
printName("name", tree.name); |
|
685 |
printTree("mods", tree.mods); |
|
686 |
printTree("vartype", tree.vartype); |
|
687 |
printTree("init", tree.init); |
|
688 |
} |
|
689 |
||
690 |
@Override |
|
691 |
public void visitSkip(JCSkip tree) { |
|
692 |
} |
|
693 |
||
694 |
@Override |
|
695 |
public void visitBlock(JCBlock tree) { |
|
696 |
printList("stats", tree.stats); |
|
697 |
} |
|
698 |
||
699 |
@Override |
|
700 |
public void visitDoLoop(JCDoWhileLoop tree) { |
|
701 |
printTree("body", tree.body); |
|
702 |
printTree("cond", tree.cond); |
|
703 |
} |
|
704 |
||
705 |
@Override |
|
706 |
public void visitWhileLoop(JCWhileLoop tree) { |
|
707 |
printTree("cond", tree.cond); |
|
708 |
printTree("body", tree.body); |
|
709 |
} |
|
710 |
||
711 |
@Override |
|
712 |
public void visitForLoop(JCForLoop tree) { |
|
713 |
printList("init", tree.init); |
|
714 |
printTree("cond", tree.cond); |
|
715 |
printList("step", tree.step); |
|
716 |
printTree("body", tree.body); |
|
717 |
} |
|
718 |
||
719 |
@Override |
|
720 |
public void visitForeachLoop(JCEnhancedForLoop tree) { |
|
721 |
printTree("var", tree.var); |
|
722 |
printTree("expr", tree.expr); |
|
723 |
printTree("body", tree.body); |
|
724 |
} |
|
725 |
||
726 |
@Override |
|
727 |
public void visitLabelled(JCLabeledStatement tree) { |
|
728 |
printTree("body", tree.body); |
|
729 |
} |
|
730 |
||
731 |
@Override |
|
732 |
public void visitSwitch(JCSwitch tree) { |
|
733 |
printTree("selector", tree.selector); |
|
734 |
printList("cases", tree.cases); |
|
735 |
} |
|
736 |
||
737 |
@Override |
|
738 |
public void visitCase(JCCase tree) { |
|
739 |
printTree("pat", tree.pat); |
|
740 |
printList("stats", tree.stats); |
|
741 |
} |
|
742 |
||
743 |
@Override |
|
744 |
public void visitSynchronized(JCSynchronized tree) { |
|
745 |
printTree("lock", tree.lock); |
|
746 |
printTree("body", tree.body); |
|
747 |
} |
|
748 |
||
749 |
@Override |
|
750 |
public void visitTry(JCTry tree) { |
|
751 |
printList("resources", tree.resources); |
|
752 |
printTree("body", tree.body); |
|
753 |
printList("catchers", tree.catchers); |
|
754 |
printTree("finalizer", tree.finalizer); |
|
755 |
} |
|
756 |
||
757 |
@Override |
|
758 |
public void visitCatch(JCCatch tree) { |
|
759 |
printTree("param", tree.param); |
|
760 |
printTree("body", tree.body); |
|
761 |
} |
|
762 |
||
763 |
@Override |
|
764 |
public void visitConditional(JCConditional tree) { |
|
765 |
printTree("cond", tree.cond); |
|
766 |
printTree("truepart", tree.truepart); |
|
767 |
printTree("falsepart", tree.falsepart); |
|
768 |
} |
|
769 |
||
770 |
@Override |
|
771 |
public void visitIf(JCIf tree) { |
|
772 |
printTree("cond", tree.cond); |
|
773 |
printTree("thenpart", tree.thenpart); |
|
774 |
printTree("elsepart", tree.elsepart); |
|
775 |
} |
|
776 |
||
777 |
@Override |
|
778 |
public void visitExec(JCExpressionStatement tree) { |
|
779 |
printTree("expr", tree.expr); |
|
780 |
} |
|
781 |
||
782 |
@Override |
|
783 |
public void visitBreak(JCBreak tree) { |
|
784 |
printName("label", tree.label); |
|
785 |
} |
|
786 |
||
787 |
@Override |
|
788 |
public void visitContinue(JCContinue tree) { |
|
789 |
printName("label", tree.label); |
|
790 |
} |
|
791 |
||
792 |
@Override |
|
793 |
public void visitReturn(JCReturn tree) { |
|
794 |
printTree("expr", tree.expr); |
|
795 |
} |
|
796 |
||
797 |
@Override |
|
798 |
public void visitThrow(JCThrow tree) { |
|
799 |
printTree("expr", tree.expr); |
|
800 |
} |
|
801 |
||
802 |
@Override |
|
803 |
public void visitAssert(JCAssert tree) { |
|
804 |
printTree("cond", tree.cond); |
|
805 |
printTree("detail", tree.detail); |
|
806 |
} |
|
807 |
||
808 |
@Override |
|
809 |
public void visitApply(JCMethodInvocation tree) { |
|
810 |
printList("typeargs", tree.typeargs); |
|
811 |
printTree("meth", tree.meth); |
|
812 |
printList("args", tree.args); |
|
813 |
} |
|
814 |
||
815 |
@Override |
|
816 |
public void visitNewClass(JCNewClass tree) { |
|
817 |
printTree("encl", tree.encl); |
|
818 |
printList("typeargs", tree.typeargs); |
|
819 |
printTree("clazz", tree.clazz); |
|
820 |
printList("args", tree.args); |
|
821 |
printTree("def", tree.def); |
|
822 |
} |
|
823 |
||
824 |
@Override |
|
825 |
public void visitNewArray(JCNewArray tree) { |
|
826 |
printList("annotations", tree.annotations); |
|
827 |
printTree("elemtype", tree.elemtype); |
|
828 |
printList("dims", tree.dims); |
|
829 |
printList("dimAnnotations", tree.dimAnnotations); |
|
830 |
printList("elems", tree.elems); |
|
831 |
} |
|
832 |
||
833 |
@Override |
|
834 |
public void visitLambda(JCLambda tree) { |
|
835 |
printTree("body", tree.body); |
|
836 |
printList("params", tree.params); |
|
837 |
} |
|
838 |
||
839 |
@Override |
|
840 |
public void visitParens(JCParens tree) { |
|
841 |
printTree("expr", tree.expr); |
|
842 |
} |
|
843 |
||
844 |
@Override |
|
845 |
public void visitAssign(JCAssign tree) { |
|
846 |
printTree("lhs", tree.lhs); |
|
847 |
printTree("rhs", tree.rhs); |
|
848 |
} |
|
849 |
||
850 |
@Override |
|
851 |
public void visitAssignop(JCAssignOp tree) { |
|
852 |
printTree("lhs", tree.lhs); |
|
853 |
printTree("rhs", tree.rhs); |
|
854 |
} |
|
855 |
||
856 |
@Override |
|
857 |
public void visitUnary(JCUnary tree) { |
|
858 |
printTree("arg", tree.arg); |
|
859 |
} |
|
860 |
||
861 |
@Override |
|
862 |
public void visitBinary(JCBinary tree) { |
|
863 |
printTree("lhs", tree.lhs); |
|
864 |
printTree("rhs", tree.rhs); |
|
865 |
} |
|
866 |
||
867 |
@Override |
|
868 |
public void visitTypeCast(JCTypeCast tree) { |
|
869 |
printTree("clazz", tree.clazz); |
|
870 |
printTree("expr", tree.expr); |
|
871 |
} |
|
872 |
||
873 |
@Override |
|
874 |
public void visitTypeTest(JCInstanceOf tree) { |
|
875 |
printTree("expr", tree.expr); |
|
876 |
printTree("clazz", tree.clazz); |
|
877 |
} |
|
878 |
||
879 |
@Override |
|
880 |
public void visitIndexed(JCArrayAccess tree) { |
|
881 |
printTree("indexed", tree.indexed); |
|
882 |
printTree("index", tree.index); |
|
883 |
} |
|
884 |
||
885 |
@Override |
|
886 |
public void visitSelect(JCFieldAccess tree) { |
|
887 |
printTree("selected", tree.selected); |
|
888 |
} |
|
889 |
||
890 |
@Override |
|
891 |
public void visitReference(JCMemberReference tree) { |
|
892 |
printTree("expr", tree.expr); |
|
893 |
printList("typeargs", tree.typeargs); |
|
894 |
} |
|
895 |
||
896 |
@Override |
|
897 |
public void visitIdent(JCIdent tree) { |
|
898 |
printName("name", tree.name); |
|
899 |
} |
|
900 |
||
901 |
@Override |
|
902 |
public void visitLiteral(JCLiteral tree) { |
|
903 |
printString("value", Pretty.toSimpleString(tree, 32)); |
|
904 |
} |
|
905 |
||
906 |
@Override |
|
907 |
public void visitTypeIdent(JCPrimitiveTypeTree tree) { |
|
908 |
printString("typetag", tree.typetag.name()); |
|
909 |
} |
|
910 |
||
911 |
@Override |
|
912 |
public void visitTypeArray(JCArrayTypeTree tree) { |
|
913 |
printTree("elemtype", tree.elemtype); |
|
914 |
} |
|
915 |
||
916 |
@Override |
|
917 |
public void visitTypeApply(JCTypeApply tree) { |
|
918 |
printTree("clazz", tree.clazz); |
|
919 |
printList("arguments", tree.arguments); |
|
920 |
} |
|
921 |
||
922 |
@Override |
|
923 |
public void visitTypeUnion(JCTypeUnion tree) { |
|
924 |
printList("alternatives", tree.alternatives); |
|
925 |
} |
|
926 |
||
927 |
@Override |
|
928 |
public void visitTypeIntersection(JCTypeIntersection tree) { |
|
929 |
printList("bounds", tree.bounds); |
|
930 |
} |
|
931 |
||
932 |
@Override |
|
933 |
public void visitTypeParameter(JCTypeParameter tree) { |
|
934 |
printName("name", tree.name); |
|
935 |
printList("annotations", tree.annotations); |
|
936 |
printList("bounds", tree.bounds); |
|
937 |
} |
|
938 |
||
939 |
@Override |
|
940 |
public void visitWildcard(JCWildcard tree) { |
|
941 |
printTree("kind", tree.kind); |
|
942 |
printTree("inner", tree.inner); |
|
943 |
} |
|
944 |
||
945 |
@Override |
|
946 |
public void visitTypeBoundKind(TypeBoundKind tree) { |
|
947 |
printString("kind", tree.kind.name()); |
|
948 |
} |
|
949 |
||
950 |
@Override |
|
951 |
public void visitModifiers(JCModifiers tree) { |
|
952 |
printList("annotations", tree.annotations); |
|
953 |
printString("flags", String.valueOf(Flags.asFlagSet(tree.flags))); |
|
954 |
} |
|
955 |
||
956 |
@Override |
|
957 |
public void visitAnnotation(JCAnnotation tree) { |
|
958 |
printTree("annotationType", tree.annotationType); |
|
959 |
printList("args", tree.args); |
|
960 |
} |
|
961 |
||
962 |
@Override |
|
963 |
public void visitAnnotatedType(JCAnnotatedType tree) { |
|
964 |
printList("annotations", tree.annotations); |
|
965 |
printTree("underlyingType", tree.underlyingType); |
|
966 |
} |
|
967 |
||
968 |
@Override |
|
969 |
public void visitErroneous(JCErroneous tree) { |
|
970 |
printList("errs", tree.errs); |
|
971 |
} |
|
972 |
||
973 |
@Override |
|
974 |
public void visitLetExpr(LetExpr tree) { |
|
975 |
printList("defs", tree.defs); |
|
976 |
printTree("expr", tree.expr); |
|
977 |
} |
|
978 |
||
979 |
@Override |
|
980 |
public void visitTree(JCTree tree) { |
|
981 |
Assert.error(); |
|
982 |
} |
|
983 |
} |
|
984 |
||
985 |
// </editor-fold> |
|
986 |
||
25291 | 987 |
// <editor-fold defaultstate="collapsed" desc="DocTree visitor"> |
988 |
||
989 |
protected DocTreeVisitor<Void,Void> docTreeVisitor = new DefaultDocTreeVisitor(); |
|
990 |
||
991 |
/** |
|
992 |
* Default visitor class for DocTree objects. |
|
993 |
* Note: each visitXYZ method ends by calling the corresponding |
|
994 |
* visit method for its superclass. |
|
995 |
*/ |
|
996 |
class DefaultDocTreeVisitor implements DocTreeVisitor<Void,Void> { |
|
997 |
||
998 |
public Void visitAttribute(AttributeTree node, Void p) { |
|
999 |
printName("name", node.getName()); |
|
1000 |
printString("vkind", node.getValueKind().name()); |
|
1001 |
printList("value", node.getValue()); |
|
1002 |
return visitTree(node, null); |
|
1003 |
} |
|
1004 |
||
1005 |
public Void visitAuthor(AuthorTree node, Void p) { |
|
1006 |
printList("name", node.getName()); |
|
1007 |
return visitBlockTag(node, null); |
|
1008 |
} |
|
1009 |
||
1010 |
public Void visitComment(CommentTree node, Void p) { |
|
1011 |
printLimitedEscapedString("body", node.getBody()); |
|
1012 |
return visitTree(node, null); |
|
1013 |
} |
|
1014 |
||
1015 |
public Void visitDeprecated(DeprecatedTree node, Void p) { |
|
1016 |
printList("body", node.getBody()); |
|
1017 |
return visitBlockTag(node, null); |
|
1018 |
} |
|
1019 |
||
1020 |
public Void visitDocComment(DocCommentTree node, Void p) { |
|
1021 |
printList("firstSentence", node.getFirstSentence()); |
|
1022 |
printList("body", node.getBody()); |
|
1023 |
printList("tags", node.getBlockTags()); |
|
1024 |
return visitTree(node, null); |
|
1025 |
} |
|
1026 |
||
1027 |
public Void visitDocRoot(DocRootTree node, Void p) { |
|
1028 |
return visitInlineTag(node, null); |
|
1029 |
} |
|
1030 |
||
48028
9e022f580a9d
8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents:
47216
diff
changeset
|
1031 |
@Override |
9e022f580a9d
8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents:
47216
diff
changeset
|
1032 |
public Void visitDocType(DocTypeTree node, Void aVoid) { |
9e022f580a9d
8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents:
47216
diff
changeset
|
1033 |
printLimitedEscapedString("body", node.getText()); |
9e022f580a9d
8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents:
47216
diff
changeset
|
1034 |
return visitTree(node, null); |
9e022f580a9d
8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents:
47216
diff
changeset
|
1035 |
} |
9e022f580a9d
8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents:
47216
diff
changeset
|
1036 |
|
25291 | 1037 |
public Void visitEndElement(EndElementTree node, Void p) { |
1038 |
printName("name", node.getName()); |
|
1039 |
return visitTree(node, null); |
|
1040 |
} |
|
1041 |
||
1042 |
public Void visitEntity(EntityTree node, Void p) { |
|
1043 |
printName("name", node.getName()); |
|
1044 |
return visitTree(node, null); |
|
1045 |
} |
|
1046 |
||
1047 |
public Void visitErroneous(ErroneousTree node, Void p) { |
|
1048 |
printLimitedEscapedString("body", node.getBody()); |
|
1049 |
printString("diag", node.getDiagnostic().getMessage(Locale.getDefault())); |
|
1050 |
return visitTree(node, null); |
|
1051 |
} |
|
1052 |
||
37009
476d8d615222
8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents:
36526
diff
changeset
|
1053 |
public Void visitHidden(HiddenTree node, Void p) { |
476d8d615222
8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents:
36526
diff
changeset
|
1054 |
printList("body", node.getBody()); |
476d8d615222
8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents:
36526
diff
changeset
|
1055 |
return visitBlockTag(node, null); |
476d8d615222
8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents:
36526
diff
changeset
|
1056 |
} |
476d8d615222
8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents:
36526
diff
changeset
|
1057 |
|
25291 | 1058 |
public Void visitIdentifier(IdentifierTree node, Void p) { |
1059 |
printName("name", node.getName()); |
|
1060 |
return visitTree(node, null); |
|
1061 |
} |
|
1062 |
||
34567
c74f68484156
8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents:
34479
diff
changeset
|
1063 |
public Void visitIndex(IndexTree node, Void p) { |
c74f68484156
8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents:
34479
diff
changeset
|
1064 |
printString("kind", node.getKind().name()); |
c74f68484156
8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents:
34479
diff
changeset
|
1065 |
printDocTree("term", node.getSearchTerm()); |
c74f68484156
8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents:
34479
diff
changeset
|
1066 |
printList("desc", node.getDescription()); |
c74f68484156
8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents:
34479
diff
changeset
|
1067 |
return visitInlineTag(node, p); |
c74f68484156
8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents:
34479
diff
changeset
|
1068 |
} |
c74f68484156
8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents:
34479
diff
changeset
|
1069 |
|
25291 | 1070 |
public Void visitInheritDoc(InheritDocTree node, Void p) { |
1071 |
return visitInlineTag(node, null); |
|
1072 |
} |
|
1073 |
||
1074 |
public Void visitLink(LinkTree node, Void p) { |
|
1075 |
printString("kind", node.getKind().name()); |
|
1076 |
printDocTree("ref", node.getReference()); |
|
1077 |
printList("list", node.getLabel()); |
|
1078 |
return visitInlineTag(node, null); |
|
1079 |
} |
|
1080 |
||
1081 |
public Void visitLiteral(LiteralTree node, Void p) { |
|
1082 |
printString("kind", node.getKind().name()); |
|
1083 |
printDocTree("body", node.getBody()); |
|
1084 |
return visitInlineTag(node, null); |
|
1085 |
} |
|
1086 |
||
1087 |
public Void visitParam(ParamTree node, Void p) { |
|
1088 |
printString("isTypeParameter", String.valueOf(node.isTypeParameter())); |
|
1089 |
printString("kind", node.getKind().name()); |
|
1090 |
printList("desc", node.getDescription()); |
|
1091 |
return visitBlockTag(node, null); |
|
1092 |
} |
|
1093 |
||
42831
feff6f296019
8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents:
40232
diff
changeset
|
1094 |
public Void visitProvides(ProvidesTree node, Void p) { |
feff6f296019
8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents:
40232
diff
changeset
|
1095 |
printString("kind", node.getKind().name()); |
feff6f296019
8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents:
40232
diff
changeset
|
1096 |
printDocTree("serviceType", node.getServiceType()); |
feff6f296019
8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents:
40232
diff
changeset
|
1097 |
printList("description", node.getDescription()); |
feff6f296019
8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents:
40232
diff
changeset
|
1098 |
return visitBlockTag(node, null); |
feff6f296019
8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents:
40232
diff
changeset
|
1099 |
} |
feff6f296019
8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents:
40232
diff
changeset
|
1100 |
|
25291 | 1101 |
public Void visitReference(ReferenceTree node, Void p) { |
1102 |
printString("signature", node.getSignature()); |
|
1103 |
return visitTree(node, null); |
|
1104 |
} |
|
1105 |
||
1106 |
public Void visitReturn(ReturnTree node, Void p) { |
|
1107 |
printList("desc", node.getDescription()); |
|
1108 |
return visitBlockTag(node, null); |
|
1109 |
} |
|
1110 |
||
1111 |
public Void visitSee(SeeTree node, Void p) { |
|
1112 |
printList("ref", node.getReference()); |
|
1113 |
return visitBlockTag(node, null); |
|
1114 |
} |
|
1115 |
||
1116 |
public Void visitSerial(SerialTree node, Void p) { |
|
1117 |
printList("desc", node.getDescription()); |
|
1118 |
return visitBlockTag(node, null); |
|
1119 |
} |
|
1120 |
||
1121 |
public Void visitSerialData(SerialDataTree node, Void p) { |
|
1122 |
printList("desc", node.getDescription()); |
|
1123 |
return visitBlockTag(node, null); |
|
1124 |
} |
|
1125 |
||
1126 |
public Void visitSerialField(SerialFieldTree node, Void p) { |
|
1127 |
printDocTree("name", node.getName()); |
|
1128 |
printDocTree("type", node.getType()); |
|
1129 |
printList("desc", node.getDescription()); |
|
1130 |
return visitBlockTag(node, null); |
|
1131 |
} |
|
1132 |
||
1133 |
public Void visitSince(SinceTree node, Void p) { |
|
1134 |
printList("body", node.getBody()); |
|
1135 |
return visitBlockTag(node, null); |
|
1136 |
} |
|
1137 |
||
1138 |
public Void visitStartElement(StartElementTree node, Void p) { |
|
1139 |
printName("name", node.getName()); |
|
1140 |
printList("attrs", node.getAttributes()); |
|
1141 |
printString("selfClosing", String.valueOf(node.isSelfClosing())); |
|
1142 |
return visitBlockTag(node, null); |
|
1143 |
} |
|
1144 |
||
46184
f1325703ea85
8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents:
42831
diff
changeset
|
1145 |
public Void visitSummary(SummaryTree node, Void p) { |
f1325703ea85
8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents:
42831
diff
changeset
|
1146 |
printString("name", node.getTagName()); |
f1325703ea85
8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents:
42831
diff
changeset
|
1147 |
printList("summary", node.getSummary()); |
f1325703ea85
8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents:
42831
diff
changeset
|
1148 |
return visitInlineTag(node, null); |
f1325703ea85
8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents:
42831
diff
changeset
|
1149 |
} |
f1325703ea85
8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents:
42831
diff
changeset
|
1150 |
|
25291 | 1151 |
public Void visitText(TextTree node, Void p) { |
1152 |
printLimitedEscapedString("body", node.getBody()); |
|
1153 |
return visitTree(node, null); |
|
1154 |
} |
|
1155 |
||
1156 |
public Void visitThrows(ThrowsTree node, Void p) { |
|
1157 |
printDocTree("name", node.getExceptionName()); |
|
1158 |
printList("desc", node.getDescription()); |
|
1159 |
return visitBlockTag(node, null); |
|
1160 |
} |
|
1161 |
||
1162 |
public Void visitUnknownBlockTag(UnknownBlockTagTree node, Void p) { |
|
1163 |
printString("name", node.getTagName()); |
|
1164 |
printList("content", node.getContent()); |
|
1165 |
return visitBlockTag(node, null); |
|
1166 |
} |
|
1167 |
||
1168 |
public Void visitUnknownInlineTag(UnknownInlineTagTree node, Void p) { |
|
1169 |
printString("name", node.getTagName()); |
|
1170 |
printList("content", node.getContent()); |
|
1171 |
return visitInlineTag(node, null); |
|
1172 |
} |
|
1173 |
||
42831
feff6f296019
8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents:
40232
diff
changeset
|
1174 |
public Void visitUses(UsesTree node, Void p) { |
feff6f296019
8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents:
40232
diff
changeset
|
1175 |
printString("kind", node.getKind().name()); |
feff6f296019
8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents:
40232
diff
changeset
|
1176 |
printDocTree("serviceType", node.getServiceType()); |
feff6f296019
8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents:
40232
diff
changeset
|
1177 |
printList("description", node.getDescription()); |
feff6f296019
8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents:
40232
diff
changeset
|
1178 |
return visitBlockTag(node, null); |
feff6f296019
8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents:
40232
diff
changeset
|
1179 |
} |
feff6f296019
8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents:
40232
diff
changeset
|
1180 |
|
25291 | 1181 |
public Void visitValue(ValueTree node, Void p) { |
1182 |
printDocTree("value", node.getReference()); |
|
1183 |
return visitInlineTag(node, null); |
|
1184 |
} |
|
1185 |
||
1186 |
public Void visitVersion(VersionTree node, Void p) { |
|
1187 |
printList("body", node.getBody()); |
|
1188 |
return visitBlockTag(node, null); |
|
1189 |
} |
|
1190 |
||
1191 |
public Void visitOther(DocTree node, Void p) { |
|
1192 |
return visitTree(node, null); |
|
1193 |
} |
|
1194 |
||
1195 |
public Void visitBlockTag(DocTree node, Void p) { |
|
1196 |
return visitTree(node, null); |
|
1197 |
} |
|
1198 |
||
1199 |
public Void visitInlineTag(DocTree node, Void p) { |
|
1200 |
return visitTree(node, null); |
|
1201 |
} |
|
1202 |
||
1203 |
public Void visitTree(DocTree node, Void p) { |
|
1204 |
return null; |
|
1205 |
} |
|
1206 |
} |
|
1207 |
||
1208 |
// </editor-fold> |
|
1209 |
||
15553 | 1210 |
// <editor-fold defaultstate="collapsed" desc="Symbol visitor"> |
1211 |
||
15560
d0509841a622
8007306: DPrinter: improve display of impl-class, internal tag/kind, and external tag/kind
jjg
parents:
15553
diff
changeset
|
1212 |
protected Symbol.Visitor<Void,Void> symVisitor = new SymbolVisitor(); |
15553 | 1213 |
|
1214 |
/** |
|
1215 |
* Default visitor class for Symbol objects. |
|
1216 |
* Note: each visitXYZ method ends by calling the corresponding |
|
1217 |
* visit method for its superclass. |
|
1218 |
*/ |
|
15560
d0509841a622
8007306: DPrinter: improve display of impl-class, internal tag/kind, and external tag/kind
jjg
parents:
15553
diff
changeset
|
1219 |
class SymbolVisitor implements Symbol.Visitor<Void,Void> { |
15553 | 1220 |
@Override |
15560
d0509841a622
8007306: DPrinter: improve display of impl-class, internal tag/kind, and external tag/kind
jjg
parents:
15553
diff
changeset
|
1221 |
public Void visitClassSymbol(ClassSymbol sym, Void ignore) { |
15553 | 1222 |
printName("fullname", sym.fullname); |
1223 |
printName("flatname", sym.flatname); |
|
1224 |
printScope("members", sym.members_field); |
|
1225 |
printFileObject("sourcefile", sym.sourcefile); |
|
1226 |
printFileObject("classfile", sym.classfile); |
|
1227 |
// trans-local? |
|
1228 |
// pool? |
|
15560
d0509841a622
8007306: DPrinter: improve display of impl-class, internal tag/kind, and external tag/kind
jjg
parents:
15553
diff
changeset
|
1229 |
return visitTypeSymbol(sym, null); |
15553 | 1230 |
} |
1231 |
||
1232 |
@Override |
|
15560
d0509841a622
8007306: DPrinter: improve display of impl-class, internal tag/kind, and external tag/kind
jjg
parents:
15553
diff
changeset
|
1233 |
public Void visitMethodSymbol(MethodSymbol sym, Void ignore) { |
15553 | 1234 |
// code |
1235 |
printList("params", sym.params); |
|
1236 |
printList("savedParameterNames", sym.savedParameterNames); |
|
15560
d0509841a622
8007306: DPrinter: improve display of impl-class, internal tag/kind, and external tag/kind
jjg
parents:
15553
diff
changeset
|
1237 |
return visitSymbol(sym, null); |
15553 | 1238 |
} |
1239 |
||
1240 |
@Override |
|
15560
d0509841a622
8007306: DPrinter: improve display of impl-class, internal tag/kind, and external tag/kind
jjg
parents:
15553
diff
changeset
|
1241 |
public Void visitPackageSymbol(PackageSymbol sym, Void ignore) { |
15553 | 1242 |
printName("fullname", sym.fullname); |
1243 |
printScope("members", sym.members_field); |
|
1244 |
printSymbol("package-info", sym.package_info, Details.SUMMARY); |
|
15560
d0509841a622
8007306: DPrinter: improve display of impl-class, internal tag/kind, and external tag/kind
jjg
parents:
15553
diff
changeset
|
1245 |
return visitTypeSymbol(sym, null); |
15553 | 1246 |
} |
1247 |
||
1248 |
@Override |
|
15560
d0509841a622
8007306: DPrinter: improve display of impl-class, internal tag/kind, and external tag/kind
jjg
parents:
15553
diff
changeset
|
1249 |
public Void visitOperatorSymbol(OperatorSymbol sym, Void ignore) { |
15553 | 1250 |
printInt("opcode", sym.opcode); |
15560
d0509841a622
8007306: DPrinter: improve display of impl-class, internal tag/kind, and external tag/kind
jjg
parents:
15553
diff
changeset
|
1251 |
return visitMethodSymbol(sym, null); |
15553 | 1252 |
} |
1253 |
||
1254 |
@Override |
|
15560
d0509841a622
8007306: DPrinter: improve display of impl-class, internal tag/kind, and external tag/kind
jjg
parents:
15553
diff
changeset
|
1255 |
public Void visitVarSymbol(VarSymbol sym, Void ignore) { |
15553 | 1256 |
printInt("pos", sym.pos); |
1257 |
printInt("adm", sym.adr); |
|
1258 |
// data is a private field, and the standard accessors may |
|
1259 |
// mutate it as part of lazy evaluation. Therefore, use |
|
1260 |
// reflection to get the raw data. |
|
1261 |
printObject("data", getField(sym, VarSymbol.class, "data"), Details.SUMMARY); |
|
15560
d0509841a622
8007306: DPrinter: improve display of impl-class, internal tag/kind, and external tag/kind
jjg
parents:
15553
diff
changeset
|
1262 |
return visitSymbol(sym, null); |
15553 | 1263 |
} |
1264 |
||
1265 |
@Override |
|
15560
d0509841a622
8007306: DPrinter: improve display of impl-class, internal tag/kind, and external tag/kind
jjg
parents:
15553
diff
changeset
|
1266 |
public Void visitTypeSymbol(TypeSymbol sym, Void ignore) { |
d0509841a622
8007306: DPrinter: improve display of impl-class, internal tag/kind, and external tag/kind
jjg
parents:
15553
diff
changeset
|
1267 |
return visitSymbol(sym, null); |
15553 | 1268 |
} |
1269 |
||
1270 |
@Override |
|
15560
d0509841a622
8007306: DPrinter: improve display of impl-class, internal tag/kind, and external tag/kind
jjg
parents:
15553
diff
changeset
|
1271 |
public Void visitSymbol(Symbol sym, Void ignore) { |
15553 | 1272 |
return null; |
1273 |
} |
|
1274 |
} |
|
1275 |
||
1276 |
// </editor-fold> |
|
1277 |
||
1278 |
// <editor-fold defaultstate="collapsed" desc="Type visitor"> |
|
1279 |
||
15560
d0509841a622
8007306: DPrinter: improve display of impl-class, internal tag/kind, and external tag/kind
jjg
parents:
15553
diff
changeset
|
1280 |
protected Type.Visitor<Void,Void> typeVisitor = new TypeVisitor(); |
15553 | 1281 |
|
1282 |
/** |
|
1283 |
* Default visitor class for Type objects. |
|
1284 |
* Note: each visitXYZ method ends by calling the corresponding |
|
1285 |
* visit method for its superclass. |
|
1286 |
*/ |
|
15560
d0509841a622
8007306: DPrinter: improve display of impl-class, internal tag/kind, and external tag/kind
jjg
parents:
15553
diff
changeset
|
1287 |
public class TypeVisitor implements Type.Visitor<Void,Void> { |
d0509841a622
8007306: DPrinter: improve display of impl-class, internal tag/kind, and external tag/kind
jjg
parents:
15553
diff
changeset
|
1288 |
public Void visitArrayType(ArrayType type, Void ignore) { |
15553 | 1289 |
printType("elemType", type.elemtype, Details.FULL); |
15560
d0509841a622
8007306: DPrinter: improve display of impl-class, internal tag/kind, and external tag/kind
jjg
parents:
15553
diff
changeset
|
1290 |
return visitType(type, null); |
15553 | 1291 |
} |
1292 |
||
15560
d0509841a622
8007306: DPrinter: improve display of impl-class, internal tag/kind, and external tag/kind
jjg
parents:
15553
diff
changeset
|
1293 |
public Void visitCapturedType(CapturedType type, Void ignore) { |
15553 | 1294 |
printType("wildcard", type.wildcard, Details.FULL); |
15560
d0509841a622
8007306: DPrinter: improve display of impl-class, internal tag/kind, and external tag/kind
jjg
parents:
15553
diff
changeset
|
1295 |
return visitTypeVar(type, null); |
15553 | 1296 |
} |
1297 |
||
15560
d0509841a622
8007306: DPrinter: improve display of impl-class, internal tag/kind, and external tag/kind
jjg
parents:
15553
diff
changeset
|
1298 |
public Void visitClassType(ClassType type, Void ignore) { |
15553 | 1299 |
printType("outer", type.getEnclosingType(), Details.SUMMARY); |
1300 |
printList("typarams", type.typarams_field); |
|
1301 |
printList("allparams", type.allparams_field); |
|
1302 |
printType("supertype", type.supertype_field, Details.SUMMARY); |
|
1303 |
printList("interfaces", type.interfaces_field); |
|
1304 |
printList("allinterfaces", type.all_interfaces_field); |
|
15560
d0509841a622
8007306: DPrinter: improve display of impl-class, internal tag/kind, and external tag/kind
jjg
parents:
15553
diff
changeset
|
1305 |
return visitType(type, null); |
15553 | 1306 |
} |
1307 |
||
15560
d0509841a622
8007306: DPrinter: improve display of impl-class, internal tag/kind, and external tag/kind
jjg
parents:
15553
diff
changeset
|
1308 |
public Void visitErrorType(ErrorType type, Void ignore) { |
15553 | 1309 |
printType("originalType", type.getOriginalType(), Details.FULL); |
15560
d0509841a622
8007306: DPrinter: improve display of impl-class, internal tag/kind, and external tag/kind
jjg
parents:
15553
diff
changeset
|
1310 |
return visitClassType(type, null); |
15553 | 1311 |
} |
1312 |
||
15560
d0509841a622
8007306: DPrinter: improve display of impl-class, internal tag/kind, and external tag/kind
jjg
parents:
15553
diff
changeset
|
1313 |
public Void visitForAll(ForAll type, Void ignore) { |
15553 | 1314 |
printList("tvars", type.tvars); |
1315 |
return visitDelegatedType(type); |
|
1316 |
} |
|
1317 |
||
15560
d0509841a622
8007306: DPrinter: improve display of impl-class, internal tag/kind, and external tag/kind
jjg
parents:
15553
diff
changeset
|
1318 |
public Void visitMethodType(MethodType type, Void ignore) { |
15553 | 1319 |
printList("argtypes", type.argtypes); |
1320 |
printType("restype", type.restype, Details.FULL); |
|
1321 |
printList("thrown", type.thrown); |
|
34479
2a1f2bb7cc13
8008685: DPrinter should include MethodType.recvtype
vromero
parents:
33917
diff
changeset
|
1322 |
printType("recvtype", type.recvtype, Details.FULL); |
15560
d0509841a622
8007306: DPrinter: improve display of impl-class, internal tag/kind, and external tag/kind
jjg
parents:
15553
diff
changeset
|
1323 |
return visitType(type, null); |
15553 | 1324 |
} |
1325 |
||
36526 | 1326 |
public Void visitModuleType(ModuleType type, Void ignore) { |
1327 |
return visitType(type, null); |
|
1328 |
} |
|
1329 |
||
15560
d0509841a622
8007306: DPrinter: improve display of impl-class, internal tag/kind, and external tag/kind
jjg
parents:
15553
diff
changeset
|
1330 |
public Void visitPackageType(PackageType type, Void ignore) { |
d0509841a622
8007306: DPrinter: improve display of impl-class, internal tag/kind, and external tag/kind
jjg
parents:
15553
diff
changeset
|
1331 |
return visitType(type, null); |
15553 | 1332 |
} |
1333 |
||
15560
d0509841a622
8007306: DPrinter: improve display of impl-class, internal tag/kind, and external tag/kind
jjg
parents:
15553
diff
changeset
|
1334 |
public Void visitTypeVar(TypeVar type, Void ignore) { |
15553 | 1335 |
// For TypeVars (and not subtypes), the bound should always be |
1336 |
// null or bot. So, only print the bound for subtypes of TypeVar, |
|
1337 |
// or if the bound is (erroneously) not null or bot. |
|
1338 |
if (!type.hasTag(TypeTag.TYPEVAR) |
|
1339 |
|| !(type.bound == null || type.bound.hasTag(TypeTag.BOT))) { |
|
1340 |
printType("bound", type.bound, Details.FULL); |
|
1341 |
} |
|
1342 |
printType("lower", type.lower, Details.FULL); |
|
15560
d0509841a622
8007306: DPrinter: improve display of impl-class, internal tag/kind, and external tag/kind
jjg
parents:
15553
diff
changeset
|
1343 |
return visitType(type, null); |
15553 | 1344 |
} |
1345 |
||
15560
d0509841a622
8007306: DPrinter: improve display of impl-class, internal tag/kind, and external tag/kind
jjg
parents:
15553
diff
changeset
|
1346 |
public Void visitUndetVar(UndetVar type, Void ignore) { |
15553 | 1347 |
for (UndetVar.InferenceBound ib: UndetVar.InferenceBound.values()) |
1348 |
printList("bounds." + ib, type.getBounds(ib)); |
|
15705 | 1349 |
printInt("declaredCount", type.declaredCount); |
33917
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
30730
diff
changeset
|
1350 |
printType("inst", type.getInst(), Details.SUMMARY); |
15553 | 1351 |
return visitDelegatedType(type); |
1352 |
} |
|
1353 |
||
15560
d0509841a622
8007306: DPrinter: improve display of impl-class, internal tag/kind, and external tag/kind
jjg
parents:
15553
diff
changeset
|
1354 |
public Void visitWildcardType(WildcardType type, Void ignore) { |
15553 | 1355 |
printType("type", type.type, Details.SUMMARY); |
1356 |
printString("kind", type.kind.name()); |
|
1357 |
printType("bound", type.bound, Details.SUMMARY); |
|
15560
d0509841a622
8007306: DPrinter: improve display of impl-class, internal tag/kind, and external tag/kind
jjg
parents:
15553
diff
changeset
|
1358 |
return visitType(type, null); |
15553 | 1359 |
} |
1360 |
||
1361 |
protected Void visitDelegatedType(DelegatedType type) { |
|
1362 |
printType("qtype", type.qtype, Details.FULL); |
|
15560
d0509841a622
8007306: DPrinter: improve display of impl-class, internal tag/kind, and external tag/kind
jjg
parents:
15553
diff
changeset
|
1363 |
return visitType(type, null); |
15553 | 1364 |
} |
1365 |
||
15560
d0509841a622
8007306: DPrinter: improve display of impl-class, internal tag/kind, and external tag/kind
jjg
parents:
15553
diff
changeset
|
1366 |
public Void visitType(Type type, Void ignore) { |
15553 | 1367 |
return null; |
1368 |
} |
|
1369 |
} |
|
1370 |
||
1371 |
// </editor-fold> |
|
1372 |
||
1373 |
// <editor-fold defaultstate="collapsed" desc="Attribute (annotations) visitor"> |
|
1374 |
||
1375 |
protected Attribute.Visitor attrVisitor = new AttributeVisitor(); |
|
1376 |
||
1377 |
/** |
|
1378 |
* Default visitor class for Attribute (annotation) objects. |
|
1379 |
*/ |
|
1380 |
public class AttributeVisitor implements Attribute.Visitor { |
|
1381 |
||
1382 |
public void visitConstant(Attribute.Constant a) { |
|
1383 |
printObject("value", a.value, Details.SUMMARY); |
|
1384 |
visitAttribute(a); |
|
1385 |
} |
|
1386 |
||
1387 |
public void visitClass(Attribute.Class a) { |
|
1388 |
printObject("classType", a.classType, Details.SUMMARY); |
|
1389 |
visitAttribute(a); |
|
1390 |
} |
|
1391 |
||
1392 |
public void visitCompound(Attribute.Compound a) { |
|
1393 |
if (a instanceof Attribute.TypeCompound) { |
|
1394 |
Attribute.TypeCompound ta = (Attribute.TypeCompound) a; |
|
1395 |
// consider a custom printer? |
|
1396 |
printObject("position", ta.position, Details.SUMMARY); |
|
1397 |
} |
|
1398 |
printObject("synthesized", a.isSynthesized(), Details.SUMMARY); |
|
1399 |
printList("values", a.values); |
|
1400 |
visitAttribute(a); |
|
1401 |
} |
|
1402 |
||
1403 |
public void visitArray(Attribute.Array a) { |
|
1404 |
printList("values", Arrays.asList(a.values)); |
|
1405 |
visitAttribute(a); |
|
1406 |
} |
|
1407 |
||
1408 |
public void visitEnum(Attribute.Enum a) { |
|
1409 |
printSymbol("value", a.value, Details.SUMMARY); |
|
1410 |
visitAttribute(a); |
|
1411 |
} |
|
1412 |
||
1413 |
public void visitError(Attribute.Error a) { |
|
1414 |
visitAttribute(a); |
|
1415 |
} |
|
1416 |
||
1417 |
public void visitAttribute(Attribute a) { |
|
1418 |
printType("type", a.type, Details.SUMMARY); |
|
1419 |
} |
|
1420 |
||
1421 |
} |
|
1422 |
// </editor-fold> |
|
1423 |
||
1424 |
// <editor-fold defaultstate="collapsed" desc="Utility front end"> |
|
1425 |
||
1426 |
/** |
|
1427 |
* Utility class to invoke DPrinter from the command line. |
|
1428 |
*/ |
|
1429 |
static class Main { |
|
1430 |
public static void main(String... args) throws IOException { |
|
15561 | 1431 |
Main m = new Main(); |
15553 | 1432 |
PrintWriter out = new PrintWriter(System.out); |
1433 |
try { |
|
1434 |
if (args.length == 0) |
|
15561 | 1435 |
m.usage(out); |
15553 | 1436 |
else |
15561 | 1437 |
m.run(out, args); |
15553 | 1438 |
} finally { |
1439 |
out.flush(); |
|
1440 |
} |
|
1441 |
} |
|
1442 |
||
15561 | 1443 |
void usage(PrintWriter out) { |
15553 | 1444 |
out.println("Usage:"); |
1445 |
out.println(" java " + Main.class.getName() + " mode [options] [javac-options]"); |
|
15561 | 1446 |
out.print("where mode is one of: "); |
1447 |
String sep = ""; |
|
1448 |
for (Handler h: getHandlers().values()) { |
|
1449 |
out.print(sep); |
|
1450 |
out.print(h.name); |
|
1451 |
sep = ", "; |
|
1452 |
} |
|
1453 |
out.println(); |
|
1454 |
out.println("and where options include:"); |
|
15553 | 1455 |
out.println(" -before PARSE|ENTER|ANALYZE|GENERATE|ANNOTATION_PROCESSING|ANNOTATION_PROCESSING_ROUND"); |
1456 |
out.println(" -after PARSE|ENTER|ANALYZE|GENERATE|ANNOTATION_PROCESSING|ANNOTATION_PROCESSING_ROUND"); |
|
1457 |
out.println(" -showPositions"); |
|
1458 |
out.println(" -showSource"); |
|
1459 |
out.println(" -showTreeSymbols"); |
|
1460 |
out.println(" -showTreeTypes"); |
|
1461 |
out.println(" -hideEmptyItems"); |
|
1462 |
out.println(" -hideNulls"); |
|
1463 |
} |
|
1464 |
||
1465 |
void run(PrintWriter out, String... args) throws IOException { |
|
1466 |
JavaCompiler c = ToolProvider.getSystemJavaCompiler(); |
|
1467 |
StandardJavaFileManager fm = c.getStandardFileManager(null, null, null); |
|
1468 |
||
1469 |
// DPrinter options |
|
1470 |
final Set<TaskEvent.Kind> before = EnumSet.noneOf(TaskEvent.Kind.class); |
|
1471 |
final Set<TaskEvent.Kind> after = EnumSet.noneOf(TaskEvent.Kind.class); |
|
1472 |
boolean showPositions = false; |
|
1473 |
boolean showSource = false; |
|
1474 |
boolean showTreeSymbols = false; |
|
1475 |
boolean showTreeTypes = false; |
|
1476 |
boolean showEmptyItems = true; |
|
1477 |
boolean showNulls = true; |
|
1478 |
||
1479 |
// javac options |
|
1480 |
Collection<String> options = new ArrayList<String>(); |
|
1481 |
Collection<File> files = new ArrayList<File>(); |
|
1482 |
String classpath = null; |
|
1483 |
String classoutdir = null; |
|
1484 |
||
1485 |
final Handler h = getHandlers().get(args[0]); |
|
1486 |
if (h == null) |
|
1487 |
throw new IllegalArgumentException(args[0]); |
|
1488 |
||
1489 |
for (int i = 1; i < args.length; i++) { |
|
1490 |
String arg = args[i]; |
|
1491 |
if (arg.equals("-before") && i + 1 < args.length) { |
|
1492 |
before.add(getKind(args[++i])); |
|
1493 |
} else if (arg.equals("-after") && i + 1 < args.length) { |
|
1494 |
after.add(getKind(args[++i])); |
|
1495 |
} else if (arg.equals("-showPositions")) { |
|
1496 |
showPositions = true; |
|
1497 |
} else if (arg.equals("-showSource")) { |
|
1498 |
showSource = true; |
|
1499 |
} else if (arg.equals("-showTreeSymbols")) { |
|
1500 |
showTreeSymbols = true; |
|
1501 |
} else if (arg.equals("-showTreeTypes")) { |
|
1502 |
showTreeTypes = true; |
|
1503 |
} else if (arg.equals("-hideEmptyLists")) { |
|
1504 |
showEmptyItems = false; |
|
1505 |
} else if (arg.equals("-hideNulls")) { |
|
1506 |
showNulls = false; |
|
1507 |
} else if (arg.equals("-classpath") && i + 1 < args.length) { |
|
1508 |
classpath = args[++i]; |
|
1509 |
} else if (arg.equals("-d") && i + 1 < args.length) { |
|
1510 |
classoutdir = args[++i]; |
|
1511 |
} else if (arg.startsWith("-")) { |
|
1512 |
int n = c.isSupportedOption(arg); |
|
1513 |
if (n < 0) throw new IllegalArgumentException(arg); |
|
1514 |
options.add(arg); |
|
1515 |
while (n > 0) options.add(args[++i]); |
|
1516 |
} else if (arg.endsWith(".java")) { |
|
1517 |
files.add(new File(arg)); |
|
1518 |
} |
|
1519 |
} |
|
1520 |
||
1521 |
if (classoutdir != null) { |
|
1522 |
fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(new File(classoutdir))); |
|
1523 |
} |
|
1524 |
||
1525 |
if (classpath != null) { |
|
1526 |
Collection<File> path = new ArrayList<File>(); |
|
1527 |
for (String p: classpath.split(File.pathSeparator)) { |
|
1528 |
if (p.isEmpty()) continue; |
|
1529 |
File f = new File(p); |
|
1530 |
if (f.exists()) path.add(f); |
|
1531 |
} |
|
1532 |
fm.setLocation(StandardLocation.CLASS_PATH, path); |
|
1533 |
} |
|
1534 |
Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjectsFromFiles(files); |
|
1535 |
||
1536 |
JavacTask task = (JavacTask) c.getTask(out, fm, null, options, null, fos); |
|
1537 |
final Trees trees = Trees.instance(task); |
|
1538 |
||
1539 |
final DPrinter dprinter = new DPrinter(out, trees); |
|
1540 |
dprinter.source(showSource) |
|
1541 |
.emptyItems(showEmptyItems) |
|
1542 |
.nulls(showNulls) |
|
1543 |
.positions(showPositions) |
|
1544 |
.treeSymbols(showTreeSymbols) |
|
1545 |
.treeTypes(showTreeTypes); |
|
1546 |
||
1547 |
if (before.isEmpty() && after.isEmpty()) { |
|
1548 |
if (h.name.equals("trees") && !showTreeSymbols && !showTreeTypes) |
|
1549 |
after.add(TaskEvent.Kind.PARSE); |
|
1550 |
else |
|
1551 |
after.add(TaskEvent.Kind.ANALYZE); |
|
1552 |
} |
|
1553 |
||
1554 |
task.addTaskListener(new TaskListener() { |
|
1555 |
public void started(TaskEvent e) { |
|
1556 |
if (before.contains(e.getKind())) |
|
1557 |
handle(e); |
|
1558 |
} |
|
1559 |
||
1560 |
public void finished(TaskEvent e) { |
|
1561 |
if (after.contains(e.getKind())) |
|
1562 |
handle(e); |
|
1563 |
} |
|
1564 |
||
1565 |
private void handle(TaskEvent e) { |
|
25291 | 1566 |
JCCompilationUnit unit = (JCCompilationUnit) e.getCompilationUnit(); |
15553 | 1567 |
switch (e.getKind()) { |
1568 |
case PARSE: |
|
1569 |
case ENTER: |
|
1570 |
h.handle(e.getSourceFile().getName(), |
|
25291 | 1571 |
unit, unit, |
15553 | 1572 |
dprinter); |
1573 |
break; |
|
1574 |
||
1575 |
default: |
|
1576 |
TypeElement elem = e.getTypeElement(); |
|
1577 |
h.handle(elem.toString(), |
|
25291 | 1578 |
unit, (JCTree) trees.getTree(elem), |
15553 | 1579 |
dprinter); |
1580 |
break; |
|
1581 |
} |
|
1582 |
} |
|
1583 |
}); |
|
1584 |
||
1585 |
task.call(); |
|
1586 |
} |
|
1587 |
||
1588 |
TaskEvent.Kind getKind(String s) { |
|
1589 |
return TaskEvent.Kind.valueOf(s.toUpperCase()); |
|
1590 |
} |
|
1591 |
||
1592 |
static protected abstract class Handler { |
|
1593 |
final String name; |
|
1594 |
Handler(String name) { |
|
1595 |
this.name = name; |
|
1596 |
} |
|
25291 | 1597 |
abstract void handle(String label, |
1598 |
JCCompilationUnit unit, JCTree tree, |
|
1599 |
DPrinter dprinter); |
|
15553 | 1600 |
} |
1601 |
||
1602 |
Map<String,Handler> getHandlers() { |
|
1603 |
Map<String,Handler> map = new HashMap<String, Handler>(); |
|
1604 |
for (Handler h: defaultHandlers) { |
|
1605 |
map.put(h.name, h); |
|
1606 |
} |
|
1607 |
return map; |
|
1608 |
} |
|
1609 |
||
1610 |
protected final Handler[] defaultHandlers = { |
|
1611 |
new Handler("trees") { |
|
1612 |
@Override |
|
25291 | 1613 |
void handle(String name, JCCompilationUnit unit, JCTree tree, DPrinter dprinter) { |
15553 | 1614 |
dprinter.printTree(name, tree); |
1615 |
dprinter.out.println(); |
|
1616 |
} |
|
1617 |
}, |
|
1618 |
||
25291 | 1619 |
new Handler("doctrees") { |
1620 |
@Override |
|
1621 |
void handle(final String name, final JCCompilationUnit unit, JCTree tree, final DPrinter dprinter) { |
|
1622 |
TreeScanner ds = new DeclScanner() { |
|
1623 |
public void visitDecl(JCTree tree, Symbol sym) { |
|
1624 |
DocTree dt = unit.docComments.getCommentTree(tree); |
|
1625 |
if (dt != null) { |
|
1626 |
String label = (sym == null) ? Pretty.toSimpleString(tree) : sym.name.toString(); |
|
1627 |
dprinter.printDocTree(label, dt); |
|
1628 |
dprinter.out.println(); |
|
1629 |
} |
|
1630 |
} |
|
1631 |
}; |
|
1632 |
ds.scan(tree); |
|
1633 |
} |
|
1634 |
}, |
|
1635 |
||
15553 | 1636 |
new Handler("symbols") { |
1637 |
@Override |
|
25291 | 1638 |
void handle(String name, JCCompilationUnit unit, JCTree tree, final DPrinter dprinter) { |
1639 |
TreeScanner ds = new DeclScanner() { |
|
1640 |
public void visitDecl(JCTree tree, Symbol sym) { |
|
1641 |
String label = (sym == null) ? Pretty.toSimpleString(tree) : sym.name.toString(); |
|
1642 |
dprinter.printSymbol(label, sym); |
|
15553 | 1643 |
dprinter.out.println(); |
1644 |
} |
|
1645 |
}; |
|
1646 |
ds.scan(tree); |
|
1647 |
} |
|
1648 |
}, |
|
1649 |
||
1650 |
new Handler("types") { |
|
1651 |
@Override |
|
25291 | 1652 |
void handle(String name, JCCompilationUnit unit, JCTree tree, final DPrinter dprinter) { |
15553 | 1653 |
TreeScanner ts = new TreeScanner() { |
1654 |
@Override |
|
1655 |
public void scan(JCTree tree) { |
|
1656 |
if (tree == null) { |
|
1657 |
return; |
|
1658 |
} |
|
1659 |
if (tree.type != null) { |
|
1660 |
String label = Pretty.toSimpleString(tree); |
|
1661 |
dprinter.printType(label, tree.type); |
|
1662 |
dprinter.out.println(); |
|
1663 |
} |
|
1664 |
super.scan(tree); |
|
1665 |
} |
|
1666 |
}; |
|
1667 |
ts.scan(tree); |
|
1668 |
} |
|
1669 |
} |
|
1670 |
}; |
|
1671 |
} |
|
1672 |
||
25291 | 1673 |
protected static abstract class DeclScanner extends TreeScanner { |
1674 |
@Override |
|
1675 |
public void visitClassDef(JCClassDecl tree) { |
|
1676 |
visitDecl(tree, tree.sym); |
|
1677 |
super.visitClassDef(tree); |
|
1678 |
} |
|
1679 |
||
1680 |
@Override |
|
1681 |
public void visitMethodDef(JCMethodDecl tree) { |
|
1682 |
visitDecl(tree, tree.sym); |
|
1683 |
super.visitMethodDef(tree); |
|
1684 |
} |
|
1685 |
||
1686 |
@Override |
|
1687 |
public void visitVarDef(JCVariableDecl tree) { |
|
1688 |
visitDecl(tree, tree.sym); |
|
1689 |
super.visitVarDef(tree); |
|
1690 |
} |
|
1691 |
||
1692 |
protected abstract void visitDecl(JCTree tree, Symbol sym); |
|
1693 |
} |
|
1694 |
||
15553 | 1695 |
// </editor-fold> |
1696 |
||
1697 |
} |