@@ -41,22 +41,31 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
41
41
def doubleLineBreak (): String = " \n\n " + (" " * indent)
42
42
43
43
def printTree (tree : Tree ): Buffer = tree match {
44
- case tree @ PackageClause (Term .Ident (name), stats) =>
44
+ case PackageObject (body)=>
45
+ printTree(body) // Print package object
46
+
47
+ case PackageClause (Term .Ident (name), (inner @ PackageClause (_, _)) :: Nil ) if name != " <empty>" && PackageObject .unapply(inner).isEmpty =>
48
+ // print inner package as `package outer.inner { ... }`
49
+ printTree(inner)
50
+
51
+ case tree @ PackageClause (name, stats) =>
45
52
val stats1 = stats.collect {
46
53
case stat @ PackageClause (_, _) => stat
47
54
case stat @ Definition () if ! (stat.flags.isObject && stat.flags.isLazy) => stat
48
55
case stat @ Import (_, _) => stat
49
56
}
50
-
51
- if (name == " <empty>" ) {
52
- printTrees(stats1, lineBreak())
53
- } else {
54
- this += " package " += name += " {"
55
- indented {
56
- this += lineBreak()
57
+ name match {
58
+ case Term .Ident (" <empty>" ) =>
57
59
printTrees(stats1, lineBreak())
58
- }
59
- this += lineBreak() += " }"
60
+ case _ =>
61
+ this += " package "
62
+ printType(name.tpe)
63
+ this += " {"
64
+ indented {
65
+ this += lineBreak()
66
+ printTrees(stats1, lineBreak())
67
+ }
68
+ this += lineBreak() += " }"
60
69
}
61
70
62
71
case Import (expr, selectors) =>
@@ -74,7 +83,11 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
74
83
if (flags.isFinal && ! flags.isObject) this += " final "
75
84
if (flags.isCase) this += " case "
76
85
77
- if (flags.isObject) this += " object " += name.stripSuffix(" $" )
86
+ if (name == " package$" ) {
87
+ this += " package object "
88
+ printDefinitionName(cdef.owner)
89
+ }
90
+ else if (flags.isObject) this += " object " += name.stripSuffix(" $" )
78
91
else if (flags.isTrait) this += " trait " += name
79
92
else if (flags.isAbstract) this += " abstract class " += name
80
93
else this += " class " += name
@@ -1136,5 +1149,11 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
1136
1149
}
1137
1150
}
1138
1151
1152
+ object PackageObject {
1153
+ def unapply (tree : Tree )(implicit ctx : Context ): Option [Tree ] = tree match {
1154
+ case PackageClause (_, ValDef (" package" , _, _) :: body :: Nil ) => Some (body)
1155
+ case _ => None
1156
+ }
1157
+ }
1139
1158
1140
1159
}
0 commit comments