@@ -70,11 +70,13 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
70
70
71
71
val flags = cdef.flags
72
72
if (flags.isImplicit) this += " implicit "
73
+ if (flags.isSealed) this += " sealed "
73
74
if (flags.isFinal && ! flags.isObject) this += " final "
74
75
if (flags.isCase) this += " case "
75
76
76
77
if (flags.isObject) this += " object " += name.stripSuffix(" $" )
77
78
else if (flags.isTrait) this += " trait " += name
79
+ else if (flags.isAbstract) this += " abstract class " += name
78
80
else this += " class " += name
79
81
80
82
if (! flags.isObject) {
@@ -549,29 +551,14 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
549
551
550
552
def printTargDef (arg : TypeDef , isMember : Boolean = false ): Buffer = {
551
553
val TypeDef (name, rhs) = arg
552
- def printBounds (bounds : TypeBoundsTree ): Buffer = {
553
- val TypeBoundsTree (lo, hi) = bounds
554
- lo match {
555
- case TypeTree .Synthetic () =>
556
- case _ =>
557
- this += " >: "
558
- printTypeTree(lo)
559
- }
560
- hi match {
561
- case TypeTree .Synthetic () => this
562
- case _ =>
563
- this += " <: "
564
- printTypeTree(hi)
565
- }
566
- }
567
554
this += name
568
555
rhs match {
569
- case rhs @ TypeBoundsTree (lo, hi) => printBounds (rhs)
556
+ case rhs @ TypeBoundsTree (lo, hi) => printBoundsTree (rhs)
570
557
case rhs @ SyntheticBounds () =>
571
558
printTypeOrBound(rhs.tpe)
572
559
case rhs @ TypeTree .TypeLambdaTree (tparams, body) =>
573
560
def printParam (t : TypeOrBoundsTree ): Unit = t match {
574
- case t @ TypeBoundsTree (_, _) => printBounds (t)
561
+ case t @ TypeBoundsTree (_, _) => printBoundsTree (t)
575
562
case t @ TypeTree () => printTypeTree(t)
576
563
}
577
564
def printSeparated (list : List [TypeDef ]): Unit = list match {
@@ -835,12 +822,14 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
835
822
case Type .SymRef (sym, prefix) =>
836
823
prefix match {
837
824
case Types .EmptyPrefix () =>
838
- case prefix@ Type .SymRef (ClassDef (_, _, _, _, _), _) =>
825
+ case prefix @ Type .SymRef (ClassDef (_, _, _, _, _), _) =>
839
826
printType(prefix)
840
827
this += " #"
841
- case prefix@ Type () =>
842
- printType(prefix)
843
- this += " ."
828
+ case prefix @ Type () =>
829
+ if (! sym.flags.isLocal) {
830
+ printType(prefix)
831
+ this += " ."
832
+ }
844
833
}
845
834
printDefinitionName(sym)
846
835
@@ -864,9 +853,8 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
864
853
}
865
854
this += name.stripSuffix(" $" )
866
855
867
- case Type .Refinement (parent, name, info) =>
868
- printType(parent)
869
- // TODO add refinements
856
+ case tpe @ Type .Refinement (_, _, _) =>
857
+ printRefinement(tpe)
870
858
871
859
case Type .AppliedType (tp, args) =>
872
860
printType(tp)
@@ -911,25 +899,7 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
911
899
912
900
case Type .TypeLambda (paramNames, tparams, body) =>
913
901
this += " ["
914
- def printBounds (bounds : TypeBounds ): Buffer = {
915
- val TypeBounds (lo, hi) = bounds
916
- this += " >: "
917
- printType(lo)
918
- this += " <: "
919
- printType(hi)
920
- }
921
- def printSeparated (list : List [(String , TypeBounds )]): Unit = list match {
922
- case Nil =>
923
- case (name, bounds) :: Nil =>
924
- this += name
925
- printBounds(bounds)
926
- case (name, bounds) :: xs =>
927
- this += name
928
- printBounds(bounds)
929
- this += " , "
930
- printSeparated(xs)
931
- }
932
- printSeparated(paramNames.zip(tparams))
902
+ printMethodicTypeParams(paramNames, tparams)
933
903
this += " ] => "
934
904
printTypeOrBound(body)
935
905
@@ -982,6 +952,95 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
982
952
else this
983
953
}
984
954
955
+ def printRefinement (tpe : Type ): Buffer = {
956
+ def printMethodicType (tp : TypeOrBounds ): Unit = tp match {
957
+ case tp @ Type .MethodType (paramNames, params, res) =>
958
+ this += " ("
959
+ printMethodicTypeParams(paramNames, params)
960
+ this += " )"
961
+ printMethodicType(res)
962
+ case tp @ Type .TypeLambda (paramNames, params, res) =>
963
+ this += " ["
964
+ printMethodicTypeParams(paramNames, params)
965
+ this += " ]"
966
+ printMethodicType(res)
967
+ case Type .ByNameType (t) =>
968
+ this += " : "
969
+ printType(t)
970
+ case tp @ Type () =>
971
+ this += " : "
972
+ printType(tp)
973
+ }
974
+ def rec (tp : Type ): Unit = tp match {
975
+ case Type .Refinement (parent, name, info) =>
976
+ rec(parent)
977
+ indented {
978
+ this += lineBreak()
979
+ info match {
980
+ case info @ TypeBounds (_, _) =>
981
+ this += " type " += name
982
+ printBounds(info)
983
+ case Type .ByNameType (_) | Type .MethodType (_, _, _) | Type .TypeLambda (_, _, _) =>
984
+ this += " def " += name
985
+ printMethodicType(info)
986
+ case info @ Type () =>
987
+ this += " val " += name
988
+ printMethodicType(info)
989
+ }
990
+ }
991
+ case tp =>
992
+ printType(tp)
993
+ this += " {"
994
+ }
995
+ rec(tpe)
996
+ this += lineBreak() += " }"
997
+ }
998
+
999
+ def printMethodicTypeParams (paramNames : List [String ], params : List [TypeOrBounds ]): Unit = {
1000
+ def printInfo (info : TypeOrBounds ) = info match {
1001
+ case info @ TypeBounds (_, _) => printBounds(info)
1002
+ case info @ Type () =>
1003
+ this += " : "
1004
+ printType(info)
1005
+ }
1006
+ def printSeparated (list : List [(String , TypeOrBounds )]): Unit = list match {
1007
+ case Nil =>
1008
+ case (name, info) :: Nil =>
1009
+ this += name
1010
+ printInfo(info)
1011
+ case (name, info) :: xs =>
1012
+ this += name
1013
+ printInfo(info)
1014
+ this += " , "
1015
+ printSeparated(xs)
1016
+ }
1017
+ printSeparated(paramNames.zip(params))
1018
+ }
1019
+
1020
+ def printBoundsTree (bounds : TypeBoundsTree ): Buffer = {
1021
+ val TypeBoundsTree (lo, hi) = bounds
1022
+ lo match {
1023
+ case TypeTree .Synthetic () =>
1024
+ case _ =>
1025
+ this += " >: "
1026
+ printTypeTree(lo)
1027
+ }
1028
+ hi match {
1029
+ case TypeTree .Synthetic () => this
1030
+ case _ =>
1031
+ this += " <: "
1032
+ printTypeTree(hi)
1033
+ }
1034
+ }
1035
+
1036
+ def printBounds (bounds : TypeBounds ): Buffer = {
1037
+ val TypeBounds (lo, hi) = bounds
1038
+ this += " >: "
1039
+ printType(lo)
1040
+ this += " <: "
1041
+ printType(hi)
1042
+ }
1043
+
985
1044
def += (x : Boolean ): this .type = { sb.append(x); this }
986
1045
def += (x : Byte ): this .type = { sb.append(x); this }
987
1046
def += (x : Short ): this .type = { sb.append(x); this }
0 commit comments