diff options
author | Martin Odersky <odersky@gmail.com> | 2014-05-07 18:26:37 +0200 |
---|---|---|
committer | Samuel Gruetter <samuel.gruetter@epfl.ch> | 2014-05-20 13:38:48 +0200 |
commit | f7910005038c188e573e8d1a42ff3e31c69c90c1 (patch) | |
tree | 936ade866ca937ae2fda21cbc6187f0dfc34dca9 /src/dotty | |
parent | c2d5246bdb33d60d3eaff62a539d01368124d859 (diff) | |
download | dotty-f7910005038c188e573e8d1a42ff3e31c69c90c1.tar.gz dotty-f7910005038c188e573e8d1a42ff3e31c69c90c1.tar.bz2 dotty-f7910005038c188e573e8d1a42ff3e31c69c90c1.zip |
Better printing of anonymous classes.
Used to be just $anon, now is `Ps { ... }`, where `Ps` are
the instantiated parents of the anonymous class.
Diffstat (limited to 'src/dotty')
-rw-r--r-- | src/dotty/tools/dotc/core/Types.scala | 11 | ||||
-rw-r--r-- | src/dotty/tools/dotc/printing/PlainPrinter.scala | 7 | ||||
-rw-r--r-- | src/dotty/tools/dotc/printing/RefinedPrinter.scala | 11 |
3 files changed, 18 insertions, 11 deletions
diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala index 36b546230..89facfee5 100644 --- a/src/dotty/tools/dotc/core/Types.scala +++ b/src/dotty/tools/dotc/core/Types.scala @@ -2002,12 +2002,23 @@ object Types { // cached because baseType needs parents private var parentsCache: List[TypeRef] = null + /** The parent type refs as seen from the given prefix */ override def parents(implicit ctx: Context): List[TypeRef] = { if (parentsCache == null) parentsCache = cls.classParents.mapConserve(rebase(_).asInstanceOf[TypeRef]) parentsCache } + /** The parent types with all type arguments */ + def instantiatedParents(implicit ctx: Context): List[Type] = + parents mapConserve { pref => + ((pref: Type) /: pref.classSymbol.typeParams) { (parent, tparam) => + val targSym = decls.lookup(tparam.name) + if (targSym.exists) RefinedType(parent, targSym.name, targSym.info) + else parent + } + } + def derivedClassInfo(prefix: Type)(implicit ctx: Context) = if (prefix eq this.prefix) this else ClassInfo(prefix, cls, classParents, decls, selfInfo) diff --git a/src/dotty/tools/dotc/printing/PlainPrinter.scala b/src/dotty/tools/dotc/printing/PlainPrinter.scala index 308470885..3a322648a 100644 --- a/src/dotty/tools/dotc/printing/PlainPrinter.scala +++ b/src/dotty/tools/dotc/printing/PlainPrinter.scala @@ -251,22 +251,21 @@ class PlainPrinter(_ctx: Context) extends Printer { case sym: Symbol if !sym.isCompleted => "this: ? =>" case _ => "this: " ~ atPrec(InfixPrec) { toText(tp.selfType) } ~ " =>" } - val parentsText = Text(cparents.map(p => - toTextLocal(reconstituteParent(cls, p))), " with ") val trueDecls = otherDecls.filterNot(treatAsTypeArg) val declsText = if (trueDecls.isEmpty || !ctx.settings.debug.value) Text() else dclsText(trueDecls) - tparamsText ~ " extends " ~ parentsText ~ "{" ~ selfText ~ declsText ~ + tparamsText ~ " extends " ~ toTextParents(tp.parents) ~ "{" ~ selfText ~ declsText ~ "} at " ~ preText case _ => ": " ~ toTextGlobal(tp) } } + protected def toTextParents(parents: List[Type]): Text = Text(parents.map(toTextLocal), " with ") + protected def treatAsTypeParam(sym: Symbol): Boolean = false protected def treatAsTypeArg(sym: Symbol): Boolean = false - protected def reconstituteParent(cls: ClassSymbol, parent: Type): Type = parent /** String representation of symbol's kind. */ def kindString(sym: Symbol): String = { diff --git a/src/dotty/tools/dotc/printing/RefinedPrinter.scala b/src/dotty/tools/dotc/printing/RefinedPrinter.scala index c20598bb3..d0a681f90 100644 --- a/src/dotty/tools/dotc/printing/RefinedPrinter.scala +++ b/src/dotty/tools/dotc/printing/RefinedPrinter.scala @@ -115,8 +115,12 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { case _ => nameString(tp.symbol) } } + else if (tp.symbol.isAnonymousClass) + return toText(tp.info) case ExprType(result) => return "=> " ~ toText(result) + case tp: ClassInfo => + return toTextParents(tp.instantiatedParents) ~ "{...}" case tp: SelectionProto => return toText(RefinedType(WildcardType, tp.name, tp.memberProto)) case tp: ViewProto => @@ -437,13 +441,6 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { sym.isType && (sym is ProtectedLocal) && (sym.allOverriddenSymbols exists (_ is TypeParam)) - override protected def reconstituteParent(cls: ClassSymbol, parent: Type): Type = - (parent /: parent.classSymbol.typeParams) { (parent, tparam) => - val targSym = cls.decls.lookup(tparam.name) - if (targSym.exists) RefinedType(parent, targSym.name, targSym.info) - else parent - } - override def toText(sym: Symbol): Text = { if (sym.name == nme.IMPORT) { def importString(tree: untpd.Tree) = s"import ${tree.show}" |