I have made the same
error few months ago. You have to set only one Xset like :
-Xset:weaveJavaxPackages=true,weaveJavaPackages=true
De :
aspectj-users-bounces@xxxxxxxxxxx [mailto:aspectj-users-bounces@xxxxxxxxxxx] De la part de Kajetan Abt
Envoyé : vendredi 25
septembre 2009 14:14
À : aspectj-users@xxxxxxxxxxx
Objet : [aspectj-users] LTW
into javax.swing
What I am trying to do: Swing has support for Tooltips, but that
functionality is very basic. There are two functions (SetToolTip() and
GetToolTip()) which either take a String argument or return one. I would like
to have different Tooltips, to be precise, different verbosity levels, for all
tooltips in my project. Of course I could either overload all used JComponents
(hah!) or use some other nontrivial approach (manage my own listeners...) to
set these values anew every time the user changes the verbosity level.
But on the other hand, having an Aspect weave into GetToolTip() would instantly
solve my issues, as I could then change the return parameter (read from a
properties file). I have managed to figure out how to basically do this, and it
works, as long as I am weaving into my own code (I suppose it would work at
compile time even). But for some reason, weaving into Swing fails without error
messages, it just does not happen. I assume the class loader has my classes
prepared before the weaver kicks in, but I have absolutely no idea how to do
that different. There is also not a lot of literature on the subject and I only
assume this happens because I've read somewhere that writing a classloader
might be necessary (without explanation as to why or how). I am settnig the
option to the weaver to include javax, but it won't find JComponent. If I don't
exclude the org.jdesktop package, it even tries to find the superclasses of
some of the jdesktop parts at javax.jnlp.*, so it doesn't completely fail.
As for the call I want to intercept: javax.swing.ToolTipManager is the class
that calls my target function. It never gets woven.
As for the code I use:
aop.xml:
<aspectj>
<aspects>
<aspect name="<something>.weaver.
Wrangler"/>
<include within="<something>..*"/>
<include within="javax.swing..*"/>
<exclude within="org.jdesktop..*"/>
</aspects>
<weaver
options="-verbose -Xset:weaveJavaxPackages=true
-Xset:weaveJavaPackages=true -showWeaveInfo" >
<include within="<something>..*"/>
<include within="javax.swing..*"/>
<exclude within="org.jdesktop..*"/>
</weaver>
</aspectj>
public aspect Wrangler {
before(JComponent component):
call( public String
JComponent.getToolTipText(MouseEvent) )
&& target(component)
{
System.out.println("Intercepted!");
//target.setToolTip("My
new thing");
}
}
The output I get:
[AppClassLoader@19134f4] weaveinfo Join point 'method-call(java.lang.String
javax.swing.JMenuItem.getToolTipText())' in Type
<something>.gui.AppClientView' (AppClientView.java:596) advised by before
advice from '<something>.weaver.Wrangler' (Wrangler.aj:33)
And all other calls I make myself. Changing this to execution or anything like
that does not help at all. No Javax.Swing classes are woven at all.