@@ -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 += " )"
@@ -349,14 +331,11 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
349
331
printTree(rhs)
350
332
351
333
case Term .Block (stats0, expr) =>
352
- def shouldNotBePrinted (tree : Tree ): Boolean = tree match {
353
- case Term .Apply (Term .Ident (" while$" | " doWhile$" ), _) => true
354
- case tree @ ValDef (_, _, _) => tree.flags.isObject
355
- case _ => false
334
+ val stats = stats0.filter {
335
+ case tree @ ValDef (_, _, _) => ! tree.flags.isObject
336
+ case _ => true
356
337
}
357
338
358
- val stats = stats0.filterNot(shouldNotBePrinted)
359
-
360
339
expr match {
361
340
case Term .Lambda (_, _) =>
362
341
// Decompile lambda from { def annon$(...) = ...; closure(annon$, ...)}
@@ -368,11 +347,8 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
368
347
this += " )"
369
348
case _ =>
370
349
this += " {"
371
- val (stats1, expr1) =
372
- if (shouldNotBePrinted(expr)) (stats.init, stats.last)
373
- else (stats, expr)
374
350
indented {
375
- printStats(stats1, expr1 )
351
+ printStats(stats, expr )
376
352
}
377
353
this += lineBreak() += " }"
378
354
}
@@ -441,7 +417,6 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
441
417
// Avoid accidental application of opening `{` on next line with a double break
442
418
val next = if (nextStats.isEmpty) expr else nextStats.head
443
419
next match {
444
- case Term .Block (DefDef (" while$" | " doWhile$" , _, _, _, _) :: Nil , _) => this += lineBreak()
445
420
case Term .Block (_, _) => this += doubleLineBreak()
446
421
case Term .Inlined (_, _, _) => this += doubleLineBreak()
447
422
case _ => this += lineBreak()
@@ -1073,7 +1048,6 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
1073
1048
private def escapedString (str : String ): String = str flatMap escapedChar
1074
1049
}
1075
1050
1076
-
1077
1051
private object SpecialOp {
1078
1052
def unapply (arg : Term )(implicit ctx : Context ): Option [(String , List [Term ])] = arg match {
1079
1053
case arg@ Term .Apply (fn, args) =>
@@ -1086,22 +1060,6 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
1086
1060
}
1087
1061
}
1088
1062
1089
- private object While {
1090
- def unapply (arg : Tree )(implicit ctx : Context ): Option [(Term , List [Statement ])] = arg match {
1091
- case DefDef (" while$" , _, _, _, Some (Term .If (cond, Term .Block (bodyStats, _), _))) => Some ((cond, bodyStats))
1092
- case Term .Block (List (tree), _) => unapply(tree)
1093
- case _ => None
1094
- }
1095
- }
1096
-
1097
- private object DoWhile {
1098
- def unapply (arg : Tree )(implicit ctx : Context ): Option [(List [Statement ], Term )] = arg match {
1099
- case DefDef (" doWhile$" , _, _, _, Some (Term .Block (body, Term .If (cond, _, _)))) => Some ((body, cond))
1100
- case Term .Block (List (tree), _) => unapply(tree)
1101
- case _ => None
1102
- }
1103
- }
1104
-
1105
1063
private object Annotation {
1106
1064
def unapply (arg : Tree )(implicit ctx : Context ): Option [(TypeTree , List [Term ])] = arg match {
1107
1065
case Term .New (annot) => Some ((annot, Nil ))
0 commit comments