@@ -204,33 +204,15 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
204
204
this
205
205
}
206
206
207
- case While (cond, stats ) =>
207
+ case Term . While (cond, body ) =>
208
208
this += " while ("
209
209
printTree(cond)
210
210
this += " ) "
211
- stats match {
212
- case stat :: Nil =>
213
- printTree(stat)
214
- case stats =>
215
- this += " {"
216
- indented {
217
- printStats(stats.init, stats.last)
218
- }
219
- this += lineBreak() += " }"
220
- }
211
+ printTree(body)
221
212
222
- case DoWhile (stats , cond) =>
213
+ case Term . DoWhile (body , cond) =>
223
214
this += " do "
224
- stats match {
225
- case stat :: Nil =>
226
- printTree(stat)
227
- case stats =>
228
- this += " {"
229
- indented {
230
- printStats(stats.init, stats.last)
231
- }
232
- this += lineBreak() += " }"
233
- }
215
+ printTree(body)
234
216
this += " while ("
235
217
printTree(cond)
236
218
this += " )"
@@ -361,14 +343,11 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
361
343
printTree(rhs)
362
344
363
345
case Term .Block (stats0, expr) =>
364
- def shouldNotBePrinted (tree : Tree ): Boolean = tree match {
365
- case Term .Apply (Term .Ident (" while$" | " doWhile$" ), _) => true
366
- case tree @ ValDef (_, _, _) => tree.flags.isObject
367
- case _ => false
346
+ val stats = stats0.filter {
347
+ case tree @ ValDef (_, _, _) => ! tree.flags.isObject
348
+ case _ => true
368
349
}
369
350
370
- val stats = stats0.filterNot(shouldNotBePrinted)
371
-
372
351
expr match {
373
352
case Term .Lambda (_, _) =>
374
353
// Decompile lambda from { def annon$(...) = ...; closure(annon$, ...)}
@@ -380,11 +359,8 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
380
359
this += " )"
381
360
case _ =>
382
361
this += " {"
383
- val (stats1, expr1) =
384
- if (shouldNotBePrinted(expr)) (stats.init, stats.last)
385
- else (stats, expr)
386
362
indented {
387
- printStats(stats1, expr1 )
363
+ printStats(stats, expr )
388
364
}
389
365
this += lineBreak() += " }"
390
366
}
@@ -452,7 +428,6 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
452
428
def printSeparator (next : Tree ): Unit = {
453
429
// Avoid accidental application of opening `{` on next line with a double break
454
430
next match {
455
- case Term .Block (DefDef (" while$" | " doWhile$" , _, _, _, _) :: Nil , _) => this += lineBreak()
456
431
case Term .Block (_, _) => this += doubleLineBreak()
457
432
case Term .Inlined (_, _, _) => this += doubleLineBreak()
458
433
case Term .Select (qual, _, _) => printSeparator(qual)
@@ -1092,7 +1067,6 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
1092
1067
private def escapedString (str : String ): String = str flatMap escapedChar
1093
1068
}
1094
1069
1095
-
1096
1070
private object SpecialOp {
1097
1071
def unapply (arg : Term )(implicit ctx : Context ): Option [(String , List [Term ])] = arg match {
1098
1072
case arg@ Term .Apply (fn, args) =>
@@ -1105,22 +1079,6 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
1105
1079
}
1106
1080
}
1107
1081
1108
- private object While {
1109
- def unapply (arg : Tree )(implicit ctx : Context ): Option [(Term , List [Statement ])] = arg match {
1110
- case DefDef (" while$" , _, _, _, Some (Term .If (cond, Term .Block (bodyStats, _), _))) => Some ((cond, bodyStats))
1111
- case Term .Block (List (tree), _) => unapply(tree)
1112
- case _ => None
1113
- }
1114
- }
1115
-
1116
- private object DoWhile {
1117
- def unapply (arg : Tree )(implicit ctx : Context ): Option [(List [Statement ], Term )] = arg match {
1118
- case DefDef (" doWhile$" , _, _, _, Some (Term .Block (body, Term .If (cond, _, _)))) => Some ((body, cond))
1119
- case Term .Block (List (tree), _) => unapply(tree)
1120
- case _ => None
1121
- }
1122
- }
1123
-
1124
1082
private object Annotation {
1125
1083
def unapply (arg : Tree )(implicit ctx : Context ): Option [(TypeTree , List [Term ])] = arg match {
1126
1084
case Term .New (annot) => Some ((annot, Nil ))
0 commit comments