Is it possible to modify AST like Lombok, instead ...
# ksp
z
Is it possible to modify AST like Lombok, instead of generating code?
j
You'll want to write a compiler plugin instead
e
@jw I did try and it's really time consuming. I guess we should wait for K2 and the real compiler plugin infrastructure described in one of the recent talks
j
do you want to modify the frontend part? or the backend? Modifying the frontend is limited to a few things like adding super types or modifying the status If it is the backend, the backend APIs are not changing a lot so you wouldn’t see a lot of differences between the current state and 2.0.0
z
@Javier I can't exactly point out whether what I want to do belongs to frontend or backend. However, I intend to finish my work on Transformation API.
j
do you need to modify anything that user needs to know when he is writing on the IDE? For example, if the user create a class which is annotated and your plugin adds a supertype
Copy code
@AddSuperTypeBar
class Foo

interface Bar

Fun main() {
   // doesn't compile even if you fix it
   // on the backend side, as it is marked as
   // error on the IDE (frontend)
   val bar: Bar = Foo() 
)
Or your user doesn't care about anything on the IDE?
Copy code
fun foo(): Foo = TODO()

Fun main() {
   // it is valid on the IDE (frontend)
   // but it would crash if you don't replace
   // the body of `foo()` with valid code, so
   // in backend you can `fun foo(): Foo = Foo()`
   val foo: Foo = foo()
)
z
@Javier It's frontend.
j
and what do you need to modify? because it is very restrictive
z
Someone aksed same question, and sound like ksp don't have capability to do this.
j
and probably you will want to move this question to #compiler
no, ksp only codegen code
but, depending on what you want to do, maybe you can't even with a compiler plugin, so I would ask in #compiler
z
Almost the same as the example you provided, does it have a ready-made solution?
Yes, #compiler doesn't look like what I want.
Predictably, I also need to provide an Idea plugin like lombok.
j
Sorry but I don't know what lombok does, without more detailed info of what you want to do, I can't help more