https://kotlinlang.org logo
#compiler
Title
# compiler
s

server

01/10/2022, 6:44 AM
can I somehow convert IrClass to PsiClass?
d

dmitriy.novozhilov

01/10/2022, 6:51 AM
You can access PSI of class via source element (
val psi = irClass.sourceElement?.getPsi()
), but this will suite only for source based classes (there won't be any PSI for library classes or synthetic classes, generated by plugins) Why do you want this?
s

server

01/10/2022, 9:12 AM
@dmitriy.novozhilov I'm using IrGenerationExtension and I have only access to IrClass. What extension should I use to do something like annotation processing? I won't generate any bytecode
one bad thing about this extension is that I don't have access to code comments and it might be useful in my usecase
d

dmitriy.novozhilov

01/10/2022, 9:12 AM
Take a look at google KSP https://github.com/google/ksp
Or you can use
AnalysisHandlerExtension
s

server

01/10/2022, 9:14 AM
how is KSP different to compiler plugin? the only difference is that I cannot create bytecode?
d

dmitriy.novozhilov

01/10/2022, 9:15 AM
KSP is a tool for creating annotation processor like compiler plugins which does not expose compiler internals Check README in KSP repo for more details
s

server

01/10/2022, 9:16 AM
thanks. I think I will stick with compiler plugin for now. I don't need to generate bytecode now, but maybe later. so it would be good to learn that.
thanks for your help
s

shikasd

01/10/2022, 2:34 PM
IR extension is mostly used to generate code, so if you want to add custom checks/logic, you might want to look into DeclarationChecker, which gives you a PSI element for additional checks.
s

server

01/10/2022, 3:14 PM
@shikasd thx
5 Views