I want to have a Guice interceptor that intercepts calls either to a class that is annotated, or a method that is annotated. I'd like to be able to combine both, ie. override the class annotation with a method annotation with different properties.
I have this working like this:
// Intercept all METHODS annotated with @MyAnnotation
bindInterceptor(
Matchers.any(),
Matchers.annotatedWith(company.MyAnnotation),
new TracingInterceptor());
// Intercept all methods in CLASSES annotated with @MyAnnotation
bindInterceptor(
Matchers.annotatedWith(company.MyAnnotation),
Matchers.any(),
new TracingInterceptor());
However when I annotate a class like this:
@MyAnnotation
class MyClass {
@MyAnnotation
public void myMethod() {}
}
The interceptor gets called twice, which is bad!
Is there any way to avoid triggering the interceptor twice, but having the same behaviour?