I'd like to implement the equivalent of an "around...
# ksp
r
I'd like to implement the equivalent of an "around advice" aspect for some auditing functions. Is KSP a reasonable tool to use? If yes, are there any examples doing something similar that I can look at?
w
what is “around advice”?
r
Basically a wrapper around a delegate. The wrapper can take actions before and after the delegate executes, or shortcut execution, etc. Mine will look basically like this: Given an `originalFun`:
Copy code
fun originalWrapperFun() {
  return try {
    originalFun().also {
      doSomething()
    }
  } catch (e: Exception) {
    doSomethingElse()
    throw e
  }
}
j
Are you generating that in a new class? If yes, KSP is fine. If no, KSP will not work.
r
I was hoping to avoid that, as that means calling code has to change. However, I suppose I could update the callers to refer to the generated classes.
Maybe the simplest approach is to simply write a function that does this and call it explicitly.
j
Not intended as an advertisement, but Micronaut supports kotlin and AOP
j
If generating in a new file is fine to you, you can achieve your goal by generating your wrapper in a new file with KSP. Alternatively you case looks like can just be a handy inline function.
r
Yeah I'm going with an inline function for now. Thx!