Skip to content

Commit b5bd270

Browse files
committed
Fix some stuff
1 parent bbb8eda commit b5bd270

File tree

1 file changed

+34
-6
lines changed

1 file changed

+34
-6
lines changed

library/src/scala/tasty/util/ShowSourceCode.scala

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,13 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
5757

5858
case cdef@ClassDef(name, DefDef(_, targs, argss, _, _), parents, self, stats) =>
5959
val flags = cdef.flags
60+
if (flags.isFinal && !flags.isObject) this += "final "
6061
if (flags.isCase) this += "case "
6162

62-
if (cdef.flags.isObject) this += "object " += name.stripSuffix("$")
63+
if (flags.isObject) this += "object " += name.stripSuffix("$")
6364
else this += "class " += name
6465

65-
if (!cdef.flags.isObject) {
66+
if (!flags.isObject) {
6667
printTargsDefs(targs)
6768
val it = argss.iterator
6869
while (it.hasNext)
@@ -200,7 +201,9 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
200201
this += "]"
201202

202203
case Term.Super(qual, tptOpt) =>
203-
???
204+
printTree(qual)
205+
this += ".super"
206+
// TODO use tptOpt?
204207

205208
case Term.Typed(term, tpt) =>
206209
this += "("
@@ -531,7 +534,11 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
531534
printType(tree.tpe)
532535

533536
case TypeTree.TypeSelect(qual, name) =>
534-
printTree(qual) += "." += name
537+
(qual: Any) match {
538+
case qual @ TypeTree.TypeIdent(_) => printTypeTree(qual) // FIXME: qual is of type Tree buy we are getting a TypeTree qualifier
539+
case _ => printTree(qual)
540+
}
541+
this += "." += name
535542

536543
case TypeTree.Singleton(ref) =>
537544
printTree(ref)
@@ -586,7 +593,8 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
586593

587594
case Type.SymRef(sym, prefix) =>
588595
prefix match {
589-
case Type.ThisType(Type.SymRef(PackageDef(pack, _), NoPrefix())) if pack == "<root>" || pack == "<empty>" =>
596+
case EmptyPackage() =>
597+
case RootPackage() =>
590598
case prefix@Type.SymRef(ClassDef(_, _, _, _, _), _) =>
591599
printType(prefix)
592600
this += "#"
@@ -610,10 +618,10 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
610618

611619
case Type.TypeRef(name, prefix) =>
612620
prefix match {
621+
case NoPrefix() =>
613622
case prefix@Type() =>
614623
printType(prefix)
615624
this += "."
616-
case NoPrefix() =>
617625
}
618626
this += name.stripSuffix("$")
619627

@@ -714,4 +722,24 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
714722
case _ => false
715723
}
716724
}
725+
726+
private object RootPackage {
727+
def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Boolean = tpe match {
728+
case Type.ThisType(Type.SymRef(PackageDef("<root>", _), NoPrefix())) => true
729+
case _ => false
730+
}
731+
}
732+
733+
private object EmptyPackage {
734+
def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Boolean = tpe match {
735+
case Type.ThisType(Type.SymRef(PackageDef("<empty>", _), prefix)) =>
736+
prefix match {
737+
case NoPrefix() => true
738+
case RootPackage() => true
739+
case _ => false
740+
}
741+
case _ => false
742+
}
743+
}
744+
717745
}

0 commit comments

Comments
 (0)