From 9d90361eeb76f3b090a96033e20ed1a272c3493c Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 17 Jul 2014 15:44:10 +0200 Subject: Add showDcl method for SingleDenotations --- src/dotty/tools/dotc/core/Denotations.scala | 8 ++++++-- src/dotty/tools/dotc/printing/PlainPrinter.scala | 10 +++++++--- src/dotty/tools/dotc/printing/Printer.scala | 5 ++++- 3 files changed, 17 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/dotty/tools/dotc/core/Denotations.scala b/src/dotty/tools/dotc/core/Denotations.scala index 43fff62ec..022230ff8 100644 --- a/src/dotty/tools/dotc/core/Denotations.scala +++ b/src/dotty/tools/dotc/core/Denotations.scala @@ -619,7 +619,7 @@ object Denotations { throw new StaleSymbol(msg) } - /** The period (interval of phases) for which there exists + /** The period (interval of phases) for which there exists * a valid denotation in this flock. */ def coveredInterval(implicit ctx: Context): Period = { @@ -641,11 +641,15 @@ object Denotations { */ def syncWithParents(implicit ctx: Context): SingleDenotation = this + /** Show declaration string; useful for showing declarations + * as seen from subclasses. + */ + def showDcl(implicit ctx: Context): String = ctx.dclText(this).show + override def toString = if (symbol == NoSymbol) symbol.toString else s"" - def definedPeriodsString: String = { var sb = new StringBuilder() var cur = this diff --git a/src/dotty/tools/dotc/printing/PlainPrinter.scala b/src/dotty/tools/dotc/printing/PlainPrinter.scala index ec4a4db88..94b325996 100644 --- a/src/dotty/tools/dotc/printing/PlainPrinter.scala +++ b/src/dotty/tools/dotc/printing/PlainPrinter.scala @@ -2,7 +2,7 @@ package dotty.tools.dotc package printing import core._ -import Texts._, Types._, Flags._, Names._, Symbols._, NameOps._, Constants._ +import Texts._, Types._, Flags._, Names._, Symbols._, NameOps._, Constants._, Denotations._ import Contexts.Context, Scopes.Scope, Denotations.Denotation, Annotations.Annotation import StdNames.nme import ast.Trees._, ast.untpd @@ -321,9 +321,13 @@ class PlainPrinter(_ctx: Context) extends Printer { def annotsText(sym: Symbol): Text = Text(sym.annotations.map(toText)) - def dclText(sym: Symbol): Text = + def dclText(sym: Symbol): Text = dclTextWithInfo(sym, sym.unforcedInfo) + + def dclText(d: SingleDenotation): Text = dclTextWithInfo(d.symbol, Some(d.info)) + + private def dclTextWithInfo(sym: Symbol, info: Option[Type]): Text = (toTextFlags(sym) ~~ keyString(sym) ~~ - (varianceString(sym) ~ nameString(sym)) ~ toTextRHS(sym.unforcedInfo)).close + (varianceString(sym) ~ nameString(sym)) ~ toTextRHS(info)).close def toText(sym: Symbol): Text = (kindString(sym) ~~ { diff --git a/src/dotty/tools/dotc/printing/Printer.scala b/src/dotty/tools/dotc/printing/Printer.scala index 65162a10f..360874522 100644 --- a/src/dotty/tools/dotc/printing/Printer.scala +++ b/src/dotty/tools/dotc/printing/Printer.scala @@ -4,7 +4,7 @@ package printing import core._ import Texts._, ast.Trees._ import Types.Type, Symbols.Symbol, Contexts.Context, Scopes.Scope, Constants.Constant, - Names.Name, Denotations.Denotation, Annotations.Annotation + Names.Name, Denotations._, Annotations.Annotation /** The base class of all printers */ @@ -59,6 +59,9 @@ abstract class Printer { /** Textual representation of symbol's declaration */ def dclText(sym: Symbol): Text + /** Textual representation of single denotation's declaration */ + def dclText(sd: SingleDenotation): Text + /** If symbol's owner is a printable class C, the text "in C", otherwise "" */ def locationText(sym: Symbol): Text -- cgit v1.2.3