@@ -68,7 +68,10 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
68
68
69
69
override protected def recursionLimitExceeded (): Unit = {}
70
70
71
- protected val PrintableFlags : FlagSet = (SourceModifierFlags | Module | Local ).toCommonFlags
71
+ protected def PrintableFlags (isType : Boolean ): FlagSet = {
72
+ if (isType) TypeSourceModifierFlags | Module | Local
73
+ else TermSourceModifierFlags | Module | Local
74
+ }.toCommonFlags
72
75
73
76
override def nameString (name : Name ): String =
74
77
if (ctx.settings.YdebugNames .value) name.debugString else name.toString
@@ -440,7 +443,8 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
440
443
case tree @ TypeDef (name, rhs) =>
441
444
def typeDefText (tparamsText : => Text , rhsText : => Text ) =
442
445
dclTextOr(tree) {
443
- modText(tree.mods, tree.symbol, keywordStr(" type" )) ~~ (varianceText(tree.mods) ~ typeText(nameIdText(tree))) ~
446
+ modText(tree.mods, tree.symbol, keywordStr(" type" ), isType = true ) ~~
447
+ (varianceText(tree.mods) ~ typeText(nameIdText(tree))) ~
444
448
withEnclosingDef(tree) { tparamsText ~ rhsText }
445
449
}
446
450
def recur (rhs : Tree , tparamsTxt : => Text ): Text = rhs match {
@@ -479,7 +483,8 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
479
483
else toText(t)
480
484
case tree @ ModuleDef (name, impl) =>
481
485
withEnclosingDef(tree) {
482
- modText(tree.mods, NoSymbol , keywordStr(" object" )) ~~ nameIdText(tree) ~ toTextTemplate(impl)
486
+ modText(tree.mods, NoSymbol , keywordStr(" object" ), isType = false ) ~~
487
+ nameIdText(tree) ~ toTextTemplate(impl)
483
488
}
484
489
case SymbolLit (str) =>
485
490
" '" + str
@@ -534,8 +539,8 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
534
539
t ~ cxBoundToText(cxb)
535
540
}
536
541
case PatDef (mods, pats, tpt, rhs) =>
537
- modText(mods, NoSymbol , keywordStr(" val" )) ~~ toText(pats, " , " ) ~ optAscription(tpt) ~
538
- optText(rhs)(" = " ~ _)
542
+ modText(mods, NoSymbol , keywordStr(" val" ), isType = false ) ~ ~
543
+ toText(pats, " , " ) ~ optAscription(tpt) ~ optText(rhs)(" = " ~ _)
539
544
case ParsedTry (expr, handler, finalizer) =>
540
545
changePrec(GlobalPrec ) {
541
546
keywordStr(" try " ) ~ toText(expr) ~ " " ~ keywordStr(" catch" ) ~ " {" ~ toText(handler) ~ " }" ~ optText(finalizer)(keywordStr(" finally " ) ~ _)
@@ -658,7 +663,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
658
663
protected def valDefToText [T >: Untyped ](tree : ValDef [T ]): Text = {
659
664
import untpd .{modsDeco => _ }
660
665
dclTextOr(tree) {
661
- modText(tree.mods, tree.symbol, keywordStr(if (tree.mods is Mutable ) " var" else " val" )) ~~
666
+ modText(tree.mods, tree.symbol, keywordStr(if (tree.mods is Mutable ) " var" else " val" ), isType = false ) ~~
662
667
valDefText(nameIdText(tree)) ~ optAscription(tree.tpt) ~
663
668
withEnclosingDef(tree) { optText(tree.rhs)(" = " ~ _) }
664
669
}
@@ -667,7 +672,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
667
672
protected def defDefToText [T >: Untyped ](tree : DefDef [T ]): Text = {
668
673
import untpd .{modsDeco => _ }
669
674
dclTextOr(tree) {
670
- val prefix = modText(tree.mods, tree.symbol, keywordStr(" def" )) ~~ valDefText(nameIdText(tree))
675
+ val prefix = modText(tree.mods, tree.symbol, keywordStr(" def" ), isType = false ) ~~ valDefText(nameIdText(tree))
671
676
withEnclosingDef(tree) {
672
677
addVparamssText(prefix ~ tparamsText(tree.tparams), tree.vparamss) ~ optAscription(tree.tpt) ~
673
678
optText(tree.rhs)(" = " ~ _)
@@ -682,7 +687,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
682
687
val prefix : Text =
683
688
if (vparamss.isEmpty || primaryConstrs.nonEmpty) tparamsTxt
684
689
else {
685
- var modsText = modText(constr.mods, constr.symbol, " " )
690
+ var modsText = modText(constr.mods, constr.symbol, " " , isType = false )
686
691
if (! modsText.isEmpty) modsText = " " ~ modsText
687
692
if (constr.mods.hasAnnotations && ! constr.mods.hasFlags) modsText = modsText ~~ " this"
688
693
withEnclosingDef(constr) { addVparamssText(tparamsTxt ~~ modsText, vparamss) }
@@ -709,7 +714,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
709
714
}
710
715
711
716
protected def templateText (tree : TypeDef , impl : Template ): Text = {
712
- val decl = modText(tree.mods, tree.symbol, keywordStr(if ((tree).mods is Trait ) " trait" else " class" ))
717
+ val decl = modText(tree.mods, tree.symbol, keywordStr(if ((tree).mods is Trait ) " trait" else " class" ), isType = true )
713
718
decl ~~ typeText(nameIdText(tree)) ~ withEnclosingDef(tree) { toTextTemplate(impl) } ~
714
719
(if (tree.hasType && ctx.settings.verbose.value) i " [decls = ${tree.symbol.info.decls}] " else " " )
715
720
}
@@ -732,12 +737,12 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
732
737
733
738
protected def annotText (tree : untpd.Tree ): Text = " @" ~ constrText(tree) // DD
734
739
735
- protected def modText (mods : untpd.Modifiers , sym : Symbol , kw : String , suppress : FlagSet = EmptyFlags ): Text = { // DD
740
+ protected def modText (mods : untpd.Modifiers , sym : Symbol , kw : String , isType : Boolean ): Text = { // DD
736
741
val suppressKw = if (enclDefIsClass) mods is ParamAndLocal else mods is Param
737
742
var flagMask =
738
743
if (ctx.settings.YdebugFlags .value) AnyFlags
739
- else if (suppressKw) PrintableFlags &~ Private &~ suppress
740
- else PrintableFlags &~ suppress
744
+ else if (suppressKw) PrintableFlags (isType) &~ Private
745
+ else PrintableFlags (isType)
741
746
if (homogenizedView && mods.flags.isTypeFlags) flagMask &~= Implicit // drop implicit from classes
742
747
val flags = (if (sym.exists) sym.flags else (mods.flags)) & flagMask
743
748
val flagsText = if (flags.isEmpty) " " else keywordStr(flags.toString)
@@ -811,7 +816,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
811
816
else {
812
817
var flags = sym.flagsUNSAFE
813
818
if (flags is TypeParam ) flags = flags &~ Protected
814
- Text ((flags & PrintableFlags ).flagStrings map (flag => stringToText(keywordStr(flag))), " " )
819
+ Text ((flags & PrintableFlags (sym.isType) ).flagStrings map (flag => stringToText(keywordStr(flag))), " " )
815
820
}
816
821
817
822
override def toText (denot : Denotation ): Text = denot match {
0 commit comments