@@ -67,7 +67,10 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
67
67
68
68
override protected def recursionLimitExceeded (): Unit = {}
69
69
70
- protected val PrintableFlags : FlagSet = (SourceModifierFlags | Label | Module | Local ).toCommonFlags
70
+ protected def PrintableFlags (isType : Boolean ): FlagSet = {
71
+ if (isType) TypeSourceModifierFlags | Module | Local
72
+ else TermSourceModifierFlags | Label | Module | Local
73
+ }.toCommonFlags
71
74
72
75
override def nameString (name : Name ): String =
73
76
if (ctx.settings.YdebugNames .value) name.debugString else name.toString
@@ -435,7 +438,8 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
435
438
case tree @ TypeDef (name, rhs) =>
436
439
def typeDefText (tparamsText : => Text , rhsText : => Text ) =
437
440
dclTextOr(tree) {
438
- modText(tree.mods, tree.symbol, keywordStr(" type" )) ~~ (varianceText(tree.mods) ~ typeText(nameIdText(tree))) ~
441
+ modText(tree.mods, tree.symbol, keywordStr(" type" ), isType = true ) ~~
442
+ (varianceText(tree.mods) ~ typeText(nameIdText(tree))) ~
439
443
withEnclosingDef(tree) { tparamsText ~ rhsText }
440
444
}
441
445
def recur (rhs : Tree , tparamsTxt : => Text ): Text = rhs match {
@@ -474,7 +478,8 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
474
478
else toText(t)
475
479
case tree @ ModuleDef (name, impl) =>
476
480
withEnclosingDef(tree) {
477
- modText(tree.mods, NoSymbol , keywordStr(" object" )) ~~ nameIdText(tree) ~ toTextTemplate(impl)
481
+ modText(tree.mods, NoSymbol , keywordStr(" object" ), isType = false ) ~~
482
+ nameIdText(tree) ~ toTextTemplate(impl)
478
483
}
479
484
case SymbolLit (str) =>
480
485
" '" + str
@@ -529,8 +534,8 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
529
534
t ~ cxBoundToText(cxb)
530
535
}
531
536
case PatDef (mods, pats, tpt, rhs) =>
532
- modText(mods, NoSymbol , keywordStr(" val" )) ~~ toText(pats, " , " ) ~ optAscription(tpt) ~
533
- optText(rhs)(" = " ~ _)
537
+ modText(mods, NoSymbol , keywordStr(" val" ), isType = false ) ~ ~
538
+ toText(pats, " , " ) ~ optAscription(tpt) ~ optText(rhs)(" = " ~ _)
534
539
case ParsedTry (expr, handler, finalizer) =>
535
540
changePrec(GlobalPrec ) {
536
541
keywordStr(" try " ) ~ toText(expr) ~ " " ~ keywordStr(" catch" ) ~ " {" ~ toText(handler) ~ " }" ~ optText(finalizer)(keywordStr(" finally " ) ~ _)
@@ -653,7 +658,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
653
658
protected def valDefToText [T >: Untyped ](tree : ValDef [T ]): Text = {
654
659
import untpd .{modsDeco => _ }
655
660
dclTextOr(tree) {
656
- modText(tree.mods, tree.symbol, keywordStr(if (tree.mods is Mutable ) " var" else " val" )) ~~
661
+ modText(tree.mods, tree.symbol, keywordStr(if (tree.mods is Mutable ) " var" else " val" ), isType = false ) ~~
657
662
valDefText(nameIdText(tree)) ~ optAscription(tree.tpt) ~
658
663
withEnclosingDef(tree) { optText(tree.rhs)(" = " ~ _) }
659
664
}
@@ -662,7 +667,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
662
667
protected def defDefToText [T >: Untyped ](tree : DefDef [T ]): Text = {
663
668
import untpd .{modsDeco => _ }
664
669
dclTextOr(tree) {
665
- val prefix = modText(tree.mods, tree.symbol, keywordStr(" def" )) ~~ valDefText(nameIdText(tree))
670
+ val prefix = modText(tree.mods, tree.symbol, keywordStr(" def" ), isType = false ) ~~ valDefText(nameIdText(tree))
666
671
withEnclosingDef(tree) {
667
672
addVparamssText(prefix ~ tparamsText(tree.tparams), tree.vparamss) ~ optAscription(tree.tpt) ~
668
673
optText(tree.rhs)(" = " ~ _)
@@ -677,7 +682,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
677
682
val prefix : Text =
678
683
if (vparamss.isEmpty || primaryConstrs.nonEmpty) tparamsTxt
679
684
else {
680
- var modsText = modText(constr.mods, constr.symbol, " " )
685
+ var modsText = modText(constr.mods, constr.symbol, " " , isType = false )
681
686
if (! modsText.isEmpty) modsText = " " ~ modsText
682
687
if (constr.mods.hasAnnotations && ! constr.mods.hasFlags) modsText = modsText ~~ " this"
683
688
withEnclosingDef(constr) { addVparamssText(tparamsTxt ~~ modsText, vparamss) }
@@ -704,7 +709,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
704
709
}
705
710
706
711
protected def templateText (tree : TypeDef , impl : Template ): Text = {
707
- val decl = modText(tree.mods, tree.symbol, keywordStr(if ((tree).mods is Trait ) " trait" else " class" ))
712
+ val decl = modText(tree.mods, tree.symbol, keywordStr(if ((tree).mods is Trait ) " trait" else " class" ), isType = true )
708
713
decl ~~ typeText(nameIdText(tree)) ~ withEnclosingDef(tree) { toTextTemplate(impl) } ~
709
714
(if (tree.hasType && ctx.settings.verbose.value) i " [decls = ${tree.symbol.info.decls}] " else " " )
710
715
}
@@ -727,12 +732,12 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
727
732
728
733
protected def annotText (tree : untpd.Tree ): Text = " @" ~ constrText(tree) // DD
729
734
730
- protected def modText (mods : untpd.Modifiers , sym : Symbol , kw : String , suppress : FlagSet = EmptyFlags ): Text = { // DD
735
+ protected def modText (mods : untpd.Modifiers , sym : Symbol , kw : String , isType : Boolean ): Text = { // DD
731
736
val suppressKw = if (enclDefIsClass) mods is ParamAndLocal else mods is Param
732
737
var flagMask =
733
738
if (ctx.settings.YdebugFlags .value) AnyFlags
734
- else if (suppressKw) PrintableFlags &~ Private &~ suppress
735
- else PrintableFlags &~ suppress
739
+ else if (suppressKw) PrintableFlags (isType) &~ Private
740
+ else PrintableFlags (isType)
736
741
if (homogenizedView && mods.flags.isTypeFlags) flagMask &~= Implicit // drop implicit from classes
737
742
val flags = (if (sym.exists) sym.flags else (mods.flags)) & flagMask
738
743
val flagsText = if (flags.isEmpty) " " else keywordStr(flags.toString)
@@ -807,7 +812,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
807
812
else {
808
813
var flags = sym.flagsUNSAFE
809
814
if (flags is TypeParam ) flags = flags &~ Protected
810
- Text ((flags & PrintableFlags ).flagStrings map (flag => stringToText(keywordStr(flag))), " " )
815
+ Text ((flags & PrintableFlags (sym.isType) ).flagStrings map (flag => stringToText(keywordStr(flag))), " " )
811
816
}
812
817
813
818
override def toText (denot : Denotation ): Text = denot match {
0 commit comments