Frage

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?

War es hilfreich?

Lösung

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

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

Andere Tipps

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top