Skip to content

Commit 3a84717

Browse files
committed
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.
1 parent d3c1c4e commit 3a84717

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1906,6 +1906,14 @@ object Types {
19061906
case _ => show
19071907
}
19081908

1909+
/** Returns the shortened and slightly prettified name of the class of the type. */
1910+
def className: String =
1911+
def go(s: String): String =
1912+
import Predef.augmentString // "import Texts._" imports the conversion to Text, which has a stripPrefix
1913+
val s2 = s.stripPrefix("Cached").stripPrefix("Real").stripSuffix("Impl").stripSuffix("$")
1914+
if s == s2 then s2 else go(s2)
1915+
go(getClass.getSimpleName.nn)
1916+
19091917
/** A simplified version of this type which is equivalent wrt =:= to this type.
19101918
* This applies a typemap to the type which (as all typemaps) follows type
19111919
* variable instances and reduces typerefs over refined types. It also

0 commit comments

Comments
 (0)