[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
RE: [aspectj-users] simple question
|
Having tried this out, I wasn't about to make this happen with before or
after or after returning advice.
Around advice seemed to work though:
pointcut newJ():
call(JComponent+.new(..));
Object around(): newJ() {
Object o = proceed();
((JComponent)o).setToolTipText("My Tip");
System.err.println("Set");
return o;
}
If anyone could explain why only around advice seemed to work, I'd
appreciate it!
Thanks,
Dave.
-----Original Message-----
From: Ron Bodkin [mailto:rbodkin@xxxxxxxxxxxxxx]
Sent: Monday, September 29, 2003 1:16 PM
To: aspectj-users@xxxxxxxxxxx
Subject: Re: [aspectj-users] simple question
Hi Dmitry,
You surely don't want before advice here; the given object hasn't been
initialized at that point (and target is null). For a more complete
discussion of the topic of construction join points and how to access newly
constructed objects, see the FAQ entries 10.6 and 10.7 at
http://dev.eclipse.org/viewcvs/indextech.cgi/~checkout~/aspectj-home/doc/faq
.html#q:initializationjoinpoints
Here's a stab at how you might write your aspect. If you need to set the
tool tip "during" construction and not after, you probably will want to
write a pointcut based on being withincode of your constructors.
public aspect AddToolTip {
pointcut newJ():
call(javax.swing.JComponent+.new(..));
after() returning (javax.swing.JComponent c) : newJ(){
c.setToolTipText("OK");
}
}
Ron Bodkin
Chief Technology Officer
New Aspects of Security
m: (415) 509-2895
> ------------Original Message-------------
> From: =?koi8-r?Q?=22=E4=CD=C9=D4=D2=C9=CA=22=20?= <dmrzh@xxxxxxx>
> To: aspectj-users@xxxxxxxxxxx
> Date: Sun, Sep-28-2003 11:50 PM
> Subject: [aspectj-users] simple question
>
> I want write aspect for set ToolTip text for all comonents, but this picks
out no join points.
> Help me please.
>
> import javax.swing.JComponent;
> public aspect AddToolTip {
> pointcut newJ(javax.swing.JComponent c):
> call(javax.swing.JComponent+.new(..))&& target(c);
> before(javax.swing.JComponent c) : newJ(c){
> c.setToolTipText("OK");
> }
> }
>
>
> import javax.swing.*;
> import java.awt.*;
> public class MyFrame extends JFrame{
> public static void main(String[] args){
> MyFrame f=new MyFrame();
> f.setSize(300,300);
> JPanel cp=new JPanel(new FlowLayout());
> JButton b=new JButton("Ok");
> cp.add(b);
> f.setContentPane(cp);
> f.show();
> }
>
> }
>
> Dmitriy.
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> http://dev.eclipse.org/mailman/listinfo/aspectj-users
>
>
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/aspectj-users