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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
|
/* ____ ____ ____ ____ ______ *\
** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala **
** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL **
** /_____/\____/\___/\____/____/ **
** **
\* */
// $Id$
package scalac.ast.printer;
import scalac.ast.*;
import scalac.symtab.*;
import scalac.util.Debug;
import scalac.Global;
import scalac.Unit;
import scalac.util.Name;
import java.io.*;
import java.util.*;
/**
* Text pretty printer for Scala abstract syntax trees.
*
* @author Michel Schinz, Matthias Zenger
* @version 1.0
*/
public class TextTreePrinter implements TreePrinter {
protected PrintWriter out;
protected final boolean autoFlush;
protected int indent = 0;
protected final int INDENT_STEP = 2;
protected String INDENT_STRING =
" ";
protected final int MAX_INDENT = INDENT_STRING.length();
public TextTreePrinter(OutputStream stream) {
this(stream, false);
}
public TextTreePrinter(OutputStream stream, boolean autoFlush) {
this.autoFlush = autoFlush;
this.out = new PrintWriter(stream);
}
public TextTreePrinter(Writer stream) {
this(stream, false);
}
public TextTreePrinter(Writer stream, boolean autoFlush) {
this.autoFlush = autoFlush;
this.out = new PrintWriter(stream);
}
public TextTreePrinter() {
this(System.out);
}
public void begin() { }
public void end() {
flush();
}
public void flush() {
out.flush();
}
public TreePrinter print(String str) {
out.print(str);
if (autoFlush) flush();
return this;
}
public TreePrinter println() {
out.println();
if (autoFlush) flush();
return this;
}
public void beginSection(int level, String title) {
out.println("[[" + title + "]]");
flush();
}
protected void indent() {
indent += Math.min(MAX_INDENT, INDENT_STEP);
}
protected void undent() {
indent -= Math.max(0, INDENT_STEP);
}
protected void printString(String str) {
out.print(str);
if (autoFlush) flush();
}
protected void printNewLine() {
out.println();
while (indent > INDENT_STRING.length()) {
INDENT_STRING = INDENT_STRING + INDENT_STRING;
}
if (indent > 0)
out.write(INDENT_STRING, 0, indent);
if (autoFlush) flush();
}
public static class SymbolUsage {
public case Definition;
public case Use;
}
public static class Text {
public case None;
public case Space;
public case Newline;
public case Simple(String str);
public case Literal(String str);
public case Keyword(String name);
public case Identifier(Symbol symbol, String name, SymbolUsage usage);
public case Sequence(Text[] elements);
}
protected void print(Text text) {
switch (text) {
case None : break;
case Space : printString(" "); break;
case Newline : printNewLine(); break;
case Simple(String str) : printString(str); break;
case Literal(String str) : printString(str); break;
case Keyword(String name) : printString(name); break;
case Identifier(Symbol sym, String name, _) :
printString(name);
if (sym != null && Global.instance.uniqid)
printString("#" + Global.instance.uniqueID.id(sym));
break;
case Sequence(Text[] elements) : print(elements); break;
}
}
protected void print(Text[] texts) {
for (int i = 0; i < texts.length; ++i)
print(texts[i]);
}
protected static final Text KW_ABSTRACT = Text.Keyword("abstract");
protected static final Text KW_CASE = Text.Keyword("case");
protected static final Text KW_CLASS = Text.Keyword("class");
protected static final Text KW_CONSTR = Text.Keyword("constr");
protected static final Text KW_DEF = Text.Keyword("def");
protected static final Text KW_DO = Text.Keyword("do");
protected static final Text KW_ELSE = Text.Keyword("else");
protected static final Text KW_EXTENDS = Text.Keyword("extends");
protected static final Text KW_FINAL = Text.Keyword("final");
protected static final Text KW_FOR = Text.Keyword("for");
protected static final Text KW_IF = Text.Keyword("if");
protected static final Text KW_IMPORT = Text.Keyword("import");
protected static final Text KW_INTERFACE = Text.Keyword("interface");
protected static final Text KW_LET = Text.Keyword("let");
protected static final Text KW_OBJECT = Text.Keyword("object");
protected static final Text KW_NEW = Text.Keyword("new");
protected static final Text KW_NULL = Text.Keyword("null");
protected static final Text KW_OUTER = Text.Keyword("outer");
protected static final Text KW_OVERRIDE = Text.Keyword("override");
protected static final Text KW_PACKAGE = Text.Keyword("package");
protected static final Text KW_PRIVATE = Text.Keyword("private");
protected static final Text KW_PROTECTED = Text.Keyword("protected");
protected static final Text KW_QUALIFIED = Text.Keyword("qualified");
protected static final Text KW_STATIC = Text.Keyword("static");
protected static final Text KW_SUPER = Text.Keyword("super");
protected static final Text KW_THIS = Text.Keyword("this");
protected static final Text KW_TYPE = Text.Keyword("type");
protected static final Text KW_VAL = Text.Keyword("val");
protected static final Text KW_VAR = Text.Keyword("var");
protected static final Text KW_WITH = Text.Keyword("with");
protected static final Text KW_YIELD = Text.Keyword("yield");
protected static final Text TXT_ERROR = Text.Simple("<error>");
protected static final Text TXT_UNKNOWN = Text.Simple("<unknown>");
protected static final Text TXT_NULL = Text.Simple("<null>");
protected static final Text TXT_OBJECT_COMMENT
= Text.Simple("/*object*/ ");
protected static final Text TXT_EMPTY = Text.Simple("<empty>");
protected static final Text TXT_QUOTE = Text.Simple("\"");
protected static final Text TXT_PLUS = Text.Simple("+");
protected static final Text TXT_COLON = Text.Simple(":");
protected static final Text TXT_SEMICOLON = Text.Simple(";");
protected static final Text TXT_DOT = Text.Simple(".");
protected static final Text TXT_COMMA = Text.Simple(",");
protected static final Text TXT_EQUAL = Text.Simple("=");
protected static final Text TXT_SUPERTYPE = Text.Simple(">:");
protected static final Text TXT_SUBTYPE = Text.Simple("<:");
protected static final Text TXT_HASH = Text.Simple("#");
protected static final Text TXT_RIGHT_ARROW = Text.Simple("=>");
protected static final Text TXT_LEFT_PAREN = Text.Simple("(");
protected static final Text TXT_RIGHT_PAREN = Text.Simple(")");
protected static final Text TXT_LEFT_BRACE = Text.Simple("{");
protected static final Text TXT_RIGHT_BRACE = Text.Simple("}");
protected static final Text TXT_LEFT_BRACKET = Text.Simple("[");
protected static final Text TXT_RIGHT_BRACKET = Text.Simple("]");
protected static final Text TXT_BAR = Text.Simple("|");
protected static final Text TXT_AT = Text.Simple("@");
protected static final Text TXT_WITH_SP =
Text.Sequence(new Text[]{ Text.Space, KW_WITH, Text.Space });
protected static final Text TXT_BLOCK_BEGIN =
Text.Sequence(new Text[]{ TXT_LEFT_BRACE, Text.Newline });
protected static final Text TXT_BLOCK_END =
Text.Sequence(new Text[]{ Text.Newline, TXT_RIGHT_BRACE });
protected static final Text TXT_BLOCK_SEP =
Text.Sequence(new Text[]{ TXT_SEMICOLON, Text.Newline });
protected static final Text TXT_COMMA_SP =
Text.Sequence(new Text[]{ TXT_COMMA, Text.Space });
protected static final Text TXT_ELSE_NL =
Text.Sequence(new Text[]{ KW_ELSE, Text.Newline });
protected static final Text TXT_BAR_SP =
Text.Sequence(new Text[]{ Text.Space, TXT_BAR, Text.Space });
public void print(Unit unit) {
printUnitHeader(unit);
if (unit.body != null) {
for (int i = 0; i < unit.body.length; ++i) {
print(unit.body[i]);
print(TXT_BLOCK_SEP);
}
} else
print(TXT_NULL);
printUnitFooter(unit);
flush();
}
protected void printUnitHeader(Unit unit) {
print(Text.Simple("// Scala source: " + unit.source + "\n"));
}
protected void printUnitFooter(Unit unit) {
print(Text.Newline);
}
public TreePrinter print(Tree tree) {
switch (tree) {
case Bad():
print(TXT_ERROR);
break;
case Empty:
print(TXT_EMPTY);
break;
case ClassDef(int mods, // :
Name name,
Tree.TypeDef[] tparams,
Tree.ValDef[][] vparams,
Tree tpe,
Tree.Template impl):
printModifiers(mods);
print((mods & Modifiers.INTERFACE) != 0
? KW_INTERFACE
: KW_CLASS);
print(Text.Space);
printSymbolDefinition(tree.symbol(), name);
printParams(tparams);
printParams(vparams);
printOpt(TXT_COLON, tpe, false);
printTemplate(KW_EXTENDS, impl, true);
break;
case PackageDef(Tree packaged, Tree.Template impl):
print(KW_PACKAGE);
print(Text.Space);
print(packaged);
printTemplate(KW_WITH, impl, true);
break;
case ModuleDef(int mods, // :
Name name,
Tree tpe,
Tree.Template impl):
printModifiers(mods);
print(KW_OBJECT);
print(Text.Space);
printSymbolDefinition(tree.symbol(), name);
printOpt(TXT_COLON, tpe, false);
printTemplate(KW_EXTENDS, impl, true);
break;
case ValDef(int mods, Name name, Tree tpe, Tree rhs):
printModifiers(mods);
if ((mods & Modifiers.MUTABLE) != 0) print(KW_VAR);
else {
if ((mods & Modifiers.MODUL) != 0) print(TXT_OBJECT_COMMENT);
print(KW_VAL);
}
print(Text.Space);
printSymbolDefinition(tree.symbol(), name);
printOpt(TXT_COLON, tpe, false);
if ((mods & Modifiers.DEFERRED) == 0) {
print(Text.Space); print(TXT_EQUAL); print(Text.Space);
if (rhs == Tree.Empty) print("_");
else print(rhs);
}
break;
case PatDef(int mods, Tree pat, Tree rhs):
printModifiers(mods);
print(KW_VAL);
print(Text.Space);
print(pat);
printOpt(TXT_EQUAL, rhs, true);
break;
case DefDef(int mods,
Name name,
Tree.TypeDef[] tparams,
Tree.ValDef[][] vparams,
Tree tpe,
Tree rhs):
printModifiers(mods);
if (name.isConstrName()) print(KW_CONSTR); else print(KW_DEF);
print(Text.Space);
printSymbolDefinition(tree.symbol(), name);
printParams(tparams);
printParams(vparams);
printOpt(TXT_COLON, tpe, false);
printOpt(TXT_EQUAL, rhs, true);
break;
case TypeDef(int mods,
Name name,
Tree rhs,
Tree lobound):
printModifiers(mods);
print(KW_TYPE);
print(Text.Space);
printSymbolDefinition(tree.symbol(), name);
if ((mods & (Modifiers.DEFERRED | Modifiers.PARAM)) != 0) {
printBounds(lobound, rhs);
} else {
printOpt(TXT_EQUAL, rhs, true);
}
break;
case Import(Tree expr, Name[] selectors):
print(KW_IMPORT);
print(Text.Space);
print(expr);
print(TXT_DOT);
print(TXT_LEFT_BRACE);
for (int i = 0; i < selectors.length; i = i + 2) {
if (i > 0) print(TXT_COMMA_SP);
print(selectors[i].toString());
if (i + 1 < selectors.length && selectors[i] != selectors[i+1]) {
print(TXT_RIGHT_ARROW);
print(selectors[i+1].toString());
}
}
print(TXT_RIGHT_BRACE);
break;
case CaseDef(Tree pat, Tree guard, Tree body):
print(KW_CASE);
print(Text.Space);
print(pat);
printOpt(KW_IF, guard, true);
print(Text.Space);
print(TXT_RIGHT_ARROW);
print(Text.Space);
print(body);
break;
case LabelDef(Tree.Ident[] params, Tree rhs):
assert tree.symbol() != null;
printSymbolDefinition(tree.symbol(), null);
printArray(params, TXT_LEFT_PAREN, TXT_RIGHT_PAREN, TXT_COMMA_SP);
print(rhs);
break;
case Block(Tree[] stats):
printArray(stats, TXT_BLOCK_BEGIN, TXT_BLOCK_END, TXT_BLOCK_SEP);
break;
case Sequence(Tree[] trees): // sure ? was Tuple before...
printArray(trees, TXT_LEFT_BRACKET, TXT_RIGHT_BRACKET, TXT_COMMA_SP);
break;
case Subsequence(Tree[] trees):
if( trees.length > 0 )
printArray(trees, TXT_LEFT_PAREN, TXT_RIGHT_PAREN, TXT_COMMA_SP);
else
{
print( TXT_LEFT_PAREN );
print( TXT_COMMA );
print( TXT_RIGHT_PAREN );
}
break;
case Alternative(Tree[] trees):
printArray(trees, TXT_LEFT_PAREN, TXT_RIGHT_PAREN, TXT_BAR_SP);
break;
case Bind(Name name, Tree t):
printSymbolDefinition(tree.symbol(), name);
print(Text.Space);
print(TXT_AT);
print(Text.Space);
print( t );
break;
case Visitor(Tree.CaseDef[] cases):
printArray(cases, TXT_BLOCK_BEGIN, TXT_BLOCK_END, Text.Newline);
break;
case Function(Tree.ValDef[] vparams, Tree body):
print(TXT_LEFT_PAREN);
printParams(vparams);
print(Text.Space);
print(TXT_RIGHT_ARROW);
print(Text.Space);
print(body);
print(TXT_RIGHT_PAREN);
break;
case Assign(Tree lhs, Tree rhs):
print(lhs);
print(Text.Space);
print(TXT_EQUAL);
print(Text.Space);
print(rhs);
break;
case If(Tree cond, Tree thenp, Tree elsep):
print(KW_IF);
print(Text.Space);
print(TXT_LEFT_PAREN);
print(cond);
print(TXT_RIGHT_PAREN);
indent(); print(Text.Newline);
print(thenp);
undent(); print(Text.Newline);
indent(); printOpt(TXT_ELSE_NL, elsep, false); undent();
printType(tree);
break;
case New(Tree.Template templ):
printTemplate(KW_NEW, templ, false);
printType(tree);
break;
case Typed(Tree expr, Tree tpe):
print(TXT_LEFT_PAREN);
print(expr);
print(TXT_RIGHT_PAREN);
print(Text.Space);
print(TXT_COLON);
print(Text.Space);
print(tpe);
printType(tree);
break;
case TypeApply(Tree fun, Tree[] targs):
print(fun);
printArray(targs, TXT_LEFT_BRACKET, TXT_RIGHT_BRACKET, TXT_COMMA_SP);
printType(tree);
break;
case Apply(Tree fun, Tree[] vargs):
if (fun instanceof Tree.TypeTerm)
print(fun.type.resultType().symbol().fullName().toString());
else
print(fun);
printArray(vargs, TXT_LEFT_PAREN, TXT_RIGHT_PAREN, TXT_COMMA_SP);
printType(tree);
break;
case Super(Tree tpe):
if (tpe != Tree.Empty)
print(TXT_LEFT_PAREN);
print(KW_SUPER);
if (tpe != Tree.Empty) {
print(Text.Space);
print(TXT_COLON);
print(Text.Space);
print(tpe);
print(TXT_RIGHT_PAREN);
}
printType(tree);
break;
case This(Tree qualifier):
if (qualifier != Tree.Empty) {
print(qualifier);
print(TXT_DOT);
}
print(KW_THIS);
printType(tree);
break;
case Select(Tree qualifier, Name name):
print(qualifier);
print(TXT_DOT);
printSymbolUse(tree.symbol(), name);
printType(tree);
break;
case Ident(Name name):
printSymbolUse(tree.symbol(), name);
printType(tree);
break;
case Literal(Object obj):
String str;
if (obj instanceof String)
str = "\"" + obj + "\"";
else if (obj instanceof Character)
str = "\'" + obj + "\'";
else
str = String.valueOf(obj);
print(Text.Literal(str));
printType(tree);
break;
case TypeTerm():
print(tree.type.toString());
break;
case SingletonType(Tree ref):
print(ref);
print(TXT_DOT); print(KW_TYPE);
break;
case SelectFromType(Tree qualifier, Name selector):
print(qualifier);
print(Text.Space); print(TXT_HASH); print(Text.Space);
printSymbolUse(tree.symbol(), selector);
break;
case FunType(Tree[] argtpes, Tree restpe):
printArray(argtpes, TXT_LEFT_PAREN, TXT_RIGHT_PAREN, TXT_COMMA_SP);
print(TXT_RIGHT_ARROW);
print(restpe);
break;
case CompoundType(Tree[] baseTypes, Tree[] refinements):
printArray(baseTypes, Text.None, Text.None, TXT_WITH_SP);
printArray(refinements, TXT_BLOCK_BEGIN, TXT_BLOCK_END, Text.Newline);
break;
case AppliedType(Tree tpe, Tree[] args):
print(tpe);
indent();
print(TXT_LEFT_BRACKET);
for (int i = 0; i < args.length; ++i) {
if (i > 0) print(TXT_COMMA_SP);
print(args[i]);
}
undent();
print(TXT_RIGHT_BRACKET);
break;
case Template(Tree[] parents, Tree[] body):
Debug.abort("unexpected case: template");
break;
default:
print(TXT_UNKNOWN);
break;
}
//print("{" + tree.type + "}");//DEBUG
if (autoFlush)
flush();
return this;
}
// Printing helpers
protected void printArray(Tree[] trees, Text open, Text close, Text sep) {
indent();
print(open);
for (int i = 0; i < trees.length; ++i) {
if (i > 0) print(sep);
print(trees[i]);
}
undent();
print(close);
}
protected void printOpt(Text prefix, Tree tree, boolean spaceBefore) {
if (tree != Tree.Empty) {
if (spaceBefore)
print(Text.Space);
print(prefix);
print(Text.Space);
print(tree);
}
}
// Printing of symbols
protected String symbolString(Symbol symbol, Name name) {
if (symbol != null)
return symbol.name.toString();
else
return name.toString();
}
protected void printSymbolDefinition(Symbol symbol, Name name) {
print(Text.Identifier(symbol,
symbolString(symbol, name),
SymbolUsage.Definition));
}
protected void printSymbolUse(Symbol symbol, Name name) {
print(Text.Identifier(symbol,
symbolString(symbol, name),
SymbolUsage.Use));
}
// Printing of trees
protected void printType(Tree tree) {
if (Global.instance.printtypes) {
print(TXT_LEFT_BRACE);
if (tree.type != null)
print(Text.Simple(tree.type.toString()));
else
print(TXT_NULL);
print(TXT_RIGHT_BRACE);
}
}
protected void printModifiers(int flags) {
if ((flags & Modifiers.ABSTRACTCLASS) != 0) {
print(KW_ABSTRACT);
print(Text.Space);
}
if ((flags & Modifiers.FINAL) != 0) {
print(KW_FINAL);
print(Text.Space);
}
if ((flags & Modifiers.PRIVATE) != 0) {
print(KW_PRIVATE);
print(Text.Space);
}
if ((flags & Modifiers.PROTECTED) != 0) {
print(KW_PROTECTED);
print(Text.Space);
}
if ((flags & Modifiers.QUALIFIED) != 0) {
print(KW_QUALIFIED);
print(Text.Space);
}
if ((flags & Modifiers.OVERRIDE) != 0) {
print(KW_OVERRIDE);
print(Text.Space);
}
if ((flags & Modifiers.CASE) != 0) {
print(KW_CASE);
print(Text.Space);
}
if ((flags & Modifiers.DEF) != 0) {
print(KW_DEF);
print(Text.Space);
}
if ((flags & Modifiers.STATIC) != 0) {
print(KW_STATIC);
print(Text.Space);
}
}
protected void printTemplate(Text prefix,
Tree.Template templ,
boolean spaceBefore) {
if (! (templ.parents.length == 0
|| (templ.parents.length == 1
&& templ.parents[0] == Tree.Empty))) {
if (spaceBefore)
print(Text.Space);
print(prefix);
print(Text.Space);
printArray(templ.parents, Text.None, Text.None, TXT_WITH_SP);
}
if (templ.body.length > 0) {
print(Text.Space);
printArray(templ.body, TXT_BLOCK_BEGIN, TXT_BLOCK_END, TXT_BLOCK_SEP);
}
}
protected void printParams(Tree.TypeDef[] tparams) {
if (tparams.length > 0) {
print(TXT_LEFT_BRACKET);
for (int i = 0; i < tparams.length; i++) {
if (i > 0) print(TXT_COMMA_SP);
printParam(tparams[i]);
}
print(TXT_RIGHT_BRACKET);
}
}
protected void printParams(Tree.ValDef[][] vparamss) {
for (int i = 0; i < vparamss.length; ++i)
printParams(vparamss[i]);
}
protected void printParams(Tree.ValDef[] vparams) {
print(TXT_LEFT_PAREN);
for (int i = 0; i < vparams.length; ++i) {
if (i > 0) print(TXT_COMMA_SP);
printParam(vparams[i]);
}
print(TXT_RIGHT_PAREN);
}
protected void printParam(Tree tree) {
switch (tree) {
case TypeDef(int mods, Name name, Tree bound, Tree lobound):
printModifiers(mods);
printSymbolDefinition(tree.symbol(), name);
printBounds(lobound, bound);
break;
case ValDef(int mods, Name name, Tree tpe, Tree.Empty):
printModifiers(mods);
printSymbolDefinition(tree.symbol(), name);
printOpt(TXT_COLON, tpe, false);
break;
default:
Debug.abort("bad parameter: " + tree);
}
}
protected void printBounds(Tree lobound, Tree hibound) {
if (!"scala.All".equals(lobound.toString()))
printOpt(TXT_SUPERTYPE, lobound, true);
if (!"scala.Any".equals(hibound.toString()))
printOpt(TXT_SUBTYPE, hibound, true);
}
}
|