-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Remove duplication from UserFacingPrinter
#3032
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
32d3c5d
94bdcf5
e0139bf
f7e9af9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package dotty.tools.dotc | ||
package printing | ||
|
||
import core._ | ||
import Constants.Constant, Contexts.Context, Denotations._, Flags._, Names._ | ||
import NameOps._, StdNames._, Decorators._, Scopes.Scope, Types._, Texts._ | ||
import SymDenotations.NoDenotation, Symbols.{ Symbol, ClassSymbol, defn } | ||
|
||
class UserFacingPrinter(_ctx: Context) extends RefinedPrinter(_ctx) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes and that's what we do in RefinedPrinter when extending plain printer :) |
||
|
||
private[this] def getPkgCls(path: String) = | ||
_ctx.requiredPackage(path).moduleClass.asClass | ||
|
||
private lazy val collectionPkg = getPkgCls("scala.collection") | ||
private lazy val immutablePkg = getPkgCls("scala.collection.immutable") | ||
private lazy val scalaPkg = defn.ScalaPackageClass | ||
private lazy val javaLangPkg = defn.JavaLangPackageVal.moduleClass.asClass | ||
|
||
def standardPkg(pkgSym: Symbol) = pkgSym match { | ||
case `scalaPkg` | `collectionPkg` | `immutablePkg` | `javaLangPkg` => true | ||
case _ => false | ||
} | ||
|
||
def wrappedName(pkgSym: Symbol) = | ||
pkgSym.name.toTermName == nme.EMPTY_PACKAGE || | ||
pkgSym.name.isReplWrapperName | ||
|
||
def wellKnownPkg(pkgSym: Symbol) = standardPkg(pkgSym) || wrappedName(pkgSym) | ||
|
||
override protected def keyString(sym: Symbol): String = | ||
if (sym.flagsUNSAFE is Package) "" else super.keyString(sym) | ||
|
||
override def nameString(name: Name): String = | ||
if (name.isReplAssignName) name.decode.toString.takeWhile(_ != '$') | ||
else name.decode.toString | ||
|
||
override def toText(sym: Symbol): Text = | ||
if (sym.name.isReplAssignName) nameString(sym.name) | ||
else keyString(sym) ~~ nameString(sym.name.stripModuleClassSuffix) | ||
|
||
override def dclText(sym: Symbol): Text = toText(sym) ~ { | ||
if (sym.is(Method)) toText(sym.info) | ||
else if (sym.isType && sym.info.isInstanceOf[TypeAlias]) toText(sym.info) | ||
else if (sym.isType || sym.isClass) "" | ||
else ":" ~~ toText(sym.info) | ||
} | ||
|
||
override def toText(const: Constant): Text = Str(const.value.toString) | ||
|
||
override def toText(tp: Type): Text = tp match { | ||
case ExprType(result) => ":" ~~ toText(result) | ||
case tp: ConstantType => toText(tp.value) | ||
case tp: TypeRef => tp.info match { | ||
case TypeAlias(alias) => toText(alias) | ||
case _ => toText(tp.info) | ||
} | ||
case tp: ClassInfo => { | ||
if (wellKnownPkg(tp.cls.owner)) nameString(tp.cls.name) | ||
else { | ||
def printPkg(sym: ClassSymbol): Text = | ||
if (sym.owner == defn.RootClass || wrappedName(sym.owner)) | ||
nameString(sym.name.stripModuleClassSuffix) | ||
else | ||
printPkg(sym.owner.asClass) ~ "." ~ toText(sym) | ||
|
||
printPkg(tp.cls.owner.asClass) ~ "." ~ nameString(tp.cls.name) | ||
} | ||
} | ||
case tp => super.toText(tp) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
scala> val toInt: Any => Int = new { def apply(a: Any) = 1; override def toString() = "<func1>" } | ||
val toInt: Any => Int = <func1> |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it intentional to keep the
dotty-repl
project in Build.scala?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like an oversight when rebasing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Remove it in #3044)