Is it possible with ByteBuddy to intercept a method that is declared by an interface with an annotation?

Viewed 92

I need to instrument all methods, which implement an interface that itself is annotated. Consider such an example:

@WebService
interface HelloWorld {
  void hello();
}
class HelloWorldImpl implements HelloWorld {
  void hello() {...}
  void goodBye() {...}
}

Here I need to have an advice around hello, because it is declared by an interface with @WebService annotation. Is it possible to build such a ButeBuddy matcher?

1 Answers

Yes, in the ElementMatchers class, you find a long row of predefined matchers, also such that deal with annotations. Do however know that annotations on interfaces are not inherited. You'd need to wrap the matcher in a ElementMatchers.hasSuperType to check the entire hierarchy.

Related