Skip to content

Commit 58f1ba4

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 2844c2b commit 58f1ba4

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
@@ -1913,6 +1913,14 @@ object Types {
19131913
case _ => show
19141914
}
19151915

1916+
/** Returns the shortened and slightly prettified name of the class of the type. */
1917+
def className: String =
1918+
def go(s: String): String =
1919+
import Predef.augmentString // "import Texts._" imports the conversion to Text, which has a stripPrefix
1920+
val s2 = s.stripPrefix("Cached").stripPrefix("Real").stripSuffix("Impl").stripSuffix("$")
1921+
if s == s2 then s2 else go(s2)
1922+
go(getClass.getSimpleName.nn)
1923+
19161924
/** A simplified version of this type which is equivalent wrt =:= to this type.
19171925
* This applies a typemap to the type which (as all typemaps) follows type
19181926
* variable instances and reduces typerefs over refined types. It also

0 commit comments

Comments
 (0)