Skip to content

Commit 9d90361

Browse files
committed
Add showDcl method for SingleDenotations
1 parent 2cb9050 commit 9d90361

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

src/dotty/tools/dotc/core/Denotations.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ object Denotations {
619619
throw new StaleSymbol(msg)
620620
}
621621

622-
/** The period (interval of phases) for which there exists
622+
/** The period (interval of phases) for which there exists
623623
* a valid denotation in this flock.
624624
*/
625625
def coveredInterval(implicit ctx: Context): Period = {
@@ -641,11 +641,15 @@ object Denotations {
641641
*/
642642
def syncWithParents(implicit ctx: Context): SingleDenotation = this
643643

644+
/** Show declaration string; useful for showing declarations
645+
* as seen from subclasses.
646+
*/
647+
def showDcl(implicit ctx: Context): String = ctx.dclText(this).show
648+
644649
override def toString =
645650
if (symbol == NoSymbol) symbol.toString
646651
else s"<SingleDenotation of type $infoOrCompleter>"
647652

648-
649653
def definedPeriodsString: String = {
650654
var sb = new StringBuilder()
651655
var cur = this

src/dotty/tools/dotc/printing/PlainPrinter.scala

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package dotty.tools.dotc
22
package printing
33

44
import core._
5-
import Texts._, Types._, Flags._, Names._, Symbols._, NameOps._, Constants._
5+
import Texts._, Types._, Flags._, Names._, Symbols._, NameOps._, Constants._, Denotations._
66
import Contexts.Context, Scopes.Scope, Denotations.Denotation, Annotations.Annotation
77
import StdNames.nme
88
import ast.Trees._, ast.untpd
@@ -321,9 +321,13 @@ class PlainPrinter(_ctx: Context) extends Printer {
321321

322322
def annotsText(sym: Symbol): Text = Text(sym.annotations.map(toText))
323323

324-
def dclText(sym: Symbol): Text =
324+
def dclText(sym: Symbol): Text = dclTextWithInfo(sym, sym.unforcedInfo)
325+
326+
def dclText(d: SingleDenotation): Text = dclTextWithInfo(d.symbol, Some(d.info))
327+
328+
private def dclTextWithInfo(sym: Symbol, info: Option[Type]): Text =
325329
(toTextFlags(sym) ~~ keyString(sym) ~~
326-
(varianceString(sym) ~ nameString(sym)) ~ toTextRHS(sym.unforcedInfo)).close
330+
(varianceString(sym) ~ nameString(sym)) ~ toTextRHS(info)).close
327331

328332
def toText(sym: Symbol): Text =
329333
(kindString(sym) ~~ {

src/dotty/tools/dotc/printing/Printer.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ package printing
44
import core._
55
import Texts._, ast.Trees._
66
import Types.Type, Symbols.Symbol, Contexts.Context, Scopes.Scope, Constants.Constant,
7-
Names.Name, Denotations.Denotation, Annotations.Annotation
7+
Names.Name, Denotations._, Annotations.Annotation
88

99
/** The base class of all printers
1010
*/
@@ -59,6 +59,9 @@ abstract class Printer {
5959
/** Textual representation of symbol's declaration */
6060
def dclText(sym: Symbol): Text
6161

62+
/** Textual representation of single denotation's declaration */
63+
def dclText(sd: SingleDenotation): Text
64+
6265
/** If symbol's owner is a printable class C, the text "in C", otherwise "" */
6366
def locationText(sym: Symbol): Text
6467

0 commit comments

Comments
 (0)