mercredi 3 octobre 2018

Wrap a method in commands using Annotation Processing

I have a bunch of tasks that need to be performed before and after a method call.

My approach is to use annotation processing, and a custom annotation to do this.

@BeforeSomething(task = 'something')
@AfterSomething(task = 'something else')
fun something(blah: Something) {
  Log.d("Something", "Something $blah")
}

So that the end output from just running this method could be like:

Before task, options 'something'
Something blahblahblah
After task, options 'somethign else'

Whats the best way to do this? I've looked into AspectJ but thats not working with Kotlin and/or Java. I've also looked into Lombok, but I can't use that library.





Aucun commentaire:

Enregistrer un commentaire