Hi! I want to dynamically add (or replace) annotat...
# arrow-meta
c
Hi! I want to dynamically add (or replace) annotations to Methods. For example if I annotate a Method in my source like this:
Copy code
@OneAnnotation(value = "someDetail")
fun methodA() { ... }
I want my plugin to add another annotation like this
Copy code
@AnotherAnnotation(value = "someDetail") // value taken from "original" annotation
@OneAnnotation(value = "someDetail")
fun methodA() { ... }
Do you think arrow-meta is a good fit for this task? Any hints on how to do it?
r
hi Cornelius, it depends on what you do later with
AnotherAnnotation
, you may be able to use just backend IR
what happens after you add it?
c
I just want it to be there at runtime. I want a more elegant way to write annotations for spring security. Spring security seems not to be too flexible regarding custom annotations but wants us to write SpEL in @PreAuthorize annotations. So thought I could create my own annotations and generate the @PreAuthorize including the (imo ugly) SpEL expressions at compile time.
r
if you use meta you can implement this with
irDeclaration { decl.annotations... }
or directly without meta using the IRGenerationExtension in the compiler apis.
the ir declarations are mutable and whatever you change will make it to the codegen phase which will eventually add it to the compiled jar
c
Thanks, I will give it a try. Enjoy the weekend :)
👍 1