https://kotlinlang.org logo
Title
a

Ademir Queiroga

03/26/2021, 6:30 PM
Hello everyone! Iam receiving an error when calling
KSName.asString()
. What is strange is that I had a working version of my processor but after a few changes in the project structure (moved classes do different packages and so on) this error is now happening. I am basically trying to get the qualified name or the simple name of a Kotlin annotation class. Basically this is the code:
annotation as KSAnnotation
val declaration = annotation.annotationType.resolve().declaration
val qualifiedName = (declaration.qualifiedName ?: declaration.simpleName).asString()

val className = ClassName.bestGuess(qualifiedName)
If I print
declaration
I can already see the string “Error type synthetic declaration”
One thing to consider is that now this annotation class lives alone in it’s own file. Before, it was sharing a file with some other annotation classes in another package
y

yigit

03/26/2021, 6:32 PM
If the declaration is an error, looks like it is but resolved
So maybe missing imports in the processed app?
a

Ademir Queiroga

03/26/2021, 6:38 PM
Indeed. Right on the spot. There was some wrong/missing imports which were not updated with the refactor.
I guess as the KSP errors were happening before the compiler reached the classes without the fixed imports I did not noticed that.
y

yigit

03/26/2021, 6:40 PM
Ksp runs before the compilation of the app
a

Ademir Queiroga

03/26/2021, 6:41 PM
Thanks for the help @yigit! I was trying to do some annotation processing with kapt and was struggling a lot to get annotations of a property from an interface. With KSP it just works! You guys are doing an awesome job!
By the way, is there a way to log/print inside the SymbolProcessor? Tried with
println()
and the logger provided in the
init()
but no luck. I am throwing exceptions as a form of log
y

yigit

03/26/2021, 7:12 PM
I used to use println, was work fine. Did you try running from the command line?
a

Ademir Queiroga

03/26/2021, 7:13 PM
No, I am running it by running the gradle build task
through intellij
y

yigit

03/26/2021, 7:16 PM
Gradlew console should show the printlns, you might need --info.
a

Ademir Queiroga

03/26/2021, 7:18 PM
I’ll try that