From 3a84717aacde2c6410f4bcec836538251234974e Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Wed, 17 Aug 2022 17:08:24 +0100 Subject: [PATCH 1/2] Add a utility "className" on Type Working with LazyRef, TypeVars and so forth, it's often unclear from RefinedPrinter's show what classes types are. So I often want to see the implementing class. But the fully-qualified name is extreme, and even the simple name can be trimmed down a touch. So I'd love to have this implemented once so I can reuse it. --- compiler/src/dotty/tools/dotc/core/Types.scala | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index 9a8e2a051ad4..6f7c898d7586 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -1906,6 +1906,14 @@ object Types { case _ => show } + /** Returns the shortened and slightly prettified name of the class of the type. */ + def className: String = + def go(s: String): String = + import Predef.augmentString // "import Texts._" imports the conversion to Text, which has a stripPrefix + val s2 = s.stripPrefix("Cached").stripPrefix("Real").stripSuffix("Impl").stripSuffix("$") + if s == s2 then s2 else go(s2) + go(getClass.getSimpleName.nn) + /** A simplified version of this type which is equivalent wrt =:= to this type. * This applies a typemap to the type which (as all typemaps) follows type * variable instances and reduces typerefs over refined types. It also From 50a9dd19b948649070d1f93d42e5b40496fba5fa Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Fri, 11 Nov 2022 20:15:18 +0000 Subject: [PATCH 2/2] Drop prettifying & generalise to all --- compiler/src/dotty/tools/dotc/core/Decorators.scala | 3 +++ compiler/src/dotty/tools/dotc/core/Types.scala | 8 -------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/core/Decorators.scala b/compiler/src/dotty/tools/dotc/core/Decorators.scala index d392a4e3079a..54faf9a41177 100644 --- a/compiler/src/dotty/tools/dotc/core/Decorators.scala +++ b/compiler/src/dotty/tools/dotc/core/Decorators.scala @@ -274,6 +274,9 @@ object Decorators { s"[cannot display due to $msg, raw string = $x]" case _ => String.valueOf(x).nn + /** Returns the simple class name of `x`. */ + def className: String = getClass.getSimpleName.nn + extension [T](x: T) def assertingErrorsReported(using Context): T = { assert(ctx.reporter.errorsReported) diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index 6f7c898d7586..9a8e2a051ad4 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -1906,14 +1906,6 @@ object Types { case _ => show } - /** Returns the shortened and slightly prettified name of the class of the type. */ - def className: String = - def go(s: String): String = - import Predef.augmentString // "import Texts._" imports the conversion to Text, which has a stripPrefix - val s2 = s.stripPrefix("Cached").stripPrefix("Real").stripSuffix("Impl").stripSuffix("$") - if s == s2 then s2 else go(s2) - go(getClass.getSimpleName.nn) - /** A simplified version of this type which is equivalent wrt =:= to this type. * This applies a typemap to the type which (as all typemaps) follows type * variable instances and reduces typerefs over refined types. It also