There is already In Scala, how do I get the *name* of an `object` (not an instance of a class)? but I have the following code:
package test
object A {
object B {
object C
}
}
val tmp = A.B.C
I would like to get the string "A.B.C" from value tmp
at runtime, so no package name and no $ since this is the same name used in pattern matching for the type.
I tried the following:
tmp.getClass.getSimpleName // leads to exception "Malformed class name"
tmp.getClass.getName // has package name and $ characters
tmp.getClass.getTypeName // the same
msg.getClass.getName.replace("$", ".") // we still have the package name
I want to get the exact same name as in the AST for pattern matching:
case A.B.C =>
Note that neither the package name nor the object names are fixed.