author | cushon |
Wed, 05 Dec 2018 11:31:20 -0800 | |
changeset 52864 | e78890a4c25f |
parent 51563 | de411d537aae |
child 55306 | ea43db53de91 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
48749
fd40b0b3d849
8152616: com.sun.tools.javac.tree.Pretty generates nested comments for enum
sdama
parents:
47268
diff
changeset
|
2 |
* Copyright (c) 1999, 2018, 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.javac.tree; |
|
27 |
||
28 |
import java.io.*; |
|
29 |
||
51563
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
48749
diff
changeset
|
30 |
import com.sun.source.tree.CaseTree.CaseKind; |
11142 | 31 |
import com.sun.source.tree.MemberReferenceTree.ReferenceMode; |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39091
diff
changeset
|
32 |
import com.sun.source.tree.ModuleTree.ModuleKind; |
13077 | 33 |
import com.sun.tools.javac.code.*; |
34 |
import com.sun.tools.javac.tree.JCTree.*; |
|
10 | 35 |
import com.sun.tools.javac.util.*; |
36 |
import com.sun.tools.javac.util.List; |
|
37 |
import static com.sun.tools.javac.code.Flags.*; |
|
10950 | 38 |
import static com.sun.tools.javac.code.Flags.ANNOTATION; |
39 |
import static com.sun.tools.javac.tree.JCTree.Tag.*; |
|
10 | 40 |
|
41 |
/** Prints out a tree as an indented Java source program. |
|
42 |
* |
|
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
43 |
* <p><b>This is NOT part of any supported API. |
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
44 |
* If you write code that depends on this, you do so at your own risk. |
10 | 45 |
* This code and its internal interfaces are subject to change or |
46 |
* deletion without notice.</b> |
|
47 |
*/ |
|
48 |
public class Pretty extends JCTree.Visitor { |
|
49 |
||
50 |
public Pretty(Writer out, boolean sourceOutput) { |
|
51 |
this.out = out; |
|
52 |
this.sourceOutput = sourceOutput; |
|
53 |
} |
|
54 |
||
55 |
/** Set when we are producing source output. If we're not |
|
56 |
* producing source output, we can sometimes give more detail in |
|
57 |
* the output even though that detail would not be valid java |
|
4413
2ae470f0b492
6902720: javac pretty printer does not handle enums correctly
jjg
parents:
3149
diff
changeset
|
58 |
* source. |
10 | 59 |
*/ |
60 |
private final boolean sourceOutput; |
|
61 |
||
62 |
/** The output stream on which trees are printed. |
|
63 |
*/ |
|
64 |
Writer out; |
|
65 |
||
66 |
/** Indentation width (can be reassigned from outside). |
|
67 |
*/ |
|
68 |
public int width = 4; |
|
69 |
||
70 |
/** The current left margin. |
|
71 |
*/ |
|
72 |
int lmargin = 0; |
|
73 |
||
74 |
/** The enclosing class name. |
|
75 |
*/ |
|
76 |
Name enclClassName; |
|
77 |
||
13077 | 78 |
/** A table mapping trees to their documentation comments |
10 | 79 |
* (can be null) |
80 |
*/ |
|
13077 | 81 |
DocCommentTable docComments = null; |
10 | 82 |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
13844
diff
changeset
|
83 |
/** |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
13844
diff
changeset
|
84 |
* A string sequence to be used when Pretty output should be constrained |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
13844
diff
changeset
|
85 |
* to fit into a given size |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
13844
diff
changeset
|
86 |
*/ |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
13844
diff
changeset
|
87 |
private final static String trimSequence = "[...]"; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
13844
diff
changeset
|
88 |
|
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
89 |
/** |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
90 |
* Max number of chars to be generated when output should fit into a single line |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
91 |
*/ |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
92 |
private final static int PREFERRED_LENGTH = 20; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
93 |
|
10 | 94 |
/** Align code to be indented to left margin. |
95 |
*/ |
|
96 |
void align() throws IOException { |
|
97 |
for (int i = 0; i < lmargin; i++) out.write(" "); |
|
98 |
} |
|
99 |
||
100 |
/** Increase left margin by indentation width. |
|
101 |
*/ |
|
102 |
void indent() { |
|
103 |
lmargin = lmargin + width; |
|
104 |
} |
|
105 |
||
106 |
/** Decrease left margin by indentation width. |
|
107 |
*/ |
|
108 |
void undent() { |
|
109 |
lmargin = lmargin - width; |
|
110 |
} |
|
111 |
||
112 |
/** Enter a new precedence level. Emit a `(' if new precedence level |
|
113 |
* is less than precedence level so far. |
|
114 |
* @param contextPrec The precedence level in force so far. |
|
115 |
* @param ownPrec The new precedence level. |
|
116 |
*/ |
|
117 |
void open(int contextPrec, int ownPrec) throws IOException { |
|
118 |
if (ownPrec < contextPrec) out.write("("); |
|
119 |
} |
|
120 |
||
121 |
/** Leave precedence level. Emit a `(' if inner precedence level |
|
122 |
* is less than precedence level we revert to. |
|
123 |
* @param contextPrec The precedence level we revert to. |
|
124 |
* @param ownPrec The inner precedence level. |
|
125 |
*/ |
|
126 |
void close(int contextPrec, int ownPrec) throws IOException { |
|
127 |
if (ownPrec < contextPrec) out.write(")"); |
|
128 |
} |
|
129 |
||
130 |
/** Print string, replacing all non-ascii character with unicode escapes. |
|
131 |
*/ |
|
132 |
public void print(Object s) throws IOException { |
|
133 |
out.write(Convert.escapeUnicode(s.toString())); |
|
134 |
} |
|
135 |
||
136 |
/** Print new line. |
|
137 |
*/ |
|
138 |
public void println() throws IOException { |
|
139 |
out.write(lineSep); |
|
140 |
} |
|
141 |
||
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
142 |
public static String toSimpleString(JCTree tree) { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
143 |
return toSimpleString(tree, PREFERRED_LENGTH); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
144 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
145 |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
13844
diff
changeset
|
146 |
public static String toSimpleString(JCTree tree, int maxLength) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
13844
diff
changeset
|
147 |
StringWriter s = new StringWriter(); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
13844
diff
changeset
|
148 |
try { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
13844
diff
changeset
|
149 |
new Pretty(s, false).printExpr(tree); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
13844
diff
changeset
|
150 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
13844
diff
changeset
|
151 |
catch (IOException e) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
13844
diff
changeset
|
152 |
// should never happen, because StringWriter is defined |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
13844
diff
changeset
|
153 |
// never to throw any IOExceptions |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
13844
diff
changeset
|
154 |
throw new AssertionError(e); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
13844
diff
changeset
|
155 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
13844
diff
changeset
|
156 |
//we need to (i) replace all line terminators with a space and (ii) remove |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
13844
diff
changeset
|
157 |
//occurrences of 'missing' in the Pretty output (generated when types are missing) |
15044 | 158 |
String res = s.toString().trim().replaceAll("\\s+", " ").replaceAll("/\\*missing\\*/", ""); |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
13844
diff
changeset
|
159 |
if (res.length() < maxLength) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
13844
diff
changeset
|
160 |
return res; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
13844
diff
changeset
|
161 |
} else { |
15044 | 162 |
int head = (maxLength - trimSequence.length()) * 2 / 3; |
163 |
int tail = maxLength - trimSequence.length() - head; |
|
164 |
return res.substring(0, head) + trimSequence + res.substring(res.length() - tail); |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
13844
diff
changeset
|
165 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
13844
diff
changeset
|
166 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
13844
diff
changeset
|
167 |
|
10 | 168 |
String lineSep = System.getProperty("line.separator"); |
169 |
||
170 |
/************************************************************************** |
|
171 |
* Traversal methods |
|
172 |
*************************************************************************/ |
|
173 |
||
174 |
/** Exception to propogate IOException through visitXXX methods */ |
|
175 |
private static class UncheckedIOException extends Error { |
|
176 |
static final long serialVersionUID = -4032692679158424751L; |
|
177 |
UncheckedIOException(IOException e) { |
|
178 |
super(e.getMessage(), e); |
|
179 |
} |
|
180 |
} |
|
181 |
||
182 |
/** Visitor argument: the current precedence level. |
|
183 |
*/ |
|
184 |
int prec; |
|
185 |
||
186 |
/** Visitor method: print expression tree. |
|
187 |
* @param prec The current precedence level. |
|
188 |
*/ |
|
189 |
public void printExpr(JCTree tree, int prec) throws IOException { |
|
190 |
int prevPrec = this.prec; |
|
191 |
try { |
|
192 |
this.prec = prec; |
|
193 |
if (tree == null) print("/*missing*/"); |
|
194 |
else { |
|
195 |
tree.accept(this); |
|
196 |
} |
|
197 |
} catch (UncheckedIOException ex) { |
|
198 |
IOException e = new IOException(ex.getMessage()); |
|
199 |
e.initCause(ex); |
|
200 |
throw e; |
|
201 |
} finally { |
|
202 |
this.prec = prevPrec; |
|
203 |
} |
|
204 |
} |
|
205 |
||
206 |
/** Derived visitor method: print expression tree at minimum precedence level |
|
207 |
* for expression. |
|
208 |
*/ |
|
209 |
public void printExpr(JCTree tree) throws IOException { |
|
210 |
printExpr(tree, TreeInfo.noPrec); |
|
211 |
} |
|
212 |
||
213 |
/** Derived visitor method: print statement tree. |
|
214 |
*/ |
|
215 |
public void printStat(JCTree tree) throws IOException { |
|
216 |
printExpr(tree, TreeInfo.notExpression); |
|
217 |
} |
|
218 |
||
219 |
/** Derived visitor method: print list of expression trees, separated by given string. |
|
220 |
* @param sep the separator string |
|
221 |
*/ |
|
222 |
public <T extends JCTree> void printExprs(List<T> trees, String sep) throws IOException { |
|
223 |
if (trees.nonEmpty()) { |
|
224 |
printExpr(trees.head); |
|
225 |
for (List<T> l = trees.tail; l.nonEmpty(); l = l.tail) { |
|
226 |
print(sep); |
|
227 |
printExpr(l.head); |
|
228 |
} |
|
229 |
} |
|
230 |
} |
|
231 |
||
232 |
/** Derived visitor method: print list of expression trees, separated by commas. |
|
233 |
*/ |
|
234 |
public <T extends JCTree> void printExprs(List<T> trees) throws IOException { |
|
235 |
printExprs(trees, ", "); |
|
236 |
} |
|
237 |
||
238 |
/** Derived visitor method: print list of statements, each on a separate line. |
|
239 |
*/ |
|
240 |
public void printStats(List<? extends JCTree> trees) throws IOException { |
|
241 |
for (List<? extends JCTree> l = trees; l.nonEmpty(); l = l.tail) { |
|
242 |
align(); |
|
243 |
printStat(l.head); |
|
244 |
println(); |
|
245 |
} |
|
246 |
} |
|
247 |
||
248 |
/** Print a set of modifiers. |
|
249 |
*/ |
|
250 |
public void printFlags(long flags) throws IOException { |
|
251 |
if ((flags & SYNTHETIC) != 0) print("/*synthetic*/ "); |
|
252 |
print(TreeInfo.flagNames(flags)); |
|
14267
6321fbe0cf50
7192245: Add parser support for default methods
mcimadamore
parents:
14258
diff
changeset
|
253 |
if ((flags & ExtendedStandardFlags) != 0) print(" "); |
10 | 254 |
if ((flags & ANNOTATION) != 0) print("@"); |
255 |
} |
|
256 |
||
257 |
public void printAnnotations(List<JCAnnotation> trees) throws IOException { |
|
258 |
for (List<JCAnnotation> l = trees; l.nonEmpty(); l = l.tail) { |
|
259 |
printStat(l.head); |
|
260 |
println(); |
|
261 |
align(); |
|
262 |
} |
|
263 |
} |
|
264 |
||
15385 | 265 |
public void printTypeAnnotations(List<JCAnnotation> trees) throws IOException { |
266 |
for (List<JCAnnotation> l = trees; l.nonEmpty(); l = l.tail) { |
|
267 |
printExpr(l.head); |
|
268 |
print(" "); |
|
269 |
} |
|
270 |
} |
|
271 |
||
10 | 272 |
/** Print documentation comment, if it exists |
273 |
* @param tree The tree for which a documentation comment should be printed. |
|
274 |
*/ |
|
275 |
public void printDocComment(JCTree tree) throws IOException { |
|
276 |
if (docComments != null) { |
|
13077 | 277 |
String dc = docComments.getCommentText(tree); |
10 | 278 |
if (dc != null) { |
279 |
print("/**"); println(); |
|
280 |
int pos = 0; |
|
281 |
int endpos = lineEndPos(dc, pos); |
|
282 |
while (pos < dc.length()) { |
|
283 |
align(); |
|
284 |
print(" *"); |
|
285 |
if (pos < dc.length() && dc.charAt(pos) > ' ') print(" "); |
|
286 |
print(dc.substring(pos, endpos)); println(); |
|
287 |
pos = endpos + 1; |
|
288 |
endpos = lineEndPos(dc, pos); |
|
289 |
} |
|
290 |
align(); print(" */"); println(); |
|
291 |
align(); |
|
292 |
} |
|
293 |
} |
|
294 |
} |
|
295 |
//where |
|
296 |
static int lineEndPos(String s, int start) { |
|
297 |
int pos = s.indexOf('\n', start); |
|
298 |
if (pos < 0) pos = s.length(); |
|
299 |
return pos; |
|
300 |
} |
|
301 |
||
13844 | 302 |
/** If type parameter list is non-empty, print it enclosed in |
303 |
* {@literal "<...>"} brackets. |
|
10 | 304 |
*/ |
305 |
public void printTypeParameters(List<JCTypeParameter> trees) throws IOException { |
|
306 |
if (trees.nonEmpty()) { |
|
307 |
print("<"); |
|
308 |
printExprs(trees); |
|
309 |
print(">"); |
|
310 |
} |
|
311 |
} |
|
312 |
||
313 |
/** Print a block. |
|
314 |
*/ |
|
315 |
public void printBlock(List<? extends JCTree> stats) throws IOException { |
|
316 |
print("{"); |
|
317 |
println(); |
|
318 |
indent(); |
|
319 |
printStats(stats); |
|
320 |
undent(); |
|
321 |
align(); |
|
322 |
print("}"); |
|
323 |
} |
|
324 |
||
325 |
/** Print a block. |
|
326 |
*/ |
|
327 |
public void printEnumBody(List<JCTree> stats) throws IOException { |
|
328 |
print("{"); |
|
329 |
println(); |
|
330 |
indent(); |
|
331 |
boolean first = true; |
|
332 |
for (List<JCTree> l = stats; l.nonEmpty(); l = l.tail) { |
|
333 |
if (isEnumerator(l.head)) { |
|
334 |
if (!first) { |
|
335 |
print(","); |
|
336 |
println(); |
|
337 |
} |
|
338 |
align(); |
|
339 |
printStat(l.head); |
|
340 |
first = false; |
|
341 |
} |
|
342 |
} |
|
343 |
print(";"); |
|
344 |
println(); |
|
345 |
for (List<JCTree> l = stats; l.nonEmpty(); l = l.tail) { |
|
346 |
if (!isEnumerator(l.head)) { |
|
347 |
align(); |
|
348 |
printStat(l.head); |
|
349 |
println(); |
|
350 |
} |
|
351 |
} |
|
352 |
undent(); |
|
353 |
align(); |
|
354 |
print("}"); |
|
355 |
} |
|
356 |
||
357 |
/** Is the given tree an enumerator definition? */ |
|
358 |
boolean isEnumerator(JCTree t) { |
|
10950 | 359 |
return t.hasTag(VARDEF) && (((JCVariableDecl) t).mods.flags & ENUM) != 0; |
10 | 360 |
} |
361 |
||
362 |
/** Print unit consisting of package clause and import statements in toplevel, |
|
363 |
* followed by class definition. if class definition == null, |
|
364 |
* print all definitions in toplevel. |
|
365 |
* @param tree The toplevel tree |
|
366 |
* @param cdef The class definition, which is assumed to be part of the |
|
367 |
* toplevel tree. |
|
368 |
*/ |
|
369 |
public void printUnit(JCCompilationUnit tree, JCClassDecl cdef) throws IOException { |
|
370 |
docComments = tree.docComments; |
|
371 |
printDocComment(tree); |
|
24069 | 372 |
|
10 | 373 |
boolean firstImport = true; |
374 |
for (List<JCTree> l = tree.defs; |
|
24069 | 375 |
l.nonEmpty() && |
376 |
(cdef == null || |
|
377 |
l.head.hasTag(IMPORT) || l.head.hasTag(PACKAGEDEF)); |
|
378 |
l = l.tail) { |
|
10950 | 379 |
if (l.head.hasTag(IMPORT)) { |
10 | 380 |
JCImport imp = (JCImport)l.head; |
381 |
Name name = TreeInfo.name(imp.qualid); |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
382 |
if (name == name.table.names.asterisk || |
10 | 383 |
cdef == null || |
384 |
isUsed(TreeInfo.symbol(imp.qualid), cdef)) { |
|
385 |
if (firstImport) { |
|
386 |
firstImport = false; |
|
387 |
println(); |
|
388 |
} |
|
389 |
printStat(imp); |
|
390 |
} |
|
391 |
} else { |
|
392 |
printStat(l.head); |
|
393 |
} |
|
394 |
} |
|
395 |
if (cdef != null) { |
|
396 |
printStat(cdef); |
|
397 |
println(); |
|
398 |
} |
|
399 |
} |
|
400 |
// where |
|
401 |
boolean isUsed(final Symbol t, JCTree cdef) { |
|
402 |
class UsedVisitor extends TreeScanner { |
|
403 |
public void scan(JCTree tree) { |
|
404 |
if (tree!=null && !result) tree.accept(this); |
|
405 |
} |
|
406 |
boolean result = false; |
|
407 |
public void visitIdent(JCIdent tree) { |
|
408 |
if (tree.sym == t) result = true; |
|
409 |
} |
|
410 |
} |
|
411 |
UsedVisitor v = new UsedVisitor(); |
|
412 |
v.scan(cdef); |
|
413 |
return v.result; |
|
414 |
} |
|
415 |
||
416 |
/************************************************************************** |
|
417 |
* Visitor methods |
|
418 |
*************************************************************************/ |
|
419 |
||
420 |
public void visitTopLevel(JCCompilationUnit tree) { |
|
421 |
try { |
|
422 |
printUnit(tree, null); |
|
423 |
} catch (IOException e) { |
|
424 |
throw new UncheckedIOException(e); |
|
425 |
} |
|
426 |
} |
|
427 |
||
24069 | 428 |
public void visitPackageDef(JCPackageDecl tree) { |
429 |
try { |
|
430 |
printDocComment(tree); |
|
431 |
printAnnotations(tree.annotations); |
|
432 |
if (tree.pid != null) { |
|
433 |
print("package "); |
|
434 |
printExpr(tree.pid); |
|
435 |
print(";"); |
|
436 |
println(); |
|
437 |
} |
|
438 |
} catch (IOException e) { |
|
439 |
throw new UncheckedIOException(e); |
|
440 |
} |
|
441 |
} |
|
442 |
||
36526 | 443 |
@Override |
444 |
public void visitModuleDef(JCModuleDecl tree) { |
|
445 |
try { |
|
44192
aff725b7874a
8176470: javac Pretty printer should include doc comment for modules
jjg
parents:
42822
diff
changeset
|
446 |
printDocComment(tree); |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39091
diff
changeset
|
447 |
printAnnotations(tree.mods.annotations); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39091
diff
changeset
|
448 |
if (tree.getModuleType() == ModuleKind.OPEN) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39091
diff
changeset
|
449 |
print("open "); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39091
diff
changeset
|
450 |
} |
36526 | 451 |
print("module "); |
452 |
printExpr(tree.qualId); |
|
453 |
if (tree.directives == null) { |
|
454 |
print(";"); |
|
455 |
} else { |
|
456 |
printBlock(tree.directives); |
|
457 |
} |
|
458 |
println(); |
|
459 |
} catch (IOException e) { |
|
460 |
throw new UncheckedIOException(e); |
|
461 |
} |
|
462 |
} |
|
463 |
||
464 |
@Override |
|
465 |
public void visitExports(JCExports tree) { |
|
466 |
try { |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
467 |
print("exports "); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
468 |
printExpr(tree.qualid); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
469 |
if (tree.moduleNames != null) { |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
470 |
print(" to "); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
471 |
printExprs(tree.moduleNames); |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39091
diff
changeset
|
472 |
} |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
473 |
print(";"); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
474 |
} catch (IOException e) { |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
475 |
throw new UncheckedIOException(e); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
476 |
} |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
477 |
} |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
478 |
|
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
479 |
@Override |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
480 |
public void visitOpens(JCOpens tree) { |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
481 |
try { |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
482 |
print("opens "); |
36526 | 483 |
printExpr(tree.qualid); |
484 |
if (tree.moduleNames != null) { |
|
485 |
print(" to "); |
|
486 |
printExprs(tree.moduleNames); |
|
487 |
} |
|
488 |
print(";"); |
|
489 |
} catch (IOException e) { |
|
490 |
throw new UncheckedIOException(e); |
|
491 |
} |
|
492 |
} |
|
493 |
||
494 |
@Override |
|
495 |
public void visitProvides(JCProvides tree) { |
|
496 |
try { |
|
497 |
print("provides "); |
|
498 |
printExpr(tree.serviceName); |
|
499 |
print(" with "); |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39091
diff
changeset
|
500 |
printExprs(tree.implNames); |
36526 | 501 |
print(";"); |
502 |
} catch (IOException e) { |
|
503 |
throw new UncheckedIOException(e); |
|
504 |
} |
|
505 |
} |
|
506 |
||
507 |
@Override |
|
508 |
public void visitRequires(JCRequires tree) { |
|
509 |
try { |
|
510 |
print("requires "); |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39091
diff
changeset
|
511 |
if (tree.isStaticPhase) |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39091
diff
changeset
|
512 |
print("static "); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39091
diff
changeset
|
513 |
if (tree.isTransitive) |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39091
diff
changeset
|
514 |
print("transitive "); |
36526 | 515 |
printExpr(tree.moduleName); |
516 |
print(";"); |
|
517 |
} catch (IOException e) { |
|
518 |
throw new UncheckedIOException(e); |
|
519 |
} |
|
520 |
} |
|
521 |
||
522 |
@Override |
|
523 |
public void visitUses(JCUses tree) { |
|
524 |
try { |
|
525 |
print("uses "); |
|
526 |
printExpr(tree.qualid); |
|
527 |
print(";"); |
|
528 |
} catch (IOException e) { |
|
529 |
throw new UncheckedIOException(e); |
|
530 |
} |
|
531 |
} |
|
532 |
||
10 | 533 |
public void visitImport(JCImport tree) { |
534 |
try { |
|
535 |
print("import "); |
|
536 |
if (tree.staticImport) print("static "); |
|
537 |
printExpr(tree.qualid); |
|
538 |
print(";"); |
|
539 |
println(); |
|
540 |
} catch (IOException e) { |
|
541 |
throw new UncheckedIOException(e); |
|
542 |
} |
|
543 |
} |
|
544 |
||
545 |
public void visitClassDef(JCClassDecl tree) { |
|
546 |
try { |
|
547 |
println(); align(); |
|
548 |
printDocComment(tree); |
|
549 |
printAnnotations(tree.mods.annotations); |
|
550 |
printFlags(tree.mods.flags & ~INTERFACE); |
|
551 |
Name enclClassNamePrev = enclClassName; |
|
552 |
enclClassName = tree.name; |
|
553 |
if ((tree.mods.flags & INTERFACE) != 0) { |
|
554 |
print("interface " + tree.name); |
|
555 |
printTypeParameters(tree.typarams); |
|
556 |
if (tree.implementing.nonEmpty()) { |
|
557 |
print(" extends "); |
|
558 |
printExprs(tree.implementing); |
|
559 |
} |
|
560 |
} else { |
|
561 |
if ((tree.mods.flags & ENUM) != 0) |
|
562 |
print("enum " + tree.name); |
|
563 |
else |
|
564 |
print("class " + tree.name); |
|
565 |
printTypeParameters(tree.typarams); |
|
566 |
if (tree.extending != null) { |
|
567 |
print(" extends "); |
|
568 |
printExpr(tree.extending); |
|
569 |
} |
|
570 |
if (tree.implementing.nonEmpty()) { |
|
571 |
print(" implements "); |
|
572 |
printExprs(tree.implementing); |
|
573 |
} |
|
574 |
} |
|
575 |
print(" "); |
|
576 |
if ((tree.mods.flags & ENUM) != 0) { |
|
577 |
printEnumBody(tree.defs); |
|
578 |
} else { |
|
579 |
printBlock(tree.defs); |
|
580 |
} |
|
581 |
enclClassName = enclClassNamePrev; |
|
582 |
} catch (IOException e) { |
|
583 |
throw new UncheckedIOException(e); |
|
584 |
} |
|
585 |
} |
|
586 |
||
587 |
public void visitMethodDef(JCMethodDecl tree) { |
|
588 |
try { |
|
589 |
// when producing source output, omit anonymous constructors |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
590 |
if (tree.name == tree.name.table.names.init && |
10 | 591 |
enclClassName == null && |
592 |
sourceOutput) return; |
|
593 |
println(); align(); |
|
594 |
printDocComment(tree); |
|
595 |
printExpr(tree.mods); |
|
596 |
printTypeParameters(tree.typarams); |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
597 |
if (tree.name == tree.name.table.names.init) { |
10 | 598 |
print(enclClassName != null ? enclClassName : tree.name); |
599 |
} else { |
|
600 |
printExpr(tree.restype); |
|
601 |
print(" " + tree.name); |
|
602 |
} |
|
603 |
print("("); |
|
15385 | 604 |
if (tree.recvparam!=null) { |
605 |
printExpr(tree.recvparam); |
|
606 |
if (tree.params.size() > 0) { |
|
607 |
print(", "); |
|
608 |
} |
|
609 |
} |
|
10 | 610 |
printExprs(tree.params); |
611 |
print(")"); |
|
612 |
if (tree.thrown.nonEmpty()) { |
|
613 |
print(" throws "); |
|
614 |
printExprs(tree.thrown); |
|
615 |
} |
|
4696
45b45d9c96dd
6665791: com.sun.source.tree.MethodTree.toString() does not output default values
jjg
parents:
4413
diff
changeset
|
616 |
if (tree.defaultValue != null) { |
45b45d9c96dd
6665791: com.sun.source.tree.MethodTree.toString() does not output default values
jjg
parents:
4413
diff
changeset
|
617 |
print(" default "); |
45b45d9c96dd
6665791: com.sun.source.tree.MethodTree.toString() does not output default values
jjg
parents:
4413
diff
changeset
|
618 |
printExpr(tree.defaultValue); |
45b45d9c96dd
6665791: com.sun.source.tree.MethodTree.toString() does not output default values
jjg
parents:
4413
diff
changeset
|
619 |
} |
10 | 620 |
if (tree.body != null) { |
621 |
print(" "); |
|
622 |
printStat(tree.body); |
|
623 |
} else { |
|
624 |
print(";"); |
|
625 |
} |
|
626 |
} catch (IOException e) { |
|
627 |
throw new UncheckedIOException(e); |
|
628 |
} |
|
629 |
} |
|
630 |
||
631 |
public void visitVarDef(JCVariableDecl tree) { |
|
632 |
try { |
|
13077 | 633 |
if (docComments != null && docComments.hasComment(tree)) { |
10 | 634 |
println(); align(); |
635 |
} |
|
636 |
printDocComment(tree); |
|
637 |
if ((tree.mods.flags & ENUM) != 0) { |
|
638 |
print("/*public static final*/ "); |
|
639 |
print(tree.name); |
|
640 |
if (tree.init != null) { |
|
48749
fd40b0b3d849
8152616: com.sun.tools.javac.tree.Pretty generates nested comments for enum
sdama
parents:
47268
diff
changeset
|
641 |
if (tree.init.hasTag(NEWCLASS)) { |
4413
2ae470f0b492
6902720: javac pretty printer does not handle enums correctly
jjg
parents:
3149
diff
changeset
|
642 |
JCNewClass init = (JCNewClass) tree.init; |
48749
fd40b0b3d849
8152616: com.sun.tools.javac.tree.Pretty generates nested comments for enum
sdama
parents:
47268
diff
changeset
|
643 |
if (sourceOutput) { |
fd40b0b3d849
8152616: com.sun.tools.javac.tree.Pretty generates nested comments for enum
sdama
parents:
47268
diff
changeset
|
644 |
print(" /*enum*/ "); |
fd40b0b3d849
8152616: com.sun.tools.javac.tree.Pretty generates nested comments for enum
sdama
parents:
47268
diff
changeset
|
645 |
if (init.args != null && init.args.nonEmpty()) { |
fd40b0b3d849
8152616: com.sun.tools.javac.tree.Pretty generates nested comments for enum
sdama
parents:
47268
diff
changeset
|
646 |
print("("); |
fd40b0b3d849
8152616: com.sun.tools.javac.tree.Pretty generates nested comments for enum
sdama
parents:
47268
diff
changeset
|
647 |
print(init.args); |
fd40b0b3d849
8152616: com.sun.tools.javac.tree.Pretty generates nested comments for enum
sdama
parents:
47268
diff
changeset
|
648 |
print(")"); |
fd40b0b3d849
8152616: com.sun.tools.javac.tree.Pretty generates nested comments for enum
sdama
parents:
47268
diff
changeset
|
649 |
} |
fd40b0b3d849
8152616: com.sun.tools.javac.tree.Pretty generates nested comments for enum
sdama
parents:
47268
diff
changeset
|
650 |
if (init.def != null && init.def.defs != null) { |
fd40b0b3d849
8152616: com.sun.tools.javac.tree.Pretty generates nested comments for enum
sdama
parents:
47268
diff
changeset
|
651 |
print(" "); |
fd40b0b3d849
8152616: com.sun.tools.javac.tree.Pretty generates nested comments for enum
sdama
parents:
47268
diff
changeset
|
652 |
printBlock(init.def.defs); |
fd40b0b3d849
8152616: com.sun.tools.javac.tree.Pretty generates nested comments for enum
sdama
parents:
47268
diff
changeset
|
653 |
} |
fd40b0b3d849
8152616: com.sun.tools.javac.tree.Pretty generates nested comments for enum
sdama
parents:
47268
diff
changeset
|
654 |
return; |
fd40b0b3d849
8152616: com.sun.tools.javac.tree.Pretty generates nested comments for enum
sdama
parents:
47268
diff
changeset
|
655 |
}else { |
fd40b0b3d849
8152616: com.sun.tools.javac.tree.Pretty generates nested comments for enum
sdama
parents:
47268
diff
changeset
|
656 |
print(" /* = "); |
fd40b0b3d849
8152616: com.sun.tools.javac.tree.Pretty generates nested comments for enum
sdama
parents:
47268
diff
changeset
|
657 |
print("new "); |
fd40b0b3d849
8152616: com.sun.tools.javac.tree.Pretty generates nested comments for enum
sdama
parents:
47268
diff
changeset
|
658 |
if (init.def != null && init.def.mods.annotations.nonEmpty()) { |
fd40b0b3d849
8152616: com.sun.tools.javac.tree.Pretty generates nested comments for enum
sdama
parents:
47268
diff
changeset
|
659 |
printTypeAnnotations(init.def.mods.annotations); |
fd40b0b3d849
8152616: com.sun.tools.javac.tree.Pretty generates nested comments for enum
sdama
parents:
47268
diff
changeset
|
660 |
} |
fd40b0b3d849
8152616: com.sun.tools.javac.tree.Pretty generates nested comments for enum
sdama
parents:
47268
diff
changeset
|
661 |
printExpr(init.clazz); |
4413
2ae470f0b492
6902720: javac pretty printer does not handle enums correctly
jjg
parents:
3149
diff
changeset
|
662 |
print("("); |
48749
fd40b0b3d849
8152616: com.sun.tools.javac.tree.Pretty generates nested comments for enum
sdama
parents:
47268
diff
changeset
|
663 |
printExprs(init.args); |
4413
2ae470f0b492
6902720: javac pretty printer does not handle enums correctly
jjg
parents:
3149
diff
changeset
|
664 |
print(")"); |
48749
fd40b0b3d849
8152616: com.sun.tools.javac.tree.Pretty generates nested comments for enum
sdama
parents:
47268
diff
changeset
|
665 |
print(" */"); |
fd40b0b3d849
8152616: com.sun.tools.javac.tree.Pretty generates nested comments for enum
sdama
parents:
47268
diff
changeset
|
666 |
print(" /*enum*/ "); |
fd40b0b3d849
8152616: com.sun.tools.javac.tree.Pretty generates nested comments for enum
sdama
parents:
47268
diff
changeset
|
667 |
if (init.args != null && init.args.nonEmpty()) { |
fd40b0b3d849
8152616: com.sun.tools.javac.tree.Pretty generates nested comments for enum
sdama
parents:
47268
diff
changeset
|
668 |
print("("); |
fd40b0b3d849
8152616: com.sun.tools.javac.tree.Pretty generates nested comments for enum
sdama
parents:
47268
diff
changeset
|
669 |
printExprs(init.args); |
fd40b0b3d849
8152616: com.sun.tools.javac.tree.Pretty generates nested comments for enum
sdama
parents:
47268
diff
changeset
|
670 |
print(")"); |
fd40b0b3d849
8152616: com.sun.tools.javac.tree.Pretty generates nested comments for enum
sdama
parents:
47268
diff
changeset
|
671 |
} |
fd40b0b3d849
8152616: com.sun.tools.javac.tree.Pretty generates nested comments for enum
sdama
parents:
47268
diff
changeset
|
672 |
if (init.def != null && init.def.defs != null) { |
fd40b0b3d849
8152616: com.sun.tools.javac.tree.Pretty generates nested comments for enum
sdama
parents:
47268
diff
changeset
|
673 |
print(" "); |
fd40b0b3d849
8152616: com.sun.tools.javac.tree.Pretty generates nested comments for enum
sdama
parents:
47268
diff
changeset
|
674 |
printBlock(init.def.defs); |
fd40b0b3d849
8152616: com.sun.tools.javac.tree.Pretty generates nested comments for enum
sdama
parents:
47268
diff
changeset
|
675 |
} |
fd40b0b3d849
8152616: com.sun.tools.javac.tree.Pretty generates nested comments for enum
sdama
parents:
47268
diff
changeset
|
676 |
return; |
4413
2ae470f0b492
6902720: javac pretty printer does not handle enums correctly
jjg
parents:
3149
diff
changeset
|
677 |
} |
2ae470f0b492
6902720: javac pretty printer does not handle enums correctly
jjg
parents:
3149
diff
changeset
|
678 |
} |
10 | 679 |
print(" /* = "); |
680 |
printExpr(tree.init); |
|
681 |
print(" */"); |
|
682 |
} |
|
683 |
} else { |
|
684 |
printExpr(tree.mods); |
|
685 |
if ((tree.mods.flags & VARARGS) != 0) { |
|
15385 | 686 |
JCTree vartype = tree.vartype; |
687 |
List<JCAnnotation> tas = null; |
|
688 |
if (vartype instanceof JCAnnotatedType) { |
|
689 |
tas = ((JCAnnotatedType)vartype).annotations; |
|
690 |
vartype = ((JCAnnotatedType)vartype).underlyingType; |
|
691 |
} |
|
692 |
printExpr(((JCArrayTypeTree) vartype).elemtype); |
|
17578 | 693 |
if (tas != null) { |
694 |
print(' '); |
|
15385 | 695 |
printTypeAnnotations(tas); |
17578 | 696 |
} |
10 | 697 |
print("... " + tree.name); |
698 |
} else { |
|
699 |
printExpr(tree.vartype); |
|
700 |
print(" " + tree.name); |
|
701 |
} |
|
702 |
if (tree.init != null) { |
|
703 |
print(" = "); |
|
704 |
printExpr(tree.init); |
|
705 |
} |
|
706 |
if (prec == TreeInfo.notExpression) print(";"); |
|
707 |
} |
|
708 |
} catch (IOException e) { |
|
709 |
throw new UncheckedIOException(e); |
|
710 |
} |
|
711 |
} |
|
712 |
||
713 |
public void visitSkip(JCSkip tree) { |
|
714 |
try { |
|
715 |
print(";"); |
|
716 |
} catch (IOException e) { |
|
717 |
throw new UncheckedIOException(e); |
|
718 |
} |
|
719 |
} |
|
720 |
||
721 |
public void visitBlock(JCBlock tree) { |
|
722 |
try { |
|
723 |
printFlags(tree.flags); |
|
724 |
printBlock(tree.stats); |
|
725 |
} catch (IOException e) { |
|
726 |
throw new UncheckedIOException(e); |
|
727 |
} |
|
728 |
} |
|
729 |
||
730 |
public void visitDoLoop(JCDoWhileLoop tree) { |
|
731 |
try { |
|
732 |
print("do "); |
|
733 |
printStat(tree.body); |
|
734 |
align(); |
|
735 |
print(" while "); |
|
10950 | 736 |
if (tree.cond.hasTag(PARENS)) { |
10 | 737 |
printExpr(tree.cond); |
738 |
} else { |
|
739 |
print("("); |
|
740 |
printExpr(tree.cond); |
|
741 |
print(")"); |
|
742 |
} |
|
743 |
print(";"); |
|
744 |
} catch (IOException e) { |
|
745 |
throw new UncheckedIOException(e); |
|
746 |
} |
|
747 |
} |
|
748 |
||
749 |
public void visitWhileLoop(JCWhileLoop tree) { |
|
750 |
try { |
|
751 |
print("while "); |
|
10950 | 752 |
if (tree.cond.hasTag(PARENS)) { |
10 | 753 |
printExpr(tree.cond); |
754 |
} else { |
|
755 |
print("("); |
|
756 |
printExpr(tree.cond); |
|
757 |
print(")"); |
|
758 |
} |
|
759 |
print(" "); |
|
760 |
printStat(tree.body); |
|
761 |
} catch (IOException e) { |
|
762 |
throw new UncheckedIOException(e); |
|
763 |
} |
|
764 |
} |
|
765 |
||
766 |
public void visitForLoop(JCForLoop tree) { |
|
767 |
try { |
|
768 |
print("for ("); |
|
769 |
if (tree.init.nonEmpty()) { |
|
10950 | 770 |
if (tree.init.head.hasTag(VARDEF)) { |
10 | 771 |
printExpr(tree.init.head); |
772 |
for (List<JCStatement> l = tree.init.tail; l.nonEmpty(); l = l.tail) { |
|
773 |
JCVariableDecl vdef = (JCVariableDecl)l.head; |
|
39091 | 774 |
print(", " + vdef.name); |
775 |
if (vdef.init != null) { |
|
776 |
print(" = "); |
|
777 |
printExpr(vdef.init); |
|
778 |
} |
|
10 | 779 |
} |
780 |
} else { |
|
781 |
printExprs(tree.init); |
|
782 |
} |
|
783 |
} |
|
784 |
print("; "); |
|
785 |
if (tree.cond != null) printExpr(tree.cond); |
|
786 |
print("; "); |
|
787 |
printExprs(tree.step); |
|
788 |
print(") "); |
|
789 |
printStat(tree.body); |
|
790 |
} catch (IOException e) { |
|
791 |
throw new UncheckedIOException(e); |
|
792 |
} |
|
793 |
} |
|
794 |
||
795 |
public void visitForeachLoop(JCEnhancedForLoop tree) { |
|
796 |
try { |
|
797 |
print("for ("); |
|
798 |
printExpr(tree.var); |
|
799 |
print(" : "); |
|
800 |
printExpr(tree.expr); |
|
801 |
print(") "); |
|
802 |
printStat(tree.body); |
|
803 |
} catch (IOException e) { |
|
804 |
throw new UncheckedIOException(e); |
|
805 |
} |
|
806 |
} |
|
807 |
||
808 |
public void visitLabelled(JCLabeledStatement tree) { |
|
809 |
try { |
|
810 |
print(tree.label + ": "); |
|
811 |
printStat(tree.body); |
|
812 |
} catch (IOException e) { |
|
813 |
throw new UncheckedIOException(e); |
|
814 |
} |
|
815 |
} |
|
816 |
||
817 |
public void visitSwitch(JCSwitch tree) { |
|
818 |
try { |
|
819 |
print("switch "); |
|
10950 | 820 |
if (tree.selector.hasTag(PARENS)) { |
10 | 821 |
printExpr(tree.selector); |
822 |
} else { |
|
823 |
print("("); |
|
824 |
printExpr(tree.selector); |
|
825 |
print(")"); |
|
826 |
} |
|
827 |
print(" {"); |
|
828 |
println(); |
|
829 |
printStats(tree.cases); |
|
830 |
align(); |
|
831 |
print("}"); |
|
832 |
} catch (IOException e) { |
|
833 |
throw new UncheckedIOException(e); |
|
834 |
} |
|
835 |
} |
|
836 |
||
837 |
public void visitCase(JCCase tree) { |
|
838 |
try { |
|
51563
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
48749
diff
changeset
|
839 |
if (tree.pats.isEmpty()) { |
10 | 840 |
print("default"); |
841 |
} else { |
|
842 |
print("case "); |
|
51563
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
48749
diff
changeset
|
843 |
printExprs(tree.pats); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
48749
diff
changeset
|
844 |
} |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
48749
diff
changeset
|
845 |
if (tree.caseKind == JCCase.STATEMENT) { |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
48749
diff
changeset
|
846 |
print(":"); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
48749
diff
changeset
|
847 |
println(); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
48749
diff
changeset
|
848 |
indent(); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
48749
diff
changeset
|
849 |
printStats(tree.stats); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
48749
diff
changeset
|
850 |
undent(); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
48749
diff
changeset
|
851 |
align(); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
48749
diff
changeset
|
852 |
} else { |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
48749
diff
changeset
|
853 |
print(" -> "); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
48749
diff
changeset
|
854 |
printStat(tree.stats.head); |
10 | 855 |
} |
51563
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
48749
diff
changeset
|
856 |
} catch (IOException e) { |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
48749
diff
changeset
|
857 |
throw new UncheckedIOException(e); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
48749
diff
changeset
|
858 |
} |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
48749
diff
changeset
|
859 |
} |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
48749
diff
changeset
|
860 |
|
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
48749
diff
changeset
|
861 |
public void visitSwitchExpression(JCSwitchExpression tree) { |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
48749
diff
changeset
|
862 |
try { |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
48749
diff
changeset
|
863 |
print("switch "); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
48749
diff
changeset
|
864 |
if (tree.selector.hasTag(PARENS)) { |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
48749
diff
changeset
|
865 |
printExpr(tree.selector); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
48749
diff
changeset
|
866 |
} else { |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
48749
diff
changeset
|
867 |
print("("); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
48749
diff
changeset
|
868 |
printExpr(tree.selector); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
48749
diff
changeset
|
869 |
print(")"); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
48749
diff
changeset
|
870 |
} |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
48749
diff
changeset
|
871 |
print(" {"); |
10 | 872 |
println(); |
51563
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
48749
diff
changeset
|
873 |
printStats(tree.cases); |
10 | 874 |
align(); |
51563
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
48749
diff
changeset
|
875 |
print("}"); |
10 | 876 |
} catch (IOException e) { |
877 |
throw new UncheckedIOException(e); |
|
878 |
} |
|
879 |
} |
|
880 |
||
881 |
public void visitSynchronized(JCSynchronized tree) { |
|
882 |
try { |
|
883 |
print("synchronized "); |
|
10950 | 884 |
if (tree.lock.hasTag(PARENS)) { |
10 | 885 |
printExpr(tree.lock); |
886 |
} else { |
|
887 |
print("("); |
|
888 |
printExpr(tree.lock); |
|
889 |
print(")"); |
|
890 |
} |
|
891 |
print(" "); |
|
892 |
printStat(tree.body); |
|
893 |
} catch (IOException e) { |
|
894 |
throw new UncheckedIOException(e); |
|
895 |
} |
|
896 |
} |
|
897 |
||
898 |
public void visitTry(JCTry tree) { |
|
899 |
try { |
|
900 |
print("try "); |
|
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5847
diff
changeset
|
901 |
if (tree.resources.nonEmpty()) { |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5847
diff
changeset
|
902 |
print("("); |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5847
diff
changeset
|
903 |
boolean first = true; |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5847
diff
changeset
|
904 |
for (JCTree var : tree.resources) { |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5847
diff
changeset
|
905 |
if (!first) { |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5847
diff
changeset
|
906 |
println(); |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5847
diff
changeset
|
907 |
indent(); |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5847
diff
changeset
|
908 |
} |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5847
diff
changeset
|
909 |
printStat(var); |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5847
diff
changeset
|
910 |
first = false; |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5847
diff
changeset
|
911 |
} |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5847
diff
changeset
|
912 |
print(") "); |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5847
diff
changeset
|
913 |
} |
10 | 914 |
printStat(tree.body); |
915 |
for (List<JCCatch> l = tree.catchers; l.nonEmpty(); l = l.tail) { |
|
916 |
printStat(l.head); |
|
917 |
} |
|
918 |
if (tree.finalizer != null) { |
|
919 |
print(" finally "); |
|
920 |
printStat(tree.finalizer); |
|
921 |
} |
|
922 |
} catch (IOException e) { |
|
923 |
throw new UncheckedIOException(e); |
|
924 |
} |
|
925 |
} |
|
926 |
||
927 |
public void visitCatch(JCCatch tree) { |
|
928 |
try { |
|
929 |
print(" catch ("); |
|
930 |
printExpr(tree.param); |
|
931 |
print(") "); |
|
932 |
printStat(tree.body); |
|
933 |
} catch (IOException e) { |
|
934 |
throw new UncheckedIOException(e); |
|
935 |
} |
|
936 |
} |
|
937 |
||
938 |
public void visitConditional(JCConditional tree) { |
|
939 |
try { |
|
940 |
open(prec, TreeInfo.condPrec); |
|
21004
dc81ffd21bd3
8024415: Bug in javac Pretty: Wrong precedence in JCConditional trees
alundblad
parents:
19651
diff
changeset
|
941 |
printExpr(tree.cond, TreeInfo.condPrec + 1); |
10 | 942 |
print(" ? "); |
21004
dc81ffd21bd3
8024415: Bug in javac Pretty: Wrong precedence in JCConditional trees
alundblad
parents:
19651
diff
changeset
|
943 |
printExpr(tree.truepart); |
10 | 944 |
print(" : "); |
945 |
printExpr(tree.falsepart, TreeInfo.condPrec); |
|
946 |
close(prec, TreeInfo.condPrec); |
|
947 |
} catch (IOException e) { |
|
948 |
throw new UncheckedIOException(e); |
|
949 |
} |
|
950 |
} |
|
951 |
||
952 |
public void visitIf(JCIf tree) { |
|
953 |
try { |
|
954 |
print("if "); |
|
10950 | 955 |
if (tree.cond.hasTag(PARENS)) { |
10 | 956 |
printExpr(tree.cond); |
957 |
} else { |
|
958 |
print("("); |
|
959 |
printExpr(tree.cond); |
|
960 |
print(")"); |
|
961 |
} |
|
962 |
print(" "); |
|
963 |
printStat(tree.thenpart); |
|
964 |
if (tree.elsepart != null) { |
|
965 |
print(" else "); |
|
966 |
printStat(tree.elsepart); |
|
967 |
} |
|
968 |
} catch (IOException e) { |
|
969 |
throw new UncheckedIOException(e); |
|
970 |
} |
|
971 |
} |
|
972 |
||
973 |
public void visitExec(JCExpressionStatement tree) { |
|
974 |
try { |
|
975 |
printExpr(tree.expr); |
|
976 |
if (prec == TreeInfo.notExpression) print(";"); |
|
977 |
} catch (IOException e) { |
|
978 |
throw new UncheckedIOException(e); |
|
979 |
} |
|
980 |
} |
|
981 |
||
982 |
public void visitBreak(JCBreak tree) { |
|
983 |
try { |
|
984 |
print("break"); |
|
51563
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
48749
diff
changeset
|
985 |
if (tree.value != null) print(" " + tree.value); |
10 | 986 |
print(";"); |
987 |
} catch (IOException e) { |
|
988 |
throw new UncheckedIOException(e); |
|
989 |
} |
|
990 |
} |
|
991 |
||
992 |
public void visitContinue(JCContinue tree) { |
|
993 |
try { |
|
994 |
print("continue"); |
|
995 |
if (tree.label != null) print(" " + tree.label); |
|
996 |
print(";"); |
|
997 |
} catch (IOException e) { |
|
998 |
throw new UncheckedIOException(e); |
|
999 |
} |
|
1000 |
} |
|
1001 |
||
1002 |
public void visitReturn(JCReturn tree) { |
|
1003 |
try { |
|
1004 |
print("return"); |
|
1005 |
if (tree.expr != null) { |
|
1006 |
print(" "); |
|
1007 |
printExpr(tree.expr); |
|
1008 |
} |
|
1009 |
print(";"); |
|
1010 |
} catch (IOException e) { |
|
1011 |
throw new UncheckedIOException(e); |
|
1012 |
} |
|
1013 |
} |
|
1014 |
||
1015 |
public void visitThrow(JCThrow tree) { |
|
1016 |
try { |
|
1017 |
print("throw "); |
|
1018 |
printExpr(tree.expr); |
|
1019 |
print(";"); |
|
1020 |
} catch (IOException e) { |
|
1021 |
throw new UncheckedIOException(e); |
|
1022 |
} |
|
1023 |
} |
|
1024 |
||
1025 |
public void visitAssert(JCAssert tree) { |
|
1026 |
try { |
|
1027 |
print("assert "); |
|
1028 |
printExpr(tree.cond); |
|
1029 |
if (tree.detail != null) { |
|
1030 |
print(" : "); |
|
1031 |
printExpr(tree.detail); |
|
1032 |
} |
|
1033 |
print(";"); |
|
1034 |
} catch (IOException e) { |
|
1035 |
throw new UncheckedIOException(e); |
|
1036 |
} |
|
1037 |
} |
|
1038 |
||
1039 |
public void visitApply(JCMethodInvocation tree) { |
|
1040 |
try { |
|
1041 |
if (!tree.typeargs.isEmpty()) { |
|
10950 | 1042 |
if (tree.meth.hasTag(SELECT)) { |
10 | 1043 |
JCFieldAccess left = (JCFieldAccess)tree.meth; |
1044 |
printExpr(left.selected); |
|
1045 |
print(".<"); |
|
1046 |
printExprs(tree.typeargs); |
|
1047 |
print(">" + left.name); |
|
1048 |
} else { |
|
1049 |
print("<"); |
|
1050 |
printExprs(tree.typeargs); |
|
1051 |
print(">"); |
|
1052 |
printExpr(tree.meth); |
|
1053 |
} |
|
1054 |
} else { |
|
1055 |
printExpr(tree.meth); |
|
1056 |
} |
|
1057 |
print("("); |
|
1058 |
printExprs(tree.args); |
|
1059 |
print(")"); |
|
1060 |
} catch (IOException e) { |
|
1061 |
throw new UncheckedIOException(e); |
|
1062 |
} |
|
1063 |
} |
|
1064 |
||
1065 |
public void visitNewClass(JCNewClass tree) { |
|
1066 |
try { |
|
1067 |
if (tree.encl != null) { |
|
1068 |
printExpr(tree.encl); |
|
1069 |
print("."); |
|
1070 |
} |
|
1071 |
print("new "); |
|
1072 |
if (!tree.typeargs.isEmpty()) { |
|
1073 |
print("<"); |
|
1074 |
printExprs(tree.typeargs); |
|
1075 |
print(">"); |
|
1076 |
} |
|
17578 | 1077 |
if (tree.def != null && tree.def.mods.annotations.nonEmpty()) { |
1078 |
printTypeAnnotations(tree.def.mods.annotations); |
|
1079 |
} |
|
10 | 1080 |
printExpr(tree.clazz); |
1081 |
print("("); |
|
1082 |
printExprs(tree.args); |
|
1083 |
print(")"); |
|
1084 |
if (tree.def != null) { |
|
1085 |
Name enclClassNamePrev = enclClassName; |
|
1086 |
enclClassName = |
|
1087 |
tree.def.name != null ? tree.def.name : |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
1088 |
tree.type != null && tree.type.tsym.name != tree.type.tsym.name.table.names.empty |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
1089 |
? tree.type.tsym.name : null; |
10 | 1090 |
if ((tree.def.mods.flags & Flags.ENUM) != 0) print("/*enum*/"); |
1091 |
printBlock(tree.def.defs); |
|
1092 |
enclClassName = enclClassNamePrev; |
|
1093 |
} |
|
1094 |
} catch (IOException e) { |
|
1095 |
throw new UncheckedIOException(e); |
|
1096 |
} |
|
1097 |
} |
|
1098 |
||
1099 |
public void visitNewArray(JCNewArray tree) { |
|
1100 |
try { |
|
1101 |
if (tree.elemtype != null) { |
|
1102 |
print("new "); |
|
1103 |
JCTree elem = tree.elemtype; |
|
15385 | 1104 |
printBaseElementType(elem); |
19651 | 1105 |
|
1106 |
if (!tree.annotations.isEmpty()) { |
|
1107 |
print(' '); |
|
1108 |
printTypeAnnotations(tree.annotations); |
|
1109 |
} |
|
1110 |
if (tree.elems != null) { |
|
1111 |
print("[]"); |
|
1112 |
} |
|
1113 |
||
15385 | 1114 |
int i = 0; |
1115 |
List<List<JCAnnotation>> da = tree.dimAnnotations; |
|
10 | 1116 |
for (List<JCExpression> l = tree.dims; l.nonEmpty(); l = l.tail) { |
17578 | 1117 |
if (da.size() > i && !da.get(i).isEmpty()) { |
1118 |
print(' '); |
|
15385 | 1119 |
printTypeAnnotations(da.get(i)); |
1120 |
} |
|
10 | 1121 |
print("["); |
15385 | 1122 |
i++; |
10 | 1123 |
printExpr(l.head); |
1124 |
print("]"); |
|
1125 |
} |
|
19651 | 1126 |
printBrackets(elem); |
10 | 1127 |
} |
1128 |
if (tree.elems != null) { |
|
1129 |
print("{"); |
|
1130 |
printExprs(tree.elems); |
|
1131 |
print("}"); |
|
1132 |
} |
|
1133 |
} catch (IOException e) { |
|
1134 |
throw new UncheckedIOException(e); |
|
1135 |
} |
|
1136 |
} |
|
1137 |
||
11141 | 1138 |
public void visitLambda(JCLambda tree) { |
1139 |
try { |
|
1140 |
print("("); |
|
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15044
diff
changeset
|
1141 |
if (tree.paramKind == JCLambda.ParameterKind.EXPLICIT) { |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1142 |
printExprs(tree.params); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1143 |
} else { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1144 |
String sep = ""; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1145 |
for (JCVariableDecl param : tree.params) { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1146 |
print(sep); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1147 |
print(param.name); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1148 |
sep = ","; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1149 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1150 |
} |
11141 | 1151 |
print(")->"); |
1152 |
printExpr(tree.body); |
|
1153 |
} catch (IOException e) { |
|
1154 |
throw new UncheckedIOException(e); |
|
1155 |
} |
|
1156 |
} |
|
1157 |
||
10 | 1158 |
public void visitParens(JCParens tree) { |
1159 |
try { |
|
1160 |
print("("); |
|
1161 |
printExpr(tree.expr); |
|
1162 |
print(")"); |
|
1163 |
} catch (IOException e) { |
|
1164 |
throw new UncheckedIOException(e); |
|
1165 |
} |
|
1166 |
} |
|
1167 |
||
1168 |
public void visitAssign(JCAssign tree) { |
|
1169 |
try { |
|
1170 |
open(prec, TreeInfo.assignPrec); |
|
1171 |
printExpr(tree.lhs, TreeInfo.assignPrec + 1); |
|
1172 |
print(" = "); |
|
1173 |
printExpr(tree.rhs, TreeInfo.assignPrec); |
|
1174 |
close(prec, TreeInfo.assignPrec); |
|
1175 |
} catch (IOException e) { |
|
1176 |
throw new UncheckedIOException(e); |
|
1177 |
} |
|
1178 |
} |
|
1179 |
||
10950 | 1180 |
public String operatorName(JCTree.Tag tag) { |
10 | 1181 |
switch(tag) { |
10950 | 1182 |
case POS: return "+"; |
1183 |
case NEG: return "-"; |
|
1184 |
case NOT: return "!"; |
|
1185 |
case COMPL: return "~"; |
|
1186 |
case PREINC: return "++"; |
|
1187 |
case PREDEC: return "--"; |
|
1188 |
case POSTINC: return "++"; |
|
1189 |
case POSTDEC: return "--"; |
|
1190 |
case NULLCHK: return "<*nullchk*>"; |
|
1191 |
case OR: return "||"; |
|
1192 |
case AND: return "&&"; |
|
1193 |
case EQ: return "=="; |
|
1194 |
case NE: return "!="; |
|
1195 |
case LT: return "<"; |
|
1196 |
case GT: return ">"; |
|
1197 |
case LE: return "<="; |
|
1198 |
case GE: return ">="; |
|
1199 |
case BITOR: return "|"; |
|
1200 |
case BITXOR: return "^"; |
|
1201 |
case BITAND: return "&"; |
|
1202 |
case SL: return "<<"; |
|
1203 |
case SR: return ">>"; |
|
1204 |
case USR: return ">>>"; |
|
1205 |
case PLUS: return "+"; |
|
1206 |
case MINUS: return "-"; |
|
1207 |
case MUL: return "*"; |
|
1208 |
case DIV: return "/"; |
|
1209 |
case MOD: return "%"; |
|
10 | 1210 |
default: throw new Error(); |
1211 |
} |
|
1212 |
} |
|
1213 |
||
1214 |
public void visitAssignop(JCAssignOp tree) { |
|
1215 |
try { |
|
1216 |
open(prec, TreeInfo.assignopPrec); |
|
1217 |
printExpr(tree.lhs, TreeInfo.assignopPrec + 1); |
|
10950 | 1218 |
print(" " + operatorName(tree.getTag().noAssignOp()) + "= "); |
10 | 1219 |
printExpr(tree.rhs, TreeInfo.assignopPrec); |
1220 |
close(prec, TreeInfo.assignopPrec); |
|
1221 |
} catch (IOException e) { |
|
1222 |
throw new UncheckedIOException(e); |
|
1223 |
} |
|
1224 |
} |
|
1225 |
||
1226 |
public void visitUnary(JCUnary tree) { |
|
1227 |
try { |
|
1228 |
int ownprec = TreeInfo.opPrec(tree.getTag()); |
|
1229 |
String opname = operatorName(tree.getTag()); |
|
1230 |
open(prec, ownprec); |
|
10950 | 1231 |
if (!tree.getTag().isPostUnaryOp()) { |
10 | 1232 |
print(opname); |
1233 |
printExpr(tree.arg, ownprec); |
|
1234 |
} else { |
|
1235 |
printExpr(tree.arg, ownprec); |
|
1236 |
print(opname); |
|
1237 |
} |
|
1238 |
close(prec, ownprec); |
|
1239 |
} catch (IOException e) { |
|
1240 |
throw new UncheckedIOException(e); |
|
1241 |
} |
|
1242 |
} |
|
1243 |
||
1244 |
public void visitBinary(JCBinary tree) { |
|
1245 |
try { |
|
1246 |
int ownprec = TreeInfo.opPrec(tree.getTag()); |
|
1247 |
String opname = operatorName(tree.getTag()); |
|
1248 |
open(prec, ownprec); |
|
1249 |
printExpr(tree.lhs, ownprec); |
|
1250 |
print(" " + opname + " "); |
|
1251 |
printExpr(tree.rhs, ownprec + 1); |
|
1252 |
close(prec, ownprec); |
|
1253 |
} catch (IOException e) { |
|
1254 |
throw new UncheckedIOException(e); |
|
1255 |
} |
|
1256 |
} |
|
1257 |
||
1258 |
public void visitTypeCast(JCTypeCast tree) { |
|
1259 |
try { |
|
1260 |
open(prec, TreeInfo.prefixPrec); |
|
1261 |
print("("); |
|
1262 |
printExpr(tree.clazz); |
|
1263 |
print(")"); |
|
1264 |
printExpr(tree.expr, TreeInfo.prefixPrec); |
|
1265 |
close(prec, TreeInfo.prefixPrec); |
|
1266 |
} catch (IOException e) { |
|
1267 |
throw new UncheckedIOException(e); |
|
1268 |
} |
|
1269 |
} |
|
1270 |
||
1271 |
public void visitTypeTest(JCInstanceOf tree) { |
|
1272 |
try { |
|
1273 |
open(prec, TreeInfo.ordPrec); |
|
1274 |
printExpr(tree.expr, TreeInfo.ordPrec); |
|
1275 |
print(" instanceof "); |
|
1276 |
printExpr(tree.clazz, TreeInfo.ordPrec + 1); |
|
1277 |
close(prec, TreeInfo.ordPrec); |
|
1278 |
} catch (IOException e) { |
|
1279 |
throw new UncheckedIOException(e); |
|
1280 |
} |
|
1281 |
} |
|
1282 |
||
1283 |
public void visitIndexed(JCArrayAccess tree) { |
|
1284 |
try { |
|
1285 |
printExpr(tree.indexed, TreeInfo.postfixPrec); |
|
1286 |
print("["); |
|
1287 |
printExpr(tree.index); |
|
1288 |
print("]"); |
|
1289 |
} catch (IOException e) { |
|
1290 |
throw new UncheckedIOException(e); |
|
1291 |
} |
|
1292 |
} |
|
1293 |
||
1294 |
public void visitSelect(JCFieldAccess tree) { |
|
1295 |
try { |
|
1296 |
printExpr(tree.selected, TreeInfo.postfixPrec); |
|
1297 |
print("." + tree.name); |
|
1298 |
} catch (IOException e) { |
|
1299 |
throw new UncheckedIOException(e); |
|
1300 |
} |
|
1301 |
} |
|
1302 |
||
11142 | 1303 |
public void visitReference(JCMemberReference tree) { |
1304 |
try { |
|
1305 |
printExpr(tree.expr); |
|
14547 | 1306 |
print("::"); |
11142 | 1307 |
if (tree.typeargs != null) { |
1308 |
print("<"); |
|
1309 |
printExprs(tree.typeargs); |
|
1310 |
print(">"); |
|
1311 |
} |
|
1312 |
print(tree.getMode() == ReferenceMode.INVOKE ? tree.name : "new"); |
|
1313 |
} catch (IOException e) { |
|
1314 |
throw new UncheckedIOException(e); |
|
1315 |
} |
|
1316 |
} |
|
1317 |
||
10 | 1318 |
public void visitIdent(JCIdent tree) { |
1319 |
try { |
|
1320 |
print(tree.name); |
|
1321 |
} catch (IOException e) { |
|
1322 |
throw new UncheckedIOException(e); |
|
1323 |
} |
|
1324 |
} |
|
1325 |
||
1326 |
public void visitLiteral(JCLiteral tree) { |
|
1327 |
try { |
|
1328 |
switch (tree.typetag) { |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
1329 |
case INT: |
10 | 1330 |
print(tree.value.toString()); |
1331 |
break; |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
1332 |
case LONG: |
10 | 1333 |
print(tree.value + "L"); |
1334 |
break; |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
1335 |
case FLOAT: |
10 | 1336 |
print(tree.value + "F"); |
1337 |
break; |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
1338 |
case DOUBLE: |
10 | 1339 |
print(tree.value.toString()); |
1340 |
break; |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
1341 |
case CHAR: |
10 | 1342 |
print("\'" + |
1343 |
Convert.quote( |
|
1344 |
String.valueOf((char)((Number)tree.value).intValue())) + |
|
1345 |
"\'"); |
|
1346 |
break; |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
1347 |
case BOOLEAN: |
10 | 1348 |
print(((Number)tree.value).intValue() == 1 ? "true" : "false"); |
1349 |
break; |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
1350 |
case BOT: |
10 | 1351 |
print("null"); |
1352 |
break; |
|
1353 |
default: |
|
1354 |
print("\"" + Convert.quote(tree.value.toString()) + "\""); |
|
1355 |
break; |
|
1356 |
} |
|
1357 |
} catch (IOException e) { |
|
1358 |
throw new UncheckedIOException(e); |
|
1359 |
} |
|
1360 |
} |
|
1361 |
||
1362 |
public void visitTypeIdent(JCPrimitiveTypeTree tree) { |
|
1363 |
try { |
|
1364 |
switch(tree.typetag) { |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
1365 |
case BYTE: |
10 | 1366 |
print("byte"); |
1367 |
break; |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
1368 |
case CHAR: |
10 | 1369 |
print("char"); |
1370 |
break; |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
1371 |
case SHORT: |
10 | 1372 |
print("short"); |
1373 |
break; |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
1374 |
case INT: |
10 | 1375 |
print("int"); |
1376 |
break; |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
1377 |
case LONG: |
10 | 1378 |
print("long"); |
1379 |
break; |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
1380 |
case FLOAT: |
10 | 1381 |
print("float"); |
1382 |
break; |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
1383 |
case DOUBLE: |
10 | 1384 |
print("double"); |
1385 |
break; |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
1386 |
case BOOLEAN: |
10 | 1387 |
print("boolean"); |
1388 |
break; |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
1389 |
case VOID: |
10 | 1390 |
print("void"); |
1391 |
break; |
|
1392 |
default: |
|
1393 |
print("error"); |
|
1394 |
break; |
|
1395 |
} |
|
1396 |
} catch (IOException e) { |
|
1397 |
throw new UncheckedIOException(e); |
|
1398 |
} |
|
1399 |
} |
|
1400 |
||
1401 |
public void visitTypeArray(JCArrayTypeTree tree) { |
|
1402 |
try { |
|
1403 |
printBaseElementType(tree); |
|
1404 |
printBrackets(tree); |
|
1405 |
} catch (IOException e) { |
|
1406 |
throw new UncheckedIOException(e); |
|
1407 |
} |
|
1408 |
} |
|
1409 |
||
1410 |
// Prints the inner element type of a nested array |
|
3149 | 1411 |
private void printBaseElementType(JCTree tree) throws IOException { |
47268
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
1412 |
printExpr(TreeInfo.innermostType(tree, false)); |
10 | 1413 |
} |
1414 |
||
1415 |
// prints the brackets of a nested array in reverse order |
|
19651 | 1416 |
// tree is either JCArrayTypeTree or JCAnnotatedTypeTree |
1417 |
private void printBrackets(JCTree tree) throws IOException { |
|
1418 |
JCTree elem = tree; |
|
10 | 1419 |
while (true) { |
15385 | 1420 |
if (elem.hasTag(ANNOTATED_TYPE)) { |
1421 |
JCAnnotatedType atype = (JCAnnotatedType) elem; |
|
1422 |
elem = atype.underlyingType; |
|
19651 | 1423 |
if (elem.hasTag(TYPEARRAY)) { |
1424 |
print(' '); |
|
1425 |
printTypeAnnotations(atype.annotations); |
|
1426 |
} |
|
15385 | 1427 |
} |
19651 | 1428 |
if (elem.hasTag(TYPEARRAY)) { |
1429 |
print("[]"); |
|
1430 |
elem = ((JCArrayTypeTree)elem).elemtype; |
|
1431 |
} else { |
|
1432 |
break; |
|
1433 |
} |
|
10 | 1434 |
} |
1435 |
} |
|
1436 |
||
1437 |
public void visitTypeApply(JCTypeApply tree) { |
|
1438 |
try { |
|
1439 |
printExpr(tree.clazz); |
|
1440 |
print("<"); |
|
1441 |
printExprs(tree.arguments); |
|
1442 |
print(">"); |
|
1443 |
} catch (IOException e) { |
|
1444 |
throw new UncheckedIOException(e); |
|
1445 |
} |
|
1446 |
} |
|
1447 |
||
9300
c2de4dd9853b
7033809: Rename "disjunctive" to "union" in javax.lang.model
darcy
parents:
8031
diff
changeset
|
1448 |
public void visitTypeUnion(JCTypeUnion tree) { |
5492
515e4b33b335
6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents:
4705
diff
changeset
|
1449 |
try { |
7074 | 1450 |
printExprs(tree.alternatives, " | "); |
5492
515e4b33b335
6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents:
4705
diff
changeset
|
1451 |
} catch (IOException e) { |
515e4b33b335
6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents:
4705
diff
changeset
|
1452 |
throw new UncheckedIOException(e); |
515e4b33b335
6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents:
4705
diff
changeset
|
1453 |
} |
515e4b33b335
6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents:
4705
diff
changeset
|
1454 |
} |
515e4b33b335
6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents:
4705
diff
changeset
|
1455 |
|
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14547
diff
changeset
|
1456 |
public void visitTypeIntersection(JCTypeIntersection tree) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14547
diff
changeset
|
1457 |
try { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14547
diff
changeset
|
1458 |
printExprs(tree.bounds, " & "); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14547
diff
changeset
|
1459 |
} catch (IOException e) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14547
diff
changeset
|
1460 |
throw new UncheckedIOException(e); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14547
diff
changeset
|
1461 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14547
diff
changeset
|
1462 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14547
diff
changeset
|
1463 |
|
10 | 1464 |
public void visitTypeParameter(JCTypeParameter tree) { |
1465 |
try { |
|
17578 | 1466 |
if (tree.annotations.nonEmpty()) { |
1467 |
this.printTypeAnnotations(tree.annotations); |
|
1468 |
} |
|
10 | 1469 |
print(tree.name); |
1470 |
if (tree.bounds.nonEmpty()) { |
|
1471 |
print(" extends "); |
|
1472 |
printExprs(tree.bounds, " & "); |
|
1473 |
} |
|
1474 |
} catch (IOException e) { |
|
1475 |
throw new UncheckedIOException(e); |
|
1476 |
} |
|
1477 |
} |
|
1478 |
||
1479 |
@Override |
|
1480 |
public void visitWildcard(JCWildcard tree) { |
|
1481 |
try { |
|
1482 |
print(tree.kind); |
|
1483 |
if (tree.kind.kind != BoundKind.UNBOUND) |
|
1484 |
printExpr(tree.inner); |
|
1485 |
} catch (IOException e) { |
|
1486 |
throw new UncheckedIOException(e); |
|
1487 |
} |
|
1488 |
} |
|
1489 |
||
1490 |
@Override |
|
1491 |
public void visitTypeBoundKind(TypeBoundKind tree) { |
|
1492 |
try { |
|
1493 |
print(String.valueOf(tree.kind)); |
|
1494 |
} catch (IOException e) { |
|
1495 |
throw new UncheckedIOException(e); |
|
1496 |
} |
|
1497 |
} |
|
1498 |
||
1499 |
public void visitErroneous(JCErroneous tree) { |
|
1500 |
try { |
|
1501 |
print("(ERROR)"); |
|
1502 |
} catch (IOException e) { |
|
1503 |
throw new UncheckedIOException(e); |
|
1504 |
} |
|
1505 |
} |
|
1506 |
||
1507 |
public void visitLetExpr(LetExpr tree) { |
|
1508 |
try { |
|
1509 |
print("(let " + tree.defs + " in " + tree.expr + ")"); |
|
1510 |
} catch (IOException e) { |
|
1511 |
throw new UncheckedIOException(e); |
|
1512 |
} |
|
1513 |
} |
|
1514 |
||
1515 |
public void visitModifiers(JCModifiers mods) { |
|
1516 |
try { |
|
1517 |
printAnnotations(mods.annotations); |
|
1518 |
printFlags(mods.flags); |
|
1519 |
} catch (IOException e) { |
|
1520 |
throw new UncheckedIOException(e); |
|
1521 |
} |
|
1522 |
} |
|
1523 |
||
1524 |
public void visitAnnotation(JCAnnotation tree) { |
|
1525 |
try { |
|
1526 |
print("@"); |
|
1527 |
printExpr(tree.annotationType); |
|
52864
e78890a4c25f
8214902: Pretty-printing marker annotations add unnecessary parenthesis
cushon
parents:
51563
diff
changeset
|
1528 |
if (!tree.args.isEmpty()) { |
e78890a4c25f
8214902: Pretty-printing marker annotations add unnecessary parenthesis
cushon
parents:
51563
diff
changeset
|
1529 |
print("("); |
e78890a4c25f
8214902: Pretty-printing marker annotations add unnecessary parenthesis
cushon
parents:
51563
diff
changeset
|
1530 |
printExprs(tree.args); |
e78890a4c25f
8214902: Pretty-printing marker annotations add unnecessary parenthesis
cushon
parents:
51563
diff
changeset
|
1531 |
print(")"); |
e78890a4c25f
8214902: Pretty-printing marker annotations add unnecessary parenthesis
cushon
parents:
51563
diff
changeset
|
1532 |
} |
10 | 1533 |
} catch (IOException e) { |
1534 |
throw new UncheckedIOException(e); |
|
1535 |
} |
|
1536 |
} |
|
1537 |
||
15385 | 1538 |
public void visitAnnotatedType(JCAnnotatedType tree) { |
1539 |
try { |
|
19651 | 1540 |
if (tree.underlyingType.hasTag(SELECT)) { |
15385 | 1541 |
JCFieldAccess access = (JCFieldAccess) tree.underlyingType; |
1542 |
printExpr(access.selected, TreeInfo.postfixPrec); |
|
1543 |
print("."); |
|
1544 |
printTypeAnnotations(tree.annotations); |
|
1545 |
print(access.name); |
|
19651 | 1546 |
} else if (tree.underlyingType.hasTag(TYPEARRAY)) { |
15385 | 1547 |
printBaseElementType(tree); |
19651 | 1548 |
printBrackets(tree); |
15385 | 1549 |
} else { |
1550 |
printTypeAnnotations(tree.annotations); |
|
1551 |
printExpr(tree.underlyingType); |
|
1552 |
} |
|
1553 |
} catch (IOException e) { |
|
1554 |
throw new UncheckedIOException(e); |
|
1555 |
} |
|
1556 |
} |
|
1557 |
||
10 | 1558 |
public void visitTree(JCTree tree) { |
1559 |
try { |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
1560 |
print("(UNKNOWN: " + tree.getTag() + ")"); |
10 | 1561 |
println(); |
1562 |
} catch (IOException e) { |
|
1563 |
throw new UncheckedIOException(e); |
|
1564 |
} |
|
1565 |
} |
|
3149 | 1566 |
|
10 | 1567 |
} |