@@ -5,6 +5,7 @@ import dotty.tools.dotc.ast.untpd.{PackageDef, Template, TypeDef}
55import dotty .tools .dotc .ast .{Trees , untpd }
66import dotty .tools .dotc .printing .Texts ._
77import dotty .tools .dotc .core .Contexts ._
8+ import dotty .tools .dotc .core .StdNames .nme
89import dotty .tools .dotc .core .Flags ._
910import dotty .tools .dotc .core .Symbols ._
1011import dotty .tools .dotc .core .StdNames ._
@@ -16,15 +17,19 @@ class DecompilerPrinter(_ctx: Context) extends RefinedPrinter(_ctx) {
1617 override protected def filterModTextAnnots (annots : List [untpd.Tree ]): List [untpd.Tree ] =
1718 annots.filter(_.tpe != defn.SourceFileAnnotType )
1819
19- override protected def blockText [T >: Untyped ](trees : List [ Trees . Tree [ T ]] ): Text = {
20- trees match {
21- case DefDef (_, _, _, _, Trees .If (cond, Trees .Block (body :: Nil , _), _)) :: y :: Nil if y.symbol.name == nme.WHILE_PREFIX =>
20+ override protected def blockToText [T >: Untyped ](block : Block [ T ] ): Text =
21+ block match {
22+ case Block ( DefDef (_, _, _, _, Trees .If (cond, Trees .Block (body :: Nil , _), _)) :: Nil , y) if y.symbol.name == nme.WHILE_PREFIX =>
2223 keywordText(" while" ) ~ " (" ~ toText(cond) ~ " )" ~ toText(body)
23- case DefDef (_, _, _, _, Trees .Block (body :: Nil , Trees .If (cond, _, _))) :: y :: Nil if y.symbol.name == nme.DO_WHILE_PREFIX =>
24+ case Block ( DefDef (_, _, _, _, Trees .Block (body :: Nil , Trees .If (cond, _, _))) :: Nil , y) if y.symbol.name == nme.DO_WHILE_PREFIX =>
2425 keywordText(" do" ) ~ toText(body) ~ keywordText(" while" ) ~ " (" ~ toText(cond) ~ " )"
25- case _ => super .blockText(trees.filterNot(_.isInstanceOf [Closure [_]]))
26+ case Block ((meth @ DefDef (nme.ANON_FUN , _, _, _, _)) :: Nil , _ : Closure [T ]) =>
27+ withEnclosingDef(meth) {
28+ addVparamssText(" " , meth.vparamss) ~ " => " ~ toText(meth.rhs)
29+ }
30+ case _ =>
31+ super .blockToText(block)
2632 }
27- }
2833
2934 override protected def packageDefText (tree : PackageDef ): Text = {
3035 val stats = tree.stats.filter {
@@ -53,16 +58,4 @@ class DecompilerPrinter(_ctx: Context) extends RefinedPrinter(_ctx) {
5358 val impl1 = impl.copy(parents = impl.parents.filterNot(_.symbol.maybeOwner == defn.ObjectClass ))
5459 super .toTextTemplate(impl1, ofNew)
5560 }
56-
57- override protected def defDefToText [T >: Untyped ](tree : DefDef [T ]): Text = {
58- import untpd .{modsDeco => _ , _ }
59- dclTextOr(tree) {
60- val printLambda = tree.symbol.isAnonymousFunction
61- val prefix = modText(tree.mods, keywordStr(" def" )) ~~ valDefText(nameIdText(tree)) provided (! printLambda)
62- withEnclosingDef(tree) {
63- addVparamssText(prefix ~ tparamsText(tree.tparams), tree.vparamss) ~ optAscription(tree.tpt).provided(! printLambda) ~
64- optText(tree.rhs)((if (printLambda) " => " else " = " ) ~ _)
65- }
66- }
67- }
6861}
0 commit comments