Domanda

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?

È stato utile?

Soluzione

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

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

Altri suggerimenti

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top