1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
package com.sun.tools.javafx.tree; |
27 | |
|
28 | |
import java.io.IOException; |
29 | |
import java.io.StringWriter; |
30 | |
import java.io.Writer; |
31 | |
import java.util.Map; |
32 | |
|
33 | |
import com.sun.javafx.api.JavafxBindStatus; |
34 | |
import com.sun.javafx.api.tree.ForExpressionInClauseTree; |
35 | |
import com.sun.javafx.api.tree.InterpolateValueTree; |
36 | |
import com.sun.javafx.api.tree.TypeTree.Cardinality; |
37 | |
import com.sun.tools.javac.tree.JCTree; |
38 | |
import com.sun.tools.javac.tree.JCTree.*; |
39 | |
import com.sun.tools.javac.tree.Pretty; |
40 | |
import com.sun.tools.javac.tree.TreeInfo; |
41 | |
import com.sun.tools.javac.util.List; |
42 | |
import com.sun.tools.javac.util.Position; |
43 | |
import java.util.Iterator; |
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | 4 | public class JavafxPretty extends Pretty implements JavafxVisitor { |
55 | |
public static final int SCOPE_OUTER = 0; |
56 | |
public static final int SCOPE_CLASS = 1; |
57 | |
public static final int SCOPE_METHOD = 2; |
58 | |
public static final int SCOPE_PARAMS = 3; |
59 | 29 | protected int variableScope = SCOPE_OUTER; |
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | 29 | Map<JCTree, String> docComments = null; |
65 | |
|
66 | |
CharSequence sourceContent; |
67 | |
|
68 | |
public JavafxPretty(Writer out, boolean sourceOutput, CharSequence content) { |
69 | 29 | super(out, sourceOutput); |
70 | 29 | sourceContent = content; |
71 | 29 | } |
72 | |
|
73 | |
public JavafxPretty(Writer out, boolean sourceOutput) { |
74 | 0 | super(out, sourceOutput); |
75 | 0 | sourceContent = null; |
76 | 0 | } |
77 | |
|
78 | |
@Override |
79 | |
public void printUnit(JCCompilationUnit tree, JCClassDecl cdef) throws IOException { |
80 | 29 | docComments = tree.docComments; |
81 | 29 | super.printUnit(tree, cdef); |
82 | 29 | } |
83 | |
|
84 | |
private String posAsString(int pos) { |
85 | 0 | if (pos == Position.NOPOS || sourceContent == null) { |
86 | 0 | return "%?%"; |
87 | |
} |
88 | 0 | int line = 1; |
89 | 0 | int bp = 0; |
90 | 0 | while (bp < sourceContent.length() && bp < pos) { |
91 | 0 | switch (sourceContent.charAt(bp++)) { |
92 | |
case 0xD: |
93 | 0 | if (bp < sourceContent.length() && sourceContent.charAt(bp) == 0xA) { |
94 | 0 | bp++; |
95 | |
} |
96 | 0 | line++; |
97 | 0 | break; |
98 | |
case 0xA: |
99 | 0 | line++; |
100 | 0 | break; |
101 | |
} |
102 | |
} |
103 | 0 | return " %(" + pos + ")" + line + "% "; |
104 | |
} |
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
@Override |
110 | |
public void printExpr(JCTree tree, int prec) throws IOException { |
111 | 598 | int prevPrec = this.prec; |
112 | |
try { |
113 | |
|
114 | |
|
115 | |
|
116 | 598 | this.prec = prec; |
117 | 598 | if (tree == null) { |
118 | 33 | print("/*missing*/"); |
119 | |
} else { |
120 | 565 | tree.accept(this); |
121 | |
} |
122 | 0 | } catch (UncheckedIOException ex) { |
123 | 0 | IOException e = new IOException(ex.getMessage()); |
124 | 0 | e.initCause(ex); |
125 | 0 | throw e; |
126 | |
} finally { |
127 | 598 | this.prec = prevPrec; |
128 | 598 | } |
129 | 598 | } |
130 | |
|
131 | |
private void printInterpolateValue(JFXInterpolateValue tree) { |
132 | |
try { |
133 | 0 | if (tree.getAttribute() != null) { |
134 | 0 | print(tree.getAttribute()); |
135 | 0 | print(':'); |
136 | |
} |
137 | 0 | print(tree.getValue()); |
138 | 0 | printTween(tree); |
139 | 0 | } catch (IOException e) { |
140 | 0 | throw new UncheckedIOException(e); |
141 | 0 | } |
142 | 0 | } |
143 | |
|
144 | |
public void visitClassDeclaration(JFXClassDeclaration tree) { |
145 | |
try { |
146 | 5 | int oldScope = variableScope; |
147 | 5 | variableScope = SCOPE_CLASS; |
148 | 5 | println(); |
149 | 5 | align(); |
150 | 5 | printDocComment(tree); |
151 | 5 | print("class "); |
152 | 5 | print(tree.getName()); |
153 | 5 | print(" {"); |
154 | 5 | println(); |
155 | 5 | indent(); |
156 | 5 | for (JCTree mem : tree.getMembers()) { |
157 | 5 | align(); |
158 | 5 | printExpr(mem); |
159 | |
} |
160 | 5 | undent(); |
161 | 5 | println(); |
162 | 5 | print("}"); |
163 | 5 | println(); |
164 | 5 | align(); |
165 | 5 | variableScope = oldScope; |
166 | 0 | } catch (IOException e) { |
167 | 0 | throw new UncheckedIOException(e); |
168 | 5 | } |
169 | 5 | } |
170 | |
|
171 | |
public static void visitFunctionValue(Pretty pretty, JFXFunctionValue tree) { |
172 | |
try { |
173 | 0 | pretty.println(); |
174 | 0 | pretty.align(); |
175 | 0 | pretty.printDocComment(tree); |
176 | 0 | pretty.print("function "); |
177 | 0 | pretty.print("("); |
178 | 0 | pretty.printExprs(tree.getParams()); |
179 | 0 | pretty.print(")"); |
180 | 0 | if (tree.getType() != null) { |
181 | 0 | pretty.printExpr(tree.getType()); |
182 | |
} |
183 | 0 | JFXBlockExpression body = tree.getBodyExpression(); |
184 | 0 | if (body != null) { |
185 | 0 | pretty.printExpr(body); |
186 | |
} |
187 | 0 | pretty.println(); |
188 | 0 | } catch (IOException e) { |
189 | 0 | throw new UncheckedIOException(e); |
190 | 0 | } |
191 | 0 | } |
192 | |
|
193 | |
public void visitFunctionValue(JFXFunctionValue tree) { |
194 | 0 | visitFunctionValue(this, tree); |
195 | 0 | } |
196 | |
|
197 | |
public static void visitFunctionDefinition(Pretty pretty, JFXFunctionDefinition tree) { |
198 | |
try { |
199 | 8 | JavafxPretty fxpretty = (JavafxPretty)pretty; |
200 | 8 | int oldScope = fxpretty.variableScope; |
201 | 8 | pretty.println(); |
202 | 8 | pretty.align(); |
203 | 8 | pretty.printDocComment(tree); |
204 | 8 | pretty.printExpr(tree.mods); |
205 | 8 | pretty.print("function "); |
206 | 8 | pretty.print(tree.name); |
207 | 8 | pretty.print("("); |
208 | 8 | fxpretty.variableScope = SCOPE_PARAMS; |
209 | 8 | pretty.printExprs(tree.getParameters()); |
210 | 8 | fxpretty.variableScope = SCOPE_METHOD; |
211 | 8 | pretty.print(")"); |
212 | 8 | pretty.printExpr(tree.operation.rettype); |
213 | 8 | JFXBlockExpression body = tree.getBodyExpression(); |
214 | 8 | if (body != null) { |
215 | 8 | pretty.print(" "); |
216 | 8 | pretty.printExpr(body); |
217 | |
} |
218 | 8 | pretty.println(); |
219 | 8 | fxpretty.variableScope = oldScope; |
220 | 0 | } catch (IOException e) { |
221 | 0 | throw new UncheckedIOException(e); |
222 | 8 | } |
223 | 8 | } |
224 | |
|
225 | |
public void visitFunctionDefinition(JFXFunctionDefinition tree) { |
226 | 8 | visitFunctionDefinition(this, tree); |
227 | 8 | } |
228 | |
|
229 | |
public void visitInitDefinition(JFXInitDefinition tree) { |
230 | |
try { |
231 | 0 | println(); |
232 | 0 | align(); |
233 | 0 | printDocComment(tree); |
234 | 0 | print("init "); |
235 | 0 | print(tree.getBody()); |
236 | 0 | println(); |
237 | 0 | } catch (IOException e) { |
238 | 0 | throw new UncheckedIOException(e); |
239 | 0 | } |
240 | 0 | } |
241 | |
|
242 | |
public void visitPostInitDefinition(JFXPostInitDefinition tree) { |
243 | |
try { |
244 | 0 | println(); |
245 | 0 | align(); |
246 | 0 | printDocComment(tree); |
247 | 0 | print("postinit "); |
248 | 0 | print(tree.getBody()); |
249 | 0 | println(); |
250 | 0 | } catch (IOException e) { |
251 | 0 | throw new UncheckedIOException(e); |
252 | 0 | } |
253 | 0 | } |
254 | |
public void visitBindExpression(JFXBindExpression tree) { |
255 | |
try { |
256 | 0 | printBind(tree.getBindStatus()); |
257 | 0 | printExpr(tree.getExpression()); |
258 | 0 | } catch (IOException e) { |
259 | 0 | throw new UncheckedIOException(e); |
260 | 0 | } |
261 | 0 | } |
262 | |
|
263 | |
public void visitBlockExpression(JFXBlockExpression tree) { |
264 | 9 | visitBlockExpression(this, tree); |
265 | 9 | } |
266 | |
|
267 | |
public static void visitBlockExpression(Pretty pretty, JFXBlockExpression tree) { |
268 | |
try { |
269 | 9 | pretty.printFlags(tree.flags); |
270 | 9 | pretty.print("{"); |
271 | 9 | pretty.println(); |
272 | 9 | pretty.indent(); |
273 | 9 | pretty.printStats(tree.stats); |
274 | 9 | if (tree.value != null) { |
275 | 1 | pretty.align(); |
276 | 1 | pretty.printExpr(tree.value); |
277 | |
} |
278 | 9 | pretty.undent(); |
279 | 9 | pretty.println(); |
280 | 9 | pretty.align(); |
281 | 9 | pretty.print("}"); |
282 | 0 | } catch (IOException e) { |
283 | 0 | throw new UncheckedIOException(e); |
284 | 9 | } |
285 | 9 | } |
286 | |
|
287 | |
void printBind(JavafxBindStatus bindStatus) { |
288 | |
try { |
289 | 0 | if (bindStatus.isUnidiBind()) { |
290 | 0 | print(" bind /*stays*/ "); |
291 | |
} |
292 | 0 | if (bindStatus.isBidiBind()) { |
293 | 0 | print(" bind /*tie*/ "); |
294 | |
} |
295 | 0 | if (bindStatus.isLazy()) { |
296 | 0 | print(" bind /*lazy*/ "); |
297 | |
} |
298 | 0 | } catch (IOException e) { |
299 | 0 | throw new UncheckedIOException(e); |
300 | 0 | } |
301 | 0 | } |
302 | |
|
303 | |
@Override |
304 | |
public void visitConditional(JCConditional tree) { |
305 | |
try { |
306 | 0 | print("if ("); |
307 | 0 | printExpr(tree.cond, TreeInfo.condPrec); |
308 | 0 | print(") "); |
309 | 0 | printExpr(tree.truepart, TreeInfo.condPrec); |
310 | 0 | if (tree.falsepart != null) { |
311 | 0 | print(" else "); |
312 | 0 | printExpr(tree.falsepart, TreeInfo.condPrec); |
313 | |
} |
314 | 0 | } catch (IOException e) { |
315 | 0 | throw new UncheckedIOException(e); |
316 | 0 | } |
317 | 0 | } |
318 | |
|
319 | |
public void visitSequenceEmpty(JFXSequenceEmpty that) { |
320 | |
try { |
321 | 0 | print("[]"); |
322 | 0 | } catch (IOException e) { |
323 | 0 | throw new UncheckedIOException(e); |
324 | 0 | } |
325 | 0 | } |
326 | |
|
327 | |
public void visitSequenceRange(JFXSequenceRange that) { |
328 | |
try { |
329 | 1 | print("["); |
330 | 1 | printExpr(that.getLower()); |
331 | 1 | print(".."); |
332 | 1 | printExpr(that.getUpper()); |
333 | 1 | if (that.getStepOrNull() != null) { |
334 | 0 | print("step "); |
335 | 0 | printExpr(that.getStepOrNull()); |
336 | |
} |
337 | 1 | if (that.isExclusive()) { |
338 | 0 | print(" exclusive"); |
339 | |
} |
340 | 1 | print("]"); |
341 | 0 | } catch (IOException e) { |
342 | 0 | throw new UncheckedIOException(e); |
343 | 1 | } |
344 | 1 | } |
345 | |
|
346 | |
public void visitSequenceExplicit(JFXSequenceExplicit that) { |
347 | |
try { |
348 | 0 | boolean first = true; |
349 | 0 | print("["); |
350 | 0 | for (JCExpression expr : that.getItems()) { |
351 | 0 | if (!first) { |
352 | 0 | print(", "); |
353 | |
} |
354 | 0 | first = false; |
355 | 0 | printExpr(expr); |
356 | |
} |
357 | 0 | print("]"); |
358 | 0 | } catch (IOException e) { |
359 | 0 | throw new UncheckedIOException(e); |
360 | 0 | } |
361 | 0 | } |
362 | |
|
363 | |
public void visitSequenceIndexed(JFXSequenceIndexed that) { |
364 | |
try { |
365 | 0 | printExpr(that.getSequence()); |
366 | 0 | print("[ "); |
367 | 0 | printExpr(that.getIndex()); |
368 | 0 | print("]"); |
369 | 0 | } catch (IOException e) { |
370 | 0 | throw new UncheckedIOException(e); |
371 | 0 | } |
372 | 0 | } |
373 | |
|
374 | |
public void visitSequenceSlice(JFXSequenceSlice that) { |
375 | |
try { |
376 | 0 | printExpr(that.getSequence()); |
377 | 0 | print("[ "); |
378 | 0 | printExpr(that.getFirstIndex()); |
379 | 0 | print(" .. "); |
380 | 0 | printExpr(that.getLastIndex()); |
381 | 0 | print("]"); |
382 | 0 | } catch (IOException e) { |
383 | 0 | throw new UncheckedIOException(e); |
384 | 0 | } |
385 | 0 | } |
386 | |
|
387 | |
@Override |
388 | |
public void visitSequenceInsert(JFXSequenceInsert that) { |
389 | |
try { |
390 | 0 | print("insert "); |
391 | 0 | printExpr(that.getElement()); |
392 | 0 | print(" into "); |
393 | 0 | printExpr(that.getSequence()); |
394 | 0 | print("; "); |
395 | 0 | } catch (IOException e) { |
396 | 0 | throw new UncheckedIOException(e); |
397 | 0 | } |
398 | 0 | } |
399 | |
|
400 | |
@Override |
401 | |
public void visitSequenceDelete(JFXSequenceDelete that) { |
402 | |
try { |
403 | 0 | print("delete "); |
404 | 0 | printExpr(that.getSequence()); |
405 | 0 | if (that.getElement() != null) { |
406 | 0 | print(" ("); |
407 | 0 | printExpr(that.getElement()); |
408 | 0 | print(")"); |
409 | |
} |
410 | 0 | print("; "); |
411 | 0 | } catch (IOException e) { |
412 | 0 | throw new UncheckedIOException(e); |
413 | 0 | } |
414 | 0 | } |
415 | |
|
416 | |
@Override |
417 | |
public void visitStringExpression(JFXStringExpression tree) { |
418 | |
try { |
419 | |
int i; |
420 | 15 | List<JCExpression> parts = tree.getParts(); |
421 | 36 | for (i = 0; i < parts.length() - 1; i += 3) { |
422 | 21 | printExpr(parts.get(i)); |
423 | 21 | print("{"); |
424 | 21 | JCExpression format = parts.get(i + 1); |
425 | 21 | if (format != null) { |
426 | 21 | printExpr(format); |
427 | |
} |
428 | 21 | printExpr(parts.get(i + 2)); |
429 | 21 | print("}"); |
430 | |
} |
431 | 15 | printExpr(parts.get(i)); |
432 | 0 | } catch (IOException e) { |
433 | 0 | throw new UncheckedIOException(e); |
434 | 15 | } |
435 | 15 | } |
436 | |
|
437 | |
public void visitInstanciate(JFXInstanciate tree) { |
438 | |
try { |
439 | 5 | JCExpression id = tree.getIdentifier(); |
440 | 5 | if (tree.getArgs().nonEmpty()) |
441 | 0 | print("new "); |
442 | 5 | if (id != null) { |
443 | 5 | printExpr(id); |
444 | |
} |
445 | 5 | if (tree.getArgs().nonEmpty()) { |
446 | |
|
447 | 0 | print("("); |
448 | 0 | printExprs(tree.getArgs()); |
449 | 0 | print(")"); |
450 | |
} else { |
451 | |
|
452 | 5 | print(" {"); |
453 | 5 | if (tree.getParts().nonEmpty()) { |
454 | 0 | indent(); |
455 | 0 | for (JFXObjectLiteralPart mem : tree.getParts()) { |
456 | 0 | println(); |
457 | 0 | align(); |
458 | 0 | printExpr(mem); |
459 | |
} |
460 | |
|
461 | 0 | undent(); |
462 | 0 | println(); |
463 | 0 | align(); |
464 | |
} |
465 | 5 | print("}"); |
466 | |
} |
467 | 0 | } catch (IOException e) { |
468 | 0 | throw new UncheckedIOException(e); |
469 | 5 | } |
470 | 5 | } |
471 | |
|
472 | |
public void visitSetAttributeToObjectBeingInitialized(JFXSetAttributeToObjectBeingInitialized tree) { |
473 | |
try { |
474 | 0 | print("attribute : "); |
475 | 0 | print(tree.getAttributeName()); |
476 | 0 | } catch (IOException e) { |
477 | 0 | throw new UncheckedIOException(e); |
478 | 0 | } |
479 | 0 | } |
480 | |
|
481 | |
public void visitObjectLiteralPart(JFXObjectLiteralPart tree) { |
482 | |
try { |
483 | 0 | print(tree.getName()); |
484 | 0 | print(": "); |
485 | 0 | printBind(tree.getBindStatus()); |
486 | 0 | printExpr(tree.getExpression()); |
487 | 0 | } catch (IOException e) { |
488 | 0 | throw new UncheckedIOException(e); |
489 | 0 | } |
490 | 0 | } |
491 | |
|
492 | |
public void visitTypeAny(JFXTypeAny tree) { |
493 | |
try { |
494 | 0 | print("* "); |
495 | 0 | print(ary(tree)); |
496 | 0 | } catch (IOException e) { |
497 | 0 | throw new UncheckedIOException(e); |
498 | 0 | } |
499 | 0 | } |
500 | |
|
501 | |
@Override |
502 | |
public void visitTypeCast(JCTypeCast tree) { |
503 | |
try { |
504 | 9 | printExpr(tree.expr, TreeInfo.prefixPrec); |
505 | 9 | print(" as "); |
506 | 9 | printExpr(tree.clazz); |
507 | 0 | } catch (IOException e) { |
508 | 0 | throw new UncheckedIOException(e); |
509 | 9 | } |
510 | 9 | } |
511 | |
|
512 | |
public void printTypeSpecifier(JFXType type) { |
513 | |
try { |
514 | 33 | if (type instanceof JFXTypeUnknown) |
515 | 9 | return; |
516 | 24 | print(": "); |
517 | 24 | printExpr(type); |
518 | 0 | } catch (IOException e) { |
519 | 0 | throw new UncheckedIOException(e); |
520 | 24 | } |
521 | 24 | } |
522 | |
public void visitTypeClass(JFXTypeClass tree) { |
523 | |
try { |
524 | 41 | print(tree.getClassName()); |
525 | 41 | print(ary(tree)); |
526 | 0 | } catch (IOException e) { |
527 | 0 | throw new UncheckedIOException(e); |
528 | 41 | } |
529 | 41 | } |
530 | |
|
531 | |
public void visitTypeFunctional(JFXTypeFunctional tree) { |
532 | |
try { |
533 | 0 | print("("); |
534 | 0 | List<JFXType> params = tree.getParams(); |
535 | 0 | if (params.nonEmpty()) { |
536 | 0 | printTypeSpecifier(params.head); |
537 | 0 | for (List<JFXType> l = params.tail; l.nonEmpty(); l = l.tail) { |
538 | 0 | print(", "); |
539 | 0 | printTypeSpecifier(l.head); |
540 | |
} |
541 | |
} |
542 | 0 | print(")"); |
543 | 0 | printTypeSpecifier((JFXType)tree.getReturnType()); |
544 | 0 | print(ary(tree)); |
545 | 0 | } catch (IOException e) { |
546 | 0 | throw new UncheckedIOException(e); |
547 | 0 | } |
548 | 0 | } |
549 | |
|
550 | |
public void visitTypeUnknown(JFXTypeUnknown tree) { |
551 | |
try { |
552 | 0 | print(ary(tree)); |
553 | 0 | } catch (IOException e) { |
554 | 0 | throw new UncheckedIOException(e); |
555 | 0 | } |
556 | 0 | } |
557 | |
|
558 | |
String ary(JFXType tree) { |
559 | |
String show; |
560 | 2 | switch (tree.getCardinality()) { |
561 | |
case ANY: |
562 | 0 | return "[]"; |
563 | |
case SINGLETON: |
564 | 41 | return ""; |
565 | |
} |
566 | 0 | return ""; |
567 | |
} |
568 | |
|
569 | |
public void visitVar(JFXVar tree) { |
570 | |
try { |
571 | 33 | if (docComments != null && docComments.get(tree) != null) { |
572 | 0 | println(); align(); |
573 | |
} |
574 | 33 | printDocComment(tree); |
575 | 33 | printExpr(tree.mods); |
576 | 33 | if (variableScope == SCOPE_CLASS) |
577 | 0 | print("attribute "); |
578 | 33 | else if (variableScope != SCOPE_PARAMS) |
579 | 28 | print("var "); |
580 | 33 | print(tree.getName()); |
581 | 33 | printTypeSpecifier(tree.getJFXType()); |
582 | 33 | if (variableScope != SCOPE_PARAMS) { |
583 | 28 | if (tree.getInitializer() != null) { |
584 | 27 | print(" = "); |
585 | 27 | printExpr(tree.getInitializer()); |
586 | |
} |
587 | |
} |
588 | 33 | printExpr(tree.getOnReplace()); |
589 | 33 | print(";"); |
590 | 33 | if (variableScope == SCOPE_OUTER || variableScope == SCOPE_CLASS) { |
591 | 28 | println(); |
592 | |
} |
593 | 0 | } catch (IOException e) { |
594 | 0 | throw new UncheckedIOException(e); |
595 | 33 | } |
596 | 33 | } |
597 | |
|
598 | |
@Override |
599 | |
public void visitOverrideAttribute(JFXOverrideAttribute tree) { |
600 | |
try { |
601 | 0 | print("override attribute "); |
602 | 0 | printExpr(tree.getId()); |
603 | 0 | if (tree.getInitializer() != null) { |
604 | 0 | print(" = "); |
605 | 0 | printExpr(tree.getInitializer()); |
606 | |
} |
607 | 0 | print(" "); |
608 | 0 | align(); |
609 | 0 | printExpr(tree.getOnReplace()); |
610 | 0 | } catch (IOException e) { |
611 | 0 | throw new UncheckedIOException(e); |
612 | 0 | } |
613 | 0 | } |
614 | |
|
615 | |
|
616 | |
@Override |
617 | |
public void visitOnReplace(JFXOnReplace tree) { |
618 | |
try { |
619 | 0 | print(" on replace"); |
620 | 0 | if (tree.getOldValue() != null) { |
621 | 0 | print(" "); |
622 | 0 | printExpr(tree.getOldValue()); |
623 | |
} |
624 | 0 | if (tree.getFirstIndex() != null) { |
625 | 0 | print("["); |
626 | 0 | printExpr(tree.getFirstIndex()); |
627 | 0 | if (tree.getLastIndex() != null) { |
628 | 0 | print(" .. "); |
629 | 0 | printExpr(tree.getLastIndex()); |
630 | |
} |
631 | 0 | print(" ]"); |
632 | |
} |
633 | 0 | if (tree.getNewElements() != null) { |
634 | 0 | print("= "); |
635 | 0 | printExpr(tree.getNewElements()); |
636 | |
} |
637 | 0 | print(" "); |
638 | 0 | } catch (IOException e) { |
639 | 0 | throw new UncheckedIOException(e); |
640 | 0 | } |
641 | 0 | } |
642 | |
|
643 | |
|
644 | |
@Override |
645 | |
public void visitForExpression(JFXForExpression tree) { |
646 | |
try { |
647 | 1 | boolean first = true; |
648 | 1 | print("for ("); |
649 | 1 | for (ForExpressionInClauseTree cl : tree.getInClauses()) { |
650 | 1 | JFXForExpressionInClause clause = (JFXForExpressionInClause)cl; |
651 | 1 | if (first) { |
652 | 1 | first = false; |
653 | |
} else { |
654 | 0 | print(", "); |
655 | |
} |
656 | 1 | print(clause.getVar().getName()); |
657 | 1 | print(" in "); |
658 | 1 | printExpr(clause.getSequenceExpression()); |
659 | 1 | if (clause.getWhereExpression() != null) { |
660 | 0 | print(" where "); |
661 | 0 | printExpr(clause.getWhereExpression()); |
662 | |
} |
663 | 1 | } |
664 | 1 | print(") "); |
665 | 1 | printExpr(tree.getBodyExpression()); |
666 | 0 | } catch (IOException e) { |
667 | 0 | throw new UncheckedIOException(e); |
668 | 1 | } |
669 | 1 | } |
670 | |
|
671 | |
public void visitIndexof(JFXIndexof that) { |
672 | |
try { |
673 | 0 | print("indexof "); |
674 | 0 | print(that.fname); |
675 | 0 | } catch (IOException e) { |
676 | 0 | throw new UncheckedIOException(e); |
677 | 0 | } |
678 | 0 | } |
679 | |
|
680 | |
@Override |
681 | |
public void visitForExpressionInClause(JFXForExpressionInClause that) { |
682 | |
try { |
683 | 0 | print(that.var); |
684 | 0 | print(" in "); |
685 | 0 | print(that.seqExpr); |
686 | 0 | if (that.whereExpr != null) { |
687 | 0 | print(" where "); |
688 | 0 | print(that.whereExpr); |
689 | |
} |
690 | 0 | } catch (IOException e) { |
691 | 0 | throw new UncheckedIOException(e); |
692 | 0 | } |
693 | 0 | } |
694 | |
|
695 | |
@Override |
696 | |
public void visitUnary(JCUnary tree) { |
697 | |
try { |
698 | 0 | if (tree.getTag() == JavafxTag.SIZEOF) { |
699 | 0 | print("(sizeof "); |
700 | 0 | printExpr(tree.arg); |
701 | 0 | print(")"); |
702 | |
} else { |
703 | 0 | super.visitUnary(tree); |
704 | |
} |
705 | 0 | } catch (IOException e) { |
706 | 0 | throw new UncheckedIOException(e); |
707 | 0 | } |
708 | 0 | } |
709 | |
|
710 | |
@Override |
711 | |
public void visitTree(JCTree tree) { |
712 | 0 | assert false : "Should not be here!!!"; |
713 | 0 | } |
714 | |
|
715 | |
@Override |
716 | |
public String operatorName(int tag) { |
717 | 6 | switch(tag) { |
718 | 0 | case JCTree.OR: return "or"; |
719 | 0 | case JCTree.AND: return "and"; |
720 | 0 | case JCTree.EQ: return "=="; |
721 | 0 | case JCTree.NE: return "<>"; |
722 | 6 | default: return super.operatorName(tag); |
723 | |
} |
724 | |
} |
725 | |
|
726 | |
|
727 | |
public static String toString(JCTree tree) { |
728 | 0 | StringWriter s = new StringWriter(); |
729 | |
try { |
730 | 0 | new JavafxPretty(s, false).printExpr(tree); |
731 | |
} |
732 | 0 | catch (IOException e) { |
733 | |
|
734 | |
|
735 | 0 | throw new AssertionError(e); |
736 | 0 | } |
737 | 0 | return s.toString(); |
738 | |
} |
739 | |
|
740 | |
public void visitTimeLiteral(JFXTimeLiteral tree) { |
741 | |
try { |
742 | 0 | Double d = ((Number)tree.value.value).doubleValue(); |
743 | 0 | d /= tree.duration.getMultiplier(); |
744 | 0 | print(d + tree.duration.getSuffix()); |
745 | 0 | } catch (IOException e) { |
746 | 0 | throw new UncheckedIOException(e); |
747 | 0 | } |
748 | 0 | } |
749 | |
|
750 | |
public void visitInterpolate(JFXInterpolate tree) { |
751 | |
try { |
752 | 0 | print(tree.getVariable()); |
753 | 0 | print(" => "); |
754 | 0 | boolean isBlock = tree.getInterpolateValues().size() > 1; |
755 | 0 | if (isBlock) |
756 | 0 | print('{'); |
757 | 0 | Iterator<InterpolateValueTree> values = tree.getInterpolateValues().iterator(); |
758 | 0 | while (values.hasNext()) { |
759 | 0 | printInterpolateValue((JFXInterpolateValue)values.next()); |
760 | 0 | if (values.hasNext()) |
761 | 0 | print(", "); |
762 | |
} |
763 | 0 | if (isBlock) |
764 | 0 | print('}'); |
765 | 0 | } catch (IOException e) { |
766 | 0 | throw new UncheckedIOException(e); |
767 | 0 | } |
768 | 0 | } |
769 | |
|
770 | |
public void visitInterpolateValue(JFXInterpolateValue tree) { |
771 | 0 | printInterpolateValue(tree); |
772 | 0 | } |
773 | |
|
774 | |
private void printTween(JFXInterpolateValue tree) throws IOException { |
775 | 0 | JCExpression tween = tree.getInterpolation(); |
776 | 0 | if (tween != null) { |
777 | 0 | print(" tween "); |
778 | 0 | print(tween); |
779 | |
} |
780 | 0 | } |
781 | |
|
782 | |
public void visitKeyFrameLiteral(JFXKeyFrameLiteral tree) { |
783 | |
try { |
784 | 0 | print("at ("); |
785 | 0 | print(tree.getStartDuration()); |
786 | 0 | print(") {"); |
787 | 0 | println(); |
788 | 0 | super.indent(); |
789 | 0 | printStats(List.convert(JCTree.class, tree.getInterpolationExpression())); |
790 | 0 | if (tree.getTriggerExpression() != null) { |
791 | 0 | super.align(); |
792 | 0 | print("trigger "); |
793 | 0 | visitBlockExpression(this, (JFXBlockExpression)tree.getTriggerExpression()); |
794 | |
} |
795 | 0 | super.undent(); |
796 | 0 | println(); |
797 | 0 | super.align(); |
798 | 0 | print("}"); |
799 | 0 | } catch (IOException e) { |
800 | 0 | throw new UncheckedIOException(e); |
801 | 0 | } |
802 | 0 | } |
803 | |
} |