diff options
author | Martin Odersky <odersky@gmail.com> | 2013-09-07 11:49:05 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2013-09-07 11:49:05 +0200 |
commit | e2fbef4be07c83fde6fb18b9b3b210c4f7d21c1e (patch) | |
tree | e6e77458eeb9cb6ecfc90244af6ec7c730e81512 /src/dotty/tools/dotc/printing | |
parent | 00302d7edcd3a59c74dbd8c360d64ab5c6790de3 (diff) | |
download | dotty-e2fbef4be07c83fde6fb18b9b3b210c4f7d21c1e.tar.gz dotty-e2fbef4be07c83fde6fb18b9b3b210c4f7d21c1e.tar.bz2 dotty-e2fbef4be07c83fde6fb18b9b3b210c4f7d21c1e.zip |
Improvements to termref printing.
Diffstat (limited to 'src/dotty/tools/dotc/printing')
-rw-r--r-- | src/dotty/tools/dotc/printing/PlainPrinter.scala | 41 | ||||
-rw-r--r-- | src/dotty/tools/dotc/printing/RefinedPrinter.scala | 12 |
2 files changed, 36 insertions, 17 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)) ~ "#" } } diff --git a/src/dotty/tools/dotc/printing/RefinedPrinter.scala b/src/dotty/tools/dotc/printing/RefinedPrinter.scala index 3ee86f665..bad2c071e 100644 --- a/src/dotty/tools/dotc/printing/RefinedPrinter.scala +++ b/src/dotty/tools/dotc/printing/RefinedPrinter.scala @@ -39,12 +39,20 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { name.decode.toString } + override def toTextRef(tp: SingletonType): Text = controlled { + tp match { + case ThisType(cls) => + if (cls.isAnonymousClass) return "this" + if (cls is ModuleClass) return fullNameString(cls) + case _ => + } + super.toTextRef(tp) + } + override def toTextPrefix(tp: Type): Text = controlled { tp match { case ThisType(cls) => - if (cls.isAnonymousClass) return "this." if (isOmittablePrefix(cls)) return "" - if (cls is ModuleClass) return fullNameString(cls) + "." case tp @ TermRef(pre, name) => val sym = tp.symbol if (sym.isPackageObject) return toTextPrefix(pre) |