I have a Kotlin data class:
package a.b.c
data class Example(
…
)
I am analyzing it with detekt which provides access to the Kotlin PSI.
I'm trying to get the FQDN of my class:
println(klass.nameAsName?.identifier)
where, klass has a type of KtClass from Kotlin PSI. But that code prints just a short name of my class, like Example, whereas I want to get a.b.c.Example.
How do a get a fully qualified domain name of class in Kotlin PSI?
KtClass implemenents the KtNamedDeclaration interface which provides the fqName method.
FqName getFqName();
Which will give you what you want. So:
klass.fqName.asString()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With