Вопрос

I create a JMenuItem which takes an anonymous inner class AbstractAction:

JMenuItem menuItem = new JMenuItem(new AbstractAction("Item") {
    @Override
    @Abc
    public void actionPerformed(ActionEvent e) {
    // ...
    }
});

I register this JMenuItem with a MenuBar which is registered to my Java Swing frame. I have a pointcut which intercepts calls to @Abc methods

pointcut abcCall() :
    call(@Abc * *(..));

and advice for this pointcut:

Object around(): abcCall() {
    // ...
}

The call to actionPerformed will originate from inside javax.Swing, which I only have the binary for (rt.jar) - is it possible to compile-time weave javax.Swing to accomplish the above?

Это было полезно?

Решение

You do not control the JDK classes, but your own code. So why not intercept method execution instead of call?

pointcut abcCall() : execution(@Abc * *(..));

Другие советы

probably, but youre talking about running the weaver against the whole jdk. the program will no longer be portable since it uses a modified jdk.

a better solution would be to create an abstract class that extends AbstractAction, and its actionPerformed method calls a common method that can be weaved, and is contained in your library.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top