Can't get javax.swing.* and java.awt.* to weave [message #689438] |
Mon, 27 June 2011 16:34 |
Steve Cohen Messages: 46 Registered: July 2009 |
Member |
|
|
I am a newbie to AOP, AspectJ, and AJDT.
I am trying to set up a debug time usage of AOP to help our team debug a complicated and somewhat odd Swing application that does a lot of strange keyboard remapping, since it needs to emulate and existing application.
To determine why some things don't work, I need to know which class is handling a given keystroke.
My pattern is to wrap the existing Swing project in an AspectJ project (putting the Swing project on the AspectJ project's Build Path), and defining an aspect that pointcuts at the appropriate places. The aspect is as follows:
package com.whatever.gui.aop;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import javax.swing.Action;
import javax.swing.JComponent;
import javax.swing.KeyStroke;
import com.whatever.gui.Login;
import com.whatever.gui.kbd.KeyRemapper;
aspect CapLogger {
pointcut logActionSearch(JComponent jc, KeyStroke ks)
: target (jc)
&& args(ks)
&& execution( protected * JComponent+.processKeyBinding(KeyStroke, KeyEvent,
int, boolean));
before(JComponent jc, KeyStroke ks) : logActionSearch(jc, ks) {
Class klass = jc.getClass();
System.out.println(String.format("Searching for handler for %s in %s",
ks, klass));
}
pointcut logAction(ActionListener a, ActionEvent e)
: target(a)
&& args(e)
&& execution(* actionPerformed(ActionEvent));
after(ActionListener a, ActionEvent e) : logAction(a, e) {
Object source = e.getSource();
Class klass = source.getClass();
if (a instanceof Action) {
System.out.println(String.format("action %s performed by an object of class %s", ((Action)a).getValue(Action.NAME), klass.getName()));
} else {
System.out.println(String.format("action performed by an object of class %s", klass.getName()));
}
}
pointcut logKeyEvent(KeyRemapper m, KeyEvent e)
: target(m)
&& args(e)
&& execution (public boolean KeyRemapper.dispatchKeyEvent(KeyEvent));
before(KeyRemapper m, KeyEvent e) : logKeyEvent(m, e) {
System.out.println(String.format("INPUT: %s", e.toString()));
}
after(KeyRemapper m, KeyEvent e) : logKeyEvent(m, e) {
System.out.println(String.format("OUTPUT: %s", e.toString()));
}
public static void main(String[] args) {
Login.main(args);
}
I try to enable runtime weaving with this aop.xml file on the classpath under META-INF:
<aspectj>
<aspects>
<!-- declare two existing aspects to the weaver -->
<aspect name="com.whatever.gui.aop.CapLogger"/>
</aspects>
<weaver options="-verbose -Xset:weaveJavaPackages=true -showWeaveInfo -debug">
<include within="javax.swing.*"/>
<include within="java.awt.*"/>
<include within="com.whatever.*"/>
</weaver>
</aspectj>
I run the application in the AspectJ project with the following JVM argument within Eclipse:
-javaagent:${eclipse_home}\plugins\org.aspectj.weaver_1.6.11.20110304135300\aspectjweaver.jar
And I've tried many other iterations.
No matter what I do, I find that my advices fire when the triggering code is within my com.whatever.* code but never fire when the triggering code is within javax.swing.* or java.awt.*.
What, if anything, am I doing wrong?
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03340 seconds