Skip to content

Fix #620: show privateWithin in tree printing #6593

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions compiler/src/dotty/tools/dotc/core/Flags.scala
Original file line number Diff line number Diff line change
Expand Up @@ -107,19 +107,22 @@ object Flags {
}

/** The list of non-empty names of flags that are set in this FlagSet */
def flagStrings: Seq[String] = {
def flagStrings(privateWithin: String): Seq[String] = {
val rawStrings = (2 to MaxFlag).flatMap(flagString)
if (this is Local)
val scopeStr =
if (this is Local) "this"
else privateWithin
if (privateWithin != "")
rawStrings.filter(_ != "<local>").map {
case "private" => "private[this]"
case "protected" => "protected[this]"
case "private" => s"private[$scopeStr]"
case "protected" => s"protected[$scopeStr]"
case str => str
}
else rawStrings
}

/** The string representation of this flag set */
override def toString: String = flagStrings.mkString(" ")
override def toString: String = flagStrings("").mkString(" ")
}

def termFlagSet(x: Long) = FlagSet(TERMS | x)
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ class PlainPrinter(_ctx: Context) extends Printer {

/** String representation of symbol's flags */
protected def toTextFlags(sym: Symbol): Text =
Text(sym.flagsUNSAFE.flagStrings map stringToText, " ")
Text(sym.flagsUNSAFE.flagStrings(nameString(sym.privateWithin.name)) map stringToText, " ")

/** String representation of symbol's variance or "" if not applicable */
protected def varianceString(sym: Symbol): String = varianceString(sym.variance)
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
val rawFlags = if (sym.exists) sym.flags else mods.flags
if (rawFlags.is(Param)) flagMask = flagMask &~ Given
val flags = rawFlags & flagMask
val flagsText = if (flags.isEmpty) "" else keywordStr(flags.toString)
val flagsText = if (flags.isEmpty) "" else keywordStr(flags.flagStrings(nameString(sym.privateWithin.name)).mkString(" "))
val annotations =
if (sym.exists) sym.annotations.filterNot(ann => dropAnnotForModText(ann.symbol)).map(_.tree)
else mods.annotations.filterNot(tree => dropAnnotForModText(tree.symbol))
Expand Down Expand Up @@ -887,7 +887,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
else {
var flags = sym.flagsUNSAFE
if (flags is TypeParam) flags = flags &~ Protected
Text((flags & PrintableFlags(sym.isType)).flagStrings map (flag => stringToText(keywordStr(flag))), " ")
Text((flags & PrintableFlags(sym.isType)).flagStrings(nameString(sym.privateWithin.name)) map (flag => stringToText(keywordStr(flag))), " ")
}

override def toText(denot: Denotation): Text = denot match {
Expand Down
2 changes: 1 addition & 1 deletion doc-tool/src/dotty/tools/dottydoc/model/factories.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ object factories {

def flags(t: Tree)(implicit ctx: Context): List[String] =
(t.symbol.flags & (if (t.symbol.isType) TypeSourceModifierFlags else TermSourceModifierFlags))
.flagStrings.toList
.flagStrings(t.symbol.privateWithin.name.show).toList
.filter(_ != "<trait>")
.filter(_ != "interface")
.filter(_ != "case")
Expand Down