1
1
package dotty .tools .dotc .printing
2
2
3
- import dotty .tools .dotc .ast .Trees .{ Closure , DefDef , Untyped , ValDef }
3
+ import dotty .tools .dotc .ast .Trees ._
4
4
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
8
import dotty .tools .dotc .core .Flags ._
9
9
import dotty .tools .dotc .core .Symbols ._
10
+ import dotty .tools .dotc .core .StdNames ._
10
11
11
12
import scala .language .implicitConversions
12
13
@@ -16,7 +17,13 @@ class DecompilerPrinter(_ctx: Context) extends RefinedPrinter(_ctx) {
16
17
annots.filter(_.tpe != defn.SourceFileAnnotType )
17
18
18
19
override protected def blockText [T >: Untyped ](trees : List [Trees .Tree [T ]]): Text = {
19
- super .blockText(trees.filterNot(_.isInstanceOf [Closure [_]]))
20
+ trees match {
21
+ case DefDef (_, _, _, _, Trees .If (cond, Trees .Block (body :: Nil , _), _)) :: y :: Nil if y.symbol.name == nme.WHILE_PREFIX =>
22
+ 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
+ keywordText(" do" ) ~ toText(body) ~ keywordText(" while" ) ~ " (" ~ toText(cond) ~ " )"
25
+ case _ => super .blockText(trees.filterNot(_.isInstanceOf [Closure [_]]))
26
+ }
20
27
}
21
28
22
29
override protected def packageDefText (tree : PackageDef ): Text = {
@@ -29,8 +36,10 @@ class DecompilerPrinter(_ctx: Context) extends RefinedPrinter(_ctx) {
29
36
case _ => toTextGlobal(stats, " \n " )
30
37
}
31
38
val bodyText =
32
- if (currentPrecedence == TopLevelPrec ) " \n " ~ statsText else " {" ~ statsText ~ " }"
33
- keywordStr(" package " ) ~ toTextPackageId(tree.pid) ~ bodyText
39
+ if (tree.pid.symbol.isEmptyPackage) statsText
40
+ else if (currentPrecedence == TopLevelPrec ) " \n " ~ statsText
41
+ else " {" ~ statsText ~ " }"
42
+ (keywordStr(" package " ) ~ toTextPackageId(tree.pid)).provided(! tree.symbol.isEmptyPackage) ~ bodyText
34
43
}
35
44
36
45
override protected def templateText (tree : TypeDef , impl : Template ): Text = {
@@ -40,6 +49,11 @@ class DecompilerPrinter(_ctx: Context) extends RefinedPrinter(_ctx) {
40
49
decl ~~ typeText(nameIdText(tree)) ~ withEnclosingDef(tree) { toTextTemplate(impl) } ~ " "
41
50
}
42
51
52
+ override protected def toTextTemplate (impl : Template , ofNew : Boolean = false ): Text = {
53
+ val impl1 = impl.copy(parents = impl.parents.filterNot(_.symbol.maybeOwner == defn.ObjectClass ))
54
+ super .toTextTemplate(impl1, ofNew)
55
+ }
56
+
43
57
override protected def defDefToText [T >: Untyped ](tree : DefDef [T ]): Text = {
44
58
import untpd .{modsDeco => _ , _ }
45
59
dclTextOr(tree) {
0 commit comments