Hi! I'm trying to build my first annotation processor, is there a way to get a
KClass
from a
KSClassDeclaration
?
TheOnlyTails
10/19/2022, 2:27 PM
In context, I'm using KotlinPoet to build my file, but I need to add a type param to the class I'm generating based on the annotated class
TheOnlyTails
10/19/2022, 2:27 PM
Copy code
TypeSpec.objectBuilder(className)
.addSuperinterface(CommandAction::class.parameterizedBy(classDeclaration.getKClass())) // how do i do this?
.build()
e
efemoney
10/19/2022, 3:42 PM
KotlinPoet does not “need” a KClass, its API is
ClassName
or the more general
TypeName
, it just turns out one of the ways to get a class name is via the short cut on KClass.
A ClassName is just a class package + its name, both of those info you can get from KSClassDeclaration