[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [aspectj-users] Addressing classes that arent being compiled

Hi Mark,

If you try :
pointcut textFieldInit () :
        call(JTextField+.new(..));
       
Object around () : textFieldInit()
{
       Object obj = proceed();
       JTextField txtFldInit = (JTextField)obj;
       System.out.println("TextFieldInit!" + txtFldInit);
	 return txtFldInit;
}   

You are using an around advice instead of 'after returning'.  When you
call the proceed() method in an around advice - this carries out the
method being advises, and returns values as normal.  In this case it
returns your newly created JTextField, which you can then use in your
advice.

Regards,

Fintan

-----Original Message-----
From: aspectj-users-bounces@xxxxxxxxxxx
[mailto:aspectj-users-bounces@xxxxxxxxxxx] 
Sent: 20 April 2005 14:13
To: aspectj-users@xxxxxxxxxxx
Subject: Re: [aspectj-users] Addressing classes that arent being
compiled


Hello,

Thank you for your reply. I had tried this, however without the '+', as 
this is new to me (as I understand this means also for any subclass). It

matches fine when I use:

pointcut textFieldInit () :
        call(JTextField+.new(..));
       
after () returning : textFieldInit()
{
        System.out.println("TextFieldInit!");   
}   

This matches fine, but I cannot relate to the instance of JTextField. 
Due to the nature of my experimenting I would like to get hold of the 
actual instance of the JTextField after it has been initialised, so I 
figured to use the following:

pointcut textFieldInit (JTextField textField) :
        call(JTextField+.new(..)) && target(textField);
       
after (JTextField textField) returning : textFieldInit(textField) {
        System.out.println("TextFieldInit!" + textField);    
}

Now this does not match very well as I receive the following error:

D:\..\userinterface\TestAspect.aj:22 [warning] advice defined in 
userinterface.TestAspect has not been applied [Xlint:adviceDidNotMatch]
after (JTextField textField) returning : textFieldInit(textField)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

So something is going wrong there :-(, what am I doing wrong? Or am I 
trying to do something that isn't that natural? (I am making new 
instances of JTextField obviously in my program...)

Cheers,

Mark


>You /can/ pass compiled .class files into the AspectJ weaver using the 
>-inpath option, but you probably don't want to be weaving rt.jar. 
>Changing your aspect slightly to:
>
>pointcut textFieldInit() : call(JTextField+.new(..));
>
>after () returning(JTextField textField) : textFieldInit()
>{
>  System.out.println("TextFieldInit!" + textField);
>}
>
>should give you want you want. The "call" pointcut matches join points 
>on the calling side, which is where you are...
>
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users


* ** *** ** * ** *** ** * ** *** ** * 
This email and any files transmitted with it are confidential and 
intended solely for the use of the individual or entity to whom they 
are addressed. 
Any views or opinions presented are solely those of the author, and do not necessarily 
represent those of ESB. 
If you have received this email in error please notify the sender. 
 
Although ESB scans e-mail and attachments for viruses, it does not guarantee 
that either are virus-free and accepts no liability for any damage sustained 
as a result of viruses. 
 
* ** *** ** * ** *** ** * ** *** ** *