@@ -41,7 +41,7 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
41
41
this += " )"
42
42
}
43
43
44
- def inSquareParens (body : => Unit ): Buffer = {
44
+ def inSquare (body : => Unit ): Buffer = {
45
45
this += " ["
46
46
body
47
47
this += " ]"
@@ -126,7 +126,7 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
126
126
def printParent (parent : Parent ): Unit = parent match {
127
127
case parent @ Term .TypeApply (fun, targs) =>
128
128
printParent(fun)
129
- inSquareParens (printTypeOrBoundsTrees(targs, " , " ))
129
+ inSquare (printTypeOrBoundsTrees(targs, " , " ))
130
130
131
131
case parent @ Term .Apply (fun, args) =>
132
132
printParent(fun)
@@ -215,6 +215,8 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
215
215
if (flags.isImplicit) this += " implicit "
216
216
if (flags.isOverride) this += " override "
217
217
218
+ printProtectedOrPrivate(vdef)
219
+
218
220
if (flags.isLazy) this += " lazy "
219
221
if (vdef.flags.isMutable) this += " var "
220
222
else this += " val "
@@ -242,12 +244,14 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
242
244
case ddef @ DefDef (name, targs, argss, tpt, rhs) =>
243
245
printDefAnnotations(ddef)
244
246
247
+ val isConstructor = name == " <init>"
248
+
245
249
val flags = ddef.flags
246
250
if (flags.isImplicit) this += " implicit "
247
251
if (flags.isInline) this += " inline "
248
252
if (flags.isOverride) this += " override "
249
253
250
- val isConstructor = name == " <init> "
254
+ printProtectedOrPrivate(ddef)
251
255
252
256
this += " def " += (if (isConstructor) " this" else name)
253
257
printTargsDefs(targs)
@@ -318,7 +322,7 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
318
322
// type bounds already printed in `fn`
319
323
this
320
324
case _ =>
321
- inSquareParens (printTypeOrBoundsTrees(args, " , " ))
325
+ inSquare (printTypeOrBoundsTrees(args, " , " ))
322
326
}
323
327
324
328
case Term .Super (qual, idOpt) =>
@@ -329,7 +333,7 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
329
333
this += " super"
330
334
for (id <- idOpt) {
331
335
val Id (name) = id
332
- inSquareParens (this += name)
336
+ inSquare (this += name)
333
337
}
334
338
this
335
339
@@ -549,7 +553,7 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
549
553
printSeparated(xs)
550
554
}
551
555
552
- inSquareParens (printSeparated(targs))
556
+ inSquare (printSeparated(targs))
553
557
}
554
558
}
555
559
@@ -578,7 +582,7 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
578
582
this += " , "
579
583
printSeparated(xs)
580
584
}
581
- inSquareParens (printSeparated(tparams))
585
+ inSquare (printSeparated(tparams))
582
586
if (isMember) {
583
587
this += " = "
584
588
printTypeOrBoundsTree(body)
@@ -600,9 +604,9 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
600
604
601
605
def printSeparated (list : List [ValDef ]): Unit = list match {
602
606
case Nil =>
603
- case x :: Nil => printArgDef (x)
607
+ case x :: Nil => printParamDef (x)
604
608
case x :: xs =>
605
- printArgDef (x)
609
+ printParamDef (x)
606
610
this += " , "
607
611
printSeparated(xs)
608
612
}
@@ -623,8 +627,28 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
623
627
this
624
628
}
625
629
626
- def printArgDef (arg : ValDef ): Unit = {
630
+ def printParamDef (arg : ValDef ): Unit = {
627
631
val ValDef (name, tpt, rhs) = arg
632
+ arg.owner match {
633
+ case DefDef (" <init>" , _, _, _, _) =>
634
+ val ClassDef (_, _, _, _, body) = arg.owner.owner
635
+ body.collectFirst {
636
+ case vdef @ ValDef (`name`, _, _) if vdef.flags.isParamAccessor =>
637
+ if (! vdef.flags.isLocal) {
638
+ var printedPrefix = false
639
+ if (vdef.flags.isOverride) {
640
+ this += " override "
641
+ printedPrefix = true
642
+ }
643
+ printedPrefix |= printProtectedOrPrivate(vdef)
644
+ if (vdef.flags.isMutable) this += " var "
645
+ else if (printedPrefix || ! vdef.flags.isCaseAcessor) this += " val "
646
+ else this // val not explicitly needed
647
+ }
648
+ }
649
+ case _ =>
650
+ }
651
+
628
652
this += name += " : "
629
653
printTypeTree(tpt)
630
654
}
@@ -704,7 +728,7 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
704
728
case Constant .String (v) => this += '"' += escapedString(v) += '"'
705
729
case Constant .ClassTag (v) =>
706
730
this += " classOf"
707
- inSquareParens (printType(v))
731
+ inSquare (printType(v))
708
732
}
709
733
710
734
def printTypeOrBoundsTree (tpt : TypeOrBoundsTree ): Buffer = tpt match {
@@ -761,7 +785,7 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
761
785
762
786
case TypeTree .Applied (tpt, args) =>
763
787
printTypeTree(tpt)
764
- inSquareParens (printTypeOrBoundsTrees(args, " , " ))
788
+ inSquare (printTypeOrBoundsTrees(args, " , " ))
765
789
766
790
case TypeTree .Annotated (tpt, annot) =>
767
791
val Annotation (ref, args) = annot
@@ -852,7 +876,7 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
852
876
this += " _*"
853
877
case _ =>
854
878
printType(tp)
855
- inSquareParens (printTypesOrBounds(args, " , " ))
879
+ inSquare (printTypesOrBounds(args, " , " ))
856
880
}
857
881
858
882
case Type .AnnotatedType (tp, annot) =>
@@ -877,21 +901,14 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
877
901
878
902
case Type .ThisType (tp) =>
879
903
tp match {
880
- case Type .SymRef (cdef @ ClassDef (name, _, _, _, _), prefix) if ! cdef.flags.isObject =>
881
- def printPrefix (prefix : TypeOrBounds ): Unit = prefix match {
882
- case Type .SymRef (ClassDef (name, _, _, _, _), prefix2) =>
883
- printPrefix(prefix2)
884
- this += name += " ."
885
- case _ =>
886
- }
887
- printPrefix(prefix)
888
- this += name
904
+ case Type .SymRef (cdef @ ClassDef (_, _, _, _, _), _) if ! cdef.flags.isObject =>
905
+ printFullClassName(tp)
889
906
this += " .this"
890
907
case _ => printType(tp)
891
908
}
892
909
893
910
case Type .TypeLambda (paramNames, tparams, body) =>
894
- inSquareParens (printMethodicTypeParams(paramNames, tparams))
911
+ inSquare (printMethodicTypeParams(paramNames, tparams))
895
912
this += " => "
896
913
printTypeOrBound(body)
897
914
@@ -948,7 +965,7 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
948
965
inParens(printMethodicTypeParams(paramNames, params))
949
966
printMethodicType(res)
950
967
case tp @ Type .TypeLambda (paramNames, params, res) =>
951
- inSquareParens (printMethodicTypeParams(paramNames, params))
968
+ inSquare (printMethodicTypeParams(paramNames, params))
952
969
printMethodicType(res)
953
970
case Type .ByNameType (t) =>
954
971
this += " : "
@@ -1027,6 +1044,46 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
1027
1044
printType(hi)
1028
1045
}
1029
1046
1047
+ def printProtectedOrPrivate (definition : Definition ): Boolean = {
1048
+ var prefixWasPrinted = false
1049
+ def printWithin (within : Type ) = within match {
1050
+ case Type .SymRef (PackageDef (name, _), _) => this += name
1051
+ case _ => printFullClassName(within)
1052
+ }
1053
+ if (definition.flags.isProtected) {
1054
+ this += " protected"
1055
+ definition.protectedWithin match {
1056
+ case Some (within) =>
1057
+ inSquare(printWithin(within))
1058
+ case _ =>
1059
+ }
1060
+ prefixWasPrinted = true
1061
+ } else {
1062
+ definition.privateWithin match {
1063
+ case Some (within) =>
1064
+ this += " private"
1065
+ inSquare(printWithin(within))
1066
+ prefixWasPrinted = true
1067
+ case _ =>
1068
+ }
1069
+ }
1070
+ if (prefixWasPrinted)
1071
+ this += " "
1072
+ prefixWasPrinted
1073
+ }
1074
+
1075
+ def printFullClassName (tp : TypeOrBounds ): Unit = {
1076
+ def printClassPrefix (prefix : TypeOrBounds ): Unit = prefix match {
1077
+ case Type .SymRef (ClassDef (name, _, _, _, _), prefix2) =>
1078
+ printClassPrefix(prefix2)
1079
+ this += name += " ."
1080
+ case _ =>
1081
+ }
1082
+ val Type .SymRef (ClassDef (name, _, _, _, _), prefix) = tp
1083
+ printClassPrefix(prefix)
1084
+ this += name
1085
+ }
1086
+
1030
1087
def += (x : Boolean ): this .type = { sb.append(x); this }
1031
1088
def += (x : Byte ): this .type = { sb.append(x); this }
1032
1089
def += (x : Short ): this .type = { sb.append(x); this }
0 commit comments