@@ -190,6 +190,8 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
190
190
if (flags.isImplicit) this += " implicit "
191
191
if (flags.isOverride) this += " override "
192
192
193
+ printProtectedOrPrivate(vdef)
194
+
193
195
if (flags.isLazy) this += " lazy "
194
196
if (vdef.flags.isMutable) this += " var "
195
197
else this += " val "
@@ -220,12 +222,14 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
220
222
case ddef @ DefDef (name, targs, argss, tpt, rhs) =>
221
223
printDefAnnotations(ddef)
222
224
225
+ val isConstructor = name == " <init>"
226
+
223
227
val flags = ddef.flags
224
228
if (flags.isImplicit) this += " implicit "
225
229
if (flags.isInline) this += " inline "
226
230
if (flags.isOverride) this += " override "
227
231
228
- val isConstructor = name == " <init> "
232
+ printProtectedOrPrivate(ddef)
229
233
230
234
this += " def " += (if (isConstructor) " this" else name)
231
235
printTargsDefs(targs)
@@ -595,9 +599,9 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
595
599
596
600
def printSeparated (list : List [ValDef ]): Unit = list match {
597
601
case Nil =>
598
- case x :: Nil => printArgDef (x)
602
+ case x :: Nil => printParamDef (x)
599
603
case x :: xs =>
600
- printArgDef (x)
604
+ printParamDef (x)
601
605
this += " , "
602
606
printSeparated(xs)
603
607
}
@@ -619,15 +623,24 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
619
623
this
620
624
}
621
625
622
- def printArgDef (arg : ValDef ): Unit = {
626
+ def printParamDef (arg : ValDef ): Unit = {
623
627
val ValDef (name, tpt, rhs) = arg
624
628
arg.owner match {
625
629
case DefDef (" <init>" , _, _, _, _) =>
626
630
val ClassDef (_, _, _, _, body) = arg.owner.owner
627
631
body.collectFirst {
628
632
case vdef @ ValDef (`name`, _, _) if vdef.flags.isParamAccessor =>
629
- if (! vdef.flags.isLocal && ! vdef.flags.isCaseAcessor)
630
- this += " val " // TODO `var`s
633
+ if (! vdef.flags.isLocal) {
634
+ var printedPrefix = false
635
+ if (vdef.flags.isOverride) {
636
+ this += " override "
637
+ printedPrefix = true
638
+ }
639
+ printedPrefix |= printProtectedOrPrivate(vdef)
640
+ if (vdef.flags.isMutable) this += " var "
641
+ else if (! printedPrefix && vdef.flags.isCaseAcessor) this // val not explicitly needed
642
+ else this += " val "
643
+ }
631
644
}
632
645
case _ =>
633
646
}
@@ -896,15 +909,8 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
896
909
897
910
case Type .ThisType (tp) =>
898
911
tp match {
899
- case Type .SymRef (cdef @ ClassDef (name, _, _, _, _), prefix) if ! cdef.flags.isObject =>
900
- def printPrefix (prefix : TypeOrBounds ): Unit = prefix match {
901
- case Type .SymRef (ClassDef (name, _, _, _, _), prefix2) =>
902
- printPrefix(prefix2)
903
- this += name += " ."
904
- case _ =>
905
- }
906
- printPrefix(prefix)
907
- this += name
912
+ case Type .SymRef (cdef @ ClassDef (_, _, _, _, _), _) if ! cdef.flags.isObject =>
913
+ printFullClassName(tp)
908
914
this += " .this"
909
915
case _ => printType(tp)
910
916
}
@@ -1053,6 +1059,48 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
1053
1059
printType(hi)
1054
1060
}
1055
1061
1062
+ def printProtectedOrPrivate (definition : Definition ): Boolean = {
1063
+ var printedPrefix = false
1064
+ def printWithin (within : Type ) = within match {
1065
+ case Type .SymRef (PackageDef (name, _), _) => this += name
1066
+ case _ => printFullClassName(within)
1067
+ }
1068
+ if (definition.flags.isProtected) {
1069
+ this += " protected"
1070
+ definition.protectedWithin match {
1071
+ case Some (within) =>
1072
+ this += " ["
1073
+ printWithin(within)
1074
+ this += " ] "
1075
+ case _ =>
1076
+ this += " "
1077
+ }
1078
+ printedPrefix = true
1079
+ } else {
1080
+ definition.privateWithin match {
1081
+ case Some (within) =>
1082
+ this += " private["
1083
+ printWithin(within)
1084
+ this += " ] "
1085
+ printedPrefix = true
1086
+ case _ =>
1087
+ }
1088
+ }
1089
+ printedPrefix
1090
+ }
1091
+
1092
+ def printFullClassName (tp : TypeOrBounds ): Unit = {
1093
+ def printClassPrefix (prefix : TypeOrBounds ): Unit = prefix match {
1094
+ case Type .SymRef (ClassDef (name, _, _, _, _), prefix2) =>
1095
+ printClassPrefix(prefix2)
1096
+ this += name += " ."
1097
+ case _ =>
1098
+ }
1099
+ val Type .SymRef (ClassDef (name, _, _, _, _), prefix) = tp
1100
+ printClassPrefix(prefix)
1101
+ this += name
1102
+ }
1103
+
1056
1104
def += (x : Boolean ): this .type = { sb.append(x); this }
1057
1105
def += (x : Byte ): this .type = { sb.append(x); this }
1058
1106
def += (x : Short ): this .type = { sb.append(x); this }
0 commit comments