3

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?

madhead
  • 31,729
  • 16
  • 153
  • 201

1 Answers1

1

KtClass implemenents the KtNamedDeclaration interface which provides the fqName method.

FqName getFqName();

Which will give you what you want. So:

klass.fqName.asString()

sksamuel
  • 16,154
  • 8
  • 60
  • 108