@@ -74,6 +74,7 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
74
74
75
75
if (flags.isObject) this += " object " += name.stripSuffix(" $" )
76
76
else if (flags.isTrait) this += " trait " += name
77
+ else if (flags.isAbstract) this += " abstract class " += name
77
78
else this += " class " += name
78
79
79
80
if (! flags.isObject) {
@@ -504,29 +505,14 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
504
505
505
506
def printTargDef (arg : TypeDef , isMember : Boolean = false ): Buffer = {
506
507
val TypeDef (name, rhs) = arg
507
- def printBounds (bounds : TypeBoundsTree ): Buffer = {
508
- val TypeBoundsTree (lo, hi) = bounds
509
- lo match {
510
- case TypeTree .Synthetic () =>
511
- case _ =>
512
- this += " >: "
513
- printTypeTree(lo)
514
- }
515
- hi match {
516
- case TypeTree .Synthetic () => this
517
- case _ =>
518
- this += " <: "
519
- printTypeTree(hi)
520
- }
521
- }
522
508
this += name
523
509
rhs match {
524
- case rhs @ TypeBoundsTree (lo, hi) => printBounds (rhs)
510
+ case rhs @ TypeBoundsTree (lo, hi) => printBoundsTree (rhs)
525
511
case rhs @ SyntheticBounds () =>
526
512
printTypeOrBound(rhs.tpe)
527
513
case rhs @ TypeTree .TypeLambdaTree (tparams, body) =>
528
514
def printParam (t : TypeOrBoundsTree ): Unit = t match {
529
- case t @ TypeBoundsTree (_, _) => printBounds (t)
515
+ case t @ TypeBoundsTree (_, _) => printBoundsTree (t)
530
516
case t @ TypeTree () => printTypeTree(t)
531
517
}
532
518
def printSeparated (list : List [TypeDef ]): Unit = list match {
@@ -824,9 +810,50 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
824
810
}
825
811
this += name.stripSuffix(" $" )
826
812
827
- case Type .Refinement (parent, name, info) =>
828
- printType(parent)
829
- // TODO add refinements
813
+ case tpe @ Type .Refinement (_, _, _) =>
814
+ def rec (tp : Type ): Unit = tp match {
815
+ case Type .Refinement (parent, name, info) =>
816
+ rec(parent)
817
+ indented {
818
+ this += lineBreak()
819
+ info match {
820
+ case info @ TypeBounds (_, _) =>
821
+ this += " type " += name
822
+ printBounds(info)
823
+ case info @ Type () =>
824
+ info match {
825
+ case Type .ByNameType (_) | Type .MethodType (_, _, _) | Type .TypeLambda (_, _, _) =>
826
+ this += " def " += name
827
+ case _ =>
828
+ this += " val " += name
829
+ }
830
+ def printMethodicType (tp : Type ): Unit = tp match {
831
+ case tp @ Type .MethodType (paramNames, params, res) =>
832
+ this += " ("
833
+ printMethodicTypeParams(paramNames, params)
834
+ this += " )"
835
+ printMethodicType(res)
836
+ case tp @ Type .TypeLambda (paramNames, params, res) =>
837
+ this += " ["
838
+ printMethodicTypeParams(paramNames, params)
839
+ this += " ]"
840
+ printMethodicType(res)
841
+ case Type .ByNameType (t) =>
842
+ this += " : "
843
+ printType(t)
844
+ case tp @ Type () =>
845
+ this += " : "
846
+ printType(tp)
847
+ }
848
+ printMethodicType(info)
849
+ }
850
+ }
851
+ case tp =>
852
+ printType(tp)
853
+ this += " {"
854
+ }
855
+ rec(tpe)
856
+ this += lineBreak() += " }"
830
857
831
858
case Type .AppliedType (tp, args) =>
832
859
printType(tp)
@@ -861,27 +888,15 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
861
888
case _ => this
862
889
}
863
890
891
+ case Type .MethodType (paramNames, params, body) =>
892
+ this += " ("
893
+ printMethodicTypeParams(paramNames, params)
894
+ this += " ) => "
895
+ printTypeOrBound(body)
896
+
864
897
case Type .TypeLambda (paramNames, tparams, body) =>
865
898
this += " ["
866
- def printBounds (bounds : TypeBounds ): Buffer = {
867
- val TypeBounds (lo, hi) = bounds
868
- this += " >: "
869
- printType(lo)
870
- this += " <: "
871
- printType(hi)
872
- }
873
- def printSeparated (list : List [(String , TypeBounds )]): Unit = list match {
874
- case Nil =>
875
- case (name, bounds) :: Nil =>
876
- this += name
877
- printBounds(bounds)
878
- case (name, bounds) :: xs =>
879
- this += name
880
- printBounds(bounds)
881
- this += " , "
882
- printSeparated(xs)
883
- }
884
- printSeparated(paramNames.zip(tparams))
899
+ printMethodicTypeParams(paramNames, tparams)
885
900
this += " ] => "
886
901
printTypeOrBound(body)
887
902
@@ -934,6 +949,51 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
934
949
else this
935
950
}
936
951
952
+ def printMethodicTypeParams (paramNames : List [String ], params : List [TypeOrBounds ]): Unit = {
953
+ def printInfo (info : TypeOrBounds ) = info match {
954
+ case info @ TypeBounds (_, _) => printBounds(info)
955
+ case info @ Type () =>
956
+ this += " : "
957
+ printType(info)
958
+ }
959
+ def printSeparated (list : List [(String , TypeOrBounds )]): Unit = list match {
960
+ case Nil =>
961
+ case (name, info) :: Nil =>
962
+ this += name
963
+ printInfo(info)
964
+ case (name, info) :: xs =>
965
+ this += name
966
+ printInfo(info)
967
+ this += " , "
968
+ printSeparated(xs)
969
+ }
970
+ printSeparated(paramNames.zip(params))
971
+ }
972
+
973
+ def printBoundsTree (bounds : TypeBoundsTree ): Buffer = {
974
+ val TypeBoundsTree (lo, hi) = bounds
975
+ lo match {
976
+ case TypeTree .Synthetic () =>
977
+ case _ =>
978
+ this += " >: "
979
+ printTypeTree(lo)
980
+ }
981
+ hi match {
982
+ case TypeTree .Synthetic () => this
983
+ case _ =>
984
+ this += " <: "
985
+ printTypeTree(hi)
986
+ }
987
+ }
988
+
989
+ def printBounds (bounds : TypeBounds ): Buffer = {
990
+ val TypeBounds (lo, hi) = bounds
991
+ this += " >: "
992
+ printType(lo)
993
+ this += " <: "
994
+ printType(hi)
995
+ }
996
+
937
997
def += (x : Boolean ): this .type = { sb.append(x); this }
938
998
def += (x : Byte ): this .type = { sb.append(x); this }
939
999
def += (x : Short ): this .type = { sb.append(x); this }
0 commit comments