[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] Getting javax.swing to weave

[first posted at the AJDT forum where I was urged to try here]

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()));
}
}
...
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 several other variations.

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? Can someone help? Is this even possible?