aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/printing/PlainPrinter.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2013-09-07 11:49:05 +0200
committerMartin Odersky <odersky@gmail.com>2013-09-07 11:49:05 +0200
commite2fbef4be07c83fde6fb18b9b3b210c4f7d21c1e (patch)
treee6e77458eeb9cb6ecfc90244af6ec7c730e81512 /src/dotty/tools/dotc/printing/PlainPrinter.scala
parent00302d7edcd3a59c74dbd8c360d64ab5c6790de3 (diff)
downloaddotty-e2fbef4be07c83fde6fb18b9b3b210c4f7d21c1e.tar.gz
dotty-e2fbef4be07c83fde6fb18b9b3b210c4f7d21c1e.tar.bz2
dotty-e2fbef4be07c83fde6fb18b9b3b210c4f7d21c1e.zip
Improvements to termref printing.
Diffstat (limited to 'src/dotty/tools/dotc/printing/PlainPrinter.scala')
-rw-r--r--src/dotty/tools/dotc/printing/PlainPrinter.scala41
1 files changed, 26 insertions, 15 deletions
diff --git a/src/dotty/tools/dotc/printing/PlainPrinter.scala b/src/dotty/tools/dotc/printing/PlainPrinter.scala
index f86075d83..74c14f96d 100644
--- a/src/dotty/tools/dotc/printing/PlainPrinter.scala
+++ b/src/dotty/tools/dotc/printing/PlainPrinter.scala
@@ -92,10 +92,12 @@ class PlainPrinter(_ctx: Context) extends Printer {
tp match {
case tp: TypeType =>
toTextRHS(tp)
+ case tp: TermRef if !tp.knownDenotation =>
+ toTextRef(tp) ~ ".type"
+ case tp: TermRef if tp.denot.isOverloaded =>
+ "<overloaded " ~ toTextRef(tp) ~ ">"
case tp: SingletonType =>
- val pre = toTextPrefix(tp)
- if (pre.lastLine.endsWith(".")) pre ~ "type"
- else fullNameString(tp.typeSymbol.skipPackageObject) ~ ".type"
+ toText(tp.underlying) ~ "(" ~ toTextRef(tp) ~ ")"
case tp @ TypeRef(pre, name) =>
toTextPrefix(pre) ~ selectionString(tp)
case tp: RefinedType =>
@@ -138,6 +140,8 @@ class PlainPrinter(_ctx: Context) extends Printer {
toTextLocal(tpe) ~ " " ~ toText(annot)
case tp: TypeVar =>
toTextLocal(tp.underlying) ~ "'" // debug for now, so that we can see where the TypeVars are.
+ case NoPrefix =>
+ "<no-prefix>"
case _ =>
tp.fallbackToText(this)
}
@@ -169,28 +173,35 @@ class PlainPrinter(_ctx: Context) extends Printer {
text.stripPrefix(objectPrefix).stripPrefix(packagePrefix)
protected def selectionString(tp: NamedType) =
- if (tp.symbol.exists) nameString(tp.symbol)
+ if (tp.knownDenotation && tp.symbol.exists) nameString(tp.symbol)
else nameString(tp.name)
/** The string representation of this type used as a prefix */
- protected def toTextPrefix(tp: Type): Text = controlled {
+ protected def toTextRef(tp: SingletonType): Text = controlled {
tp match {
case tp @ TermRef(pre, name) =>
- toTextPrefix(pre) ~ selectionString(tp) ~ "."
+ toTextPrefix(pre) ~ selectionString(tp)
case ThisType(cls) =>
- nameString(cls) + ".this."
+ nameString(cls) + ".this"
+ case SuperType(thistpe: SingletonType, _) =>
+ toTextRef(thistpe).map(_.replaceAll("""\bthis$""", "super"))
case SuperType(thistpe, _) =>
- toTextPrefix(thistpe).map(_.replaceAll("""\bthis\.$""", "super."))
+ "Super(" ~ toTextLocal(thistpe) ~ ")"
case tp @ ConstantType(value) =>
- toTextLocal(tp.underlying) ~ "(" ~ toText(value) ~ ")."
+ toText(value)
case MethodParam(mt, idx) =>
- nameString(mt.paramNames(idx)) + "."
+ nameString(mt.paramNames(idx))
case RefinedThis(_) =>
- "this."
- case NoPrefix =>
- ""
- case _ =>
- trimPrefix(toTextLocal(tp)) ~ "#"
+ "this"
+ }
+ }
+
+ /** The string representation of this type used as a prefix */
+ protected def toTextPrefix(tp: Type): Text = controlled {
+ tp match {
+ case NoPrefix => ""
+ case tp: SingletonType => toTextRef(tp) ~ "."
+ case _ => trimPrefix(toTextLocal(tp)) ~ "#"
}
}