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

Hi,

Thanks for your help, I know understand why my code didnt work. Sorry I didnt get you the first time round Adrian, I just thought you forgot to write down the target and things in your pointcut, but obviously I was wrong. I didnt know you can use after returning advice (though it is very useful!).

Also thanks for the other solution which enlightend me on how I would have to do an around advice on a constructor (as I was unsure what type to use).

It seems to work now :)

Cheers and thanks,

Mark



Fintan is correct in his assessment, however there *is* a way to get the
JTextField instance, which is to use the returning parameter form of after
returning advice, as in the sample I posted earlier:



pointcut textFieldInit() : call(JTextField+.new(..));

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



-- adrian

20 April 2005 15:05
To: <aspectj-users@xxxxxxxxxxx>
cc:
From: "Conway. Fintan (IT Solutions)" <Fintan.Conway@xxxxxx>
Subject: RE: [aspectj-users] Addressing classes that arent being compiled



Hi Mark,

Your pointcut matches a call to a constructor, as you know.  However,
when your code calls the constructor, the object has not been created
yet (since this is the constructor's job).  Therefore there is no
target, so your pointcut cannot match.

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.

* ** *** ** * ** *** ** * ** *** ** *

_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users

_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users