@@ -411,7 +411,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
411
411
case tree @ TypeDef (name, rhs) =>
412
412
def typeDefText (tparamsText : => Text , rhsText : => Text ) =
413
413
dclTextOr(tree) {
414
- modText(tree.mods, keywordStr(" type" )) ~~ (varianceText(tree.mods) ~ typeText(nameIdText(tree))) ~
414
+ modText(tree.mods, tree.symbol, keywordStr(" type" )) ~~ (varianceText(tree.mods) ~ typeText(nameIdText(tree))) ~
415
415
withEnclosingDef(tree) { tparamsText ~ rhsText }
416
416
}
417
417
def recur (rhs : Tree , tparamsTxt : => Text ): Text = rhs match {
@@ -449,7 +449,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
449
449
toText(t)
450
450
case tree @ ModuleDef (name, impl) =>
451
451
withEnclosingDef(tree) {
452
- modText(tree.mods, keywordStr(" object" )) ~~ nameIdText(tree) ~ toTextTemplate(impl)
452
+ modText(tree.mods, NoSymbol , keywordStr(" object" )) ~~ nameIdText(tree) ~ toTextTemplate(impl)
453
453
}
454
454
case SymbolLit (str) =>
455
455
" '" + str
@@ -506,7 +506,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
506
506
t ~ cxBoundToText(cxb)
507
507
}
508
508
case PatDef (mods, pats, tpt, rhs) =>
509
- modText(mods, keywordStr(" val" )) ~~ toText(pats, " , " ) ~ optAscription(tpt) ~
509
+ modText(mods, NoSymbol , keywordStr(" val" )) ~~ toText(pats, " , " ) ~ optAscription(tpt) ~
510
510
optText(rhs)(" = " ~ _)
511
511
case ParsedTry (expr, handler, finalizer) =>
512
512
changePrec(GlobalPrec ) {
@@ -618,7 +618,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
618
618
protected def valDefToText [T >: Untyped ](tree : ValDef [T ]): Text = {
619
619
import untpd .{modsDeco => _ , _ }
620
620
dclTextOr(tree) {
621
- modText(tree.mods, keywordStr(if (tree.mods is Mutable ) " var" else " val" )) ~~
621
+ modText(tree.mods, tree.symbol, keywordStr(if (tree.mods is Mutable ) " var" else " val" )) ~~
622
622
valDefText(nameIdText(tree)) ~ optAscription(tree.tpt) ~
623
623
withEnclosingDef(tree) { optText(tree.rhs)(" = " ~ _) }
624
624
}
@@ -627,7 +627,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
627
627
protected def defDefToText [T >: Untyped ](tree : DefDef [T ]): Text = {
628
628
import untpd .{modsDeco => _ , _ }
629
629
dclTextOr(tree) {
630
- val prefix = modText(tree.mods, keywordStr(" def" )) ~~ valDefText(nameIdText(tree))
630
+ val prefix = modText(tree.mods, tree.symbol, keywordStr(" def" )) ~~ valDefText(nameIdText(tree))
631
631
withEnclosingDef(tree) {
632
632
addVparamssText(prefix ~ tparamsText(tree.tparams), tree.vparamss) ~ optAscription(tree.tpt) ~
633
633
optText(tree.rhs)(" = " ~ _)
@@ -642,7 +642,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
642
642
val prefix : Text =
643
643
if (vparamss.isEmpty || primaryConstrs.nonEmpty) tparamsTxt
644
644
else {
645
- var modsText = modText(constr.mods, " " )
645
+ var modsText = modText(constr.mods, constr.symbol, " " )
646
646
if (! modsText.isEmpty) modsText = " " ~ modsText
647
647
if (constr.mods.hasAnnotations && ! constr.mods.hasFlags) modsText = modsText ~~ " this"
648
648
withEnclosingDef(constr) { addVparamssText(tparamsTxt ~~ modsText, vparamss) }
@@ -670,7 +670,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
670
670
}
671
671
672
672
protected def templateText (tree : TypeDef , impl : Template ): Text = {
673
- val decl = modText(tree.mods, keywordStr(if ((tree).mods is Trait ) " trait" else " class" ))
673
+ val decl = modText(tree.mods, tree.symbol, keywordStr(if ((tree).mods is Trait ) " trait" else " class" ))
674
674
decl ~~ typeText(nameIdText(tree)) ~ withEnclosingDef(tree) { toTextTemplate(impl) } ~
675
675
(if (tree.hasType && ctx.settings.verbose.value) i " [decls = ${tree.symbol.info.decls}] " else " " )
676
676
}
@@ -693,16 +693,18 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
693
693
694
694
protected def annotText (tree : untpd.Tree ): Text = " @" ~ constrText(tree) // DD
695
695
696
- protected def modText (mods : untpd.Modifiers , kw : String ): Text = { // DD
696
+ protected def modText (mods : untpd.Modifiers , sym : Symbol , kw : String , suppress : FlagSet = EmptyFlags ): Text = { // DD
697
697
val suppressKw = if (enclDefIsClass) mods is ParamAndLocal else mods is Param
698
698
var flagMask =
699
699
if (ctx.settings.YdebugFlags .value) AnyFlags
700
- else if (suppressKw) PrintableFlags &~ Private
701
- else PrintableFlags
700
+ else if (suppressKw) PrintableFlags &~ Private &~ suppress
701
+ else PrintableFlags &~ suppress
702
702
if (homogenizedView && mods.flags.isTypeFlags) flagMask &~= Implicit // drop implicit from classes
703
- val flags = mods.flags & flagMask
704
- val flagsText = if (flags.isEmpty) " " else keywordStr((mods.flags & flagMask).toString)
705
- val annotations = filterModTextAnnots(mods.annotations)
703
+ val flags = (if (sym.exists) sym.flags else (mods.flags)) & flagMask
704
+ val flagsText = if (flags.isEmpty) " " else keywordStr(flags.toString)
705
+ val annotations = filterModTextAnnots(
706
+ if (sym.exists) sym.annotations.filterNot(_.isInstanceOf [Annotations .BodyAnnotation ]).map(_.tree)
707
+ else mods.annotations)
706
708
Text (annotations.map(annotText), " " ) ~~ flagsText ~~ (Str (kw) provided ! suppressKw)
707
709
}
708
710
0 commit comments