Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
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
> 
> 


Back to the top