v79
11/26/2023, 7:43 PM@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.SOURCE)
annotation class APISchema
~~~
@Serializable
@APISchema
class DummyClass(val name: String, val age: Int)
Then my processor fails to find DummyClass
, and it says that there are no annotations:
override fun process(resolver: Resolver): List<KSAnnotated> {
val schemaClasses = resolver.getSymbolsWithAnnotation(APISchema::class.qualifiedName!!, false)
.filterIsInstance<APISchema>()
if (!schemaClasses.iterator().hasNext()) {
logger.warn("No classes found with @APISchema annotation")
}
resolver.getAllFiles().forEach { file ->
logger.warn("Found file: ${file.fileName}")
if(file.fileName == "DummyClass.kt") {
logger.warn("Found DummyClass.kt")
logger.warn(file.toString())
file.annotations.forEach { annotation ->
logger.warn("Found annotation: ${annotation.shortName}")
}
}
}
}
The logs show:
w: [ksp] No classes found with @APISchema annotation
...
w: [ksp] Found file: DummyClass.kt
w: [ksp] Found DummyClass.kt
w: [ksp] File: DummyClass.kt <-- I'd expect the file.annotations.forEach {} to list "@APISchema" and "Serializable" here!
w: [ksp] Found file: Authorizer.kt
...
David Rawson
11/27/2023, 12:56 AMresolver.getSymbolsWithAnnotation(APISchema::class.qualifiedName!!, false)
will never be of type ApiSchema
.
So the filterIsInstance
call in the code sample will always ensure the sequence is empty. I think what you are looking for is something like:
filterIsInstance<KSClassDeclaration>()
This KSP-eye view of things takes a while to get used to and it's worth setting breakpoints and using the debugger to see what's going onv79
11/27/2023, 6:55 AMgetSymbolsWithAnnotation
incorrectly. And it seems my resolver.getAllFiles().forEach {}
was not going to be useful either.
Now I just need to write the information I get from the KClassDeclaration into a plain text file, ideally into /src/main/resources...v79
11/27/2023, 10:01 PM