Hey all, trying to do something and I'm missing th...
# ksp
r
Hey all, trying to do something and I'm missing the idiomatic way of doing it. I'm using KSP to read an annotation on a class, this annotation takes an enum variant as a parameter. The variants each have their own function called
resolve
. I would like to get that function and insert it as text/code in the generated file. So far the only way I've been able to do this is to read the enum file and regex out the function which seems totally wrong 😆
g
I believe KSP doesn't allow to get the runtime code, you'll only have the
resolve
signature (as far as I know).
r
That's what it looks like as I'm digging into the
KSFunctionDeclaration
. Is this a use case for PSI?
m
The symbol processor only has access to the symbols, not the code in the body. I think you would either need to put the code into a string argument in an annotation e.g. @ResolveFn(""" Code here """) Alternatively you would need to use something that actually reads the source code e.g. https://github.com/kotlinx/ast If its a known set of enums, then you can add them as a dependency on the symbol processor itself, recognize them, and then generate code to match e.g. fun MyEnumName_ResolveFunction() { ... }
thank you color 1