Open-api: Annotation based interception of arbitrary method execution

Is there an easy way to intercept arbitrary methods annotated with a specific marker annotation and execute code around them? 

I know that @org.jetbrains.annotations.NotNull is intercepted on runtime to log contract violations, so obviously this is possible. 


Here my specific use case

my.annotation.MyAnnotation // marker annotation
my.annotation.MyAnnotationHandler // wrapper for methods annotated with MyAnnotation

// custom annotated method
void doSomething() {...}

// annotation handler
// interception logic should wrap the execution of doSomething()
Object handle() {
try {
return ... //intercepted method invocation
} catch (Exception e) {
... //do some custom handling
throw e;

1 comment

@NotNull is not intercepted at runtime.  If you look at the decompiler output, the `if ( != null)` check is compiled into the code, so the annotation has a compiler hook that adds the code.


Please sign in to leave a comment.