@@ -5,6 +5,7 @@ import dotty.tools.dotc.ast.untpd.{PackageDef, Template, TypeDef}
5
5
import dotty .tools .dotc .ast .{Trees , untpd }
6
6
import dotty .tools .dotc .printing .Texts ._
7
7
import dotty .tools .dotc .core .Contexts ._
8
+ import dotty .tools .dotc .core .StdNames .nme
8
9
import dotty .tools .dotc .core .Flags ._
9
10
import dotty .tools .dotc .core .Symbols ._
10
11
import dotty .tools .dotc .core .StdNames ._
@@ -16,15 +17,19 @@ class DecompilerPrinter(_ctx: Context) extends RefinedPrinter(_ctx) {
16
17
override protected def filterModTextAnnots (annots : List [untpd.Tree ]): List [untpd.Tree ] =
17
18
annots.filter(_.tpe != defn.SourceFileAnnotType )
18
19
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 =>
22
23
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 =>
24
25
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)
26
32
}
27
- }
28
33
29
34
override protected def packageDefText (tree : PackageDef ): Text = {
30
35
val stats = tree.stats.filter {
@@ -53,16 +58,4 @@ class DecompilerPrinter(_ctx: Context) extends RefinedPrinter(_ctx) {
53
58
val impl1 = impl.copy(parents = impl.parents.filterNot(_.symbol.maybeOwner == defn.ObjectClass ))
54
59
super .toTextTemplate(impl1, ofNew)
55
60
}
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
- }
68
61
}
0 commit comments