Home » Language IDEs » AspectJ » PointCut and Advice to "new" object
PointCut and Advice to "new" object [message #45974] |
Wed, 12 January 2005 09:37  |
Eclipse User |
|
|
|
Hi,
I want pointcut each and every "new my.pkg1.MyClass()" call in every class
of my.pkg2 package. In the advice, I want to catch the instance from which
the "new my.pkg1.MyClass()" is called, and the new my.pkg1.MyClass
instance.
How should I write the pointcut and advice? It seems I could only get
either one instance, not both.
Harry Sheng
|
|
| | |
Re: PointCut and Advice to "new" object [message #46168 is a reply to message #46052] |
Sat, 15 January 2005 15:42   |
Eclipse User |
|
|
|
Originally posted by: newsserver_mails.bodden.de
On Thu, 13 Jan 2005 14:50:33 +0000 (UTC), Harry Sheng wrote:
> In this advice, the thisJoinPoint.getTarget() returns NULL. Tried the
> before and around advices, the same result. Should not it be the "caller"?
No. For a call pointcut the target is the object being called. However, in
this specific case, due to a compiler limitation, the called object is not
yet known (since it is still about to be created). Thus you will get null.
Eric
--
Eric Bodden, ICQ: 12656220, http://www.bodden.de, PGP: BB465582
Arithmetic Coding - educational example code and more
http://ac.bodden.de/
|
|
| | | |
Re: PointCut and Advice to "new" object [message #46403 is a reply to message #46344] |
Mon, 17 January 2005 12:09   |
Eclipse User |
|
|
|
Originally posted by: newsserver_mails.bodden.de
On Mon, 17 Jan 2005 13:49:00 +0000 (UTC), Matthew Webster wrote:
> Please see this thread
> ( http://dev.eclipse.org/mhonarc/lists/aspectj-dev/msg01149.ht ml)
> concerning return values at join points, especially Gregor's response. The
> object created by a call to new is not a property of the join point either.
Ok, I see the connection. So do I understand correctly, that technically it
would actually be possible to expose the object in this specific context,
but since such arguments are only exposed when they exist while entering
*and* leaving the joinpoint, they are not exposed?
Cheers,
Eric
--
Eric Bodden, ICQ: 12656220, http://www.bodden.de, PGP: BB465582
Arithmetic Coding Revealed - a comprehensive guide to AC
http://bodden.de/studies/publications/pub_ac_en/
|
|
|
Re: PointCut and Advice to "new" object [message #46461 is a reply to message #46403] |
Tue, 18 January 2005 03:41  |
Eclipse User |
|
|
|
Join points have both static (e.g. declaring type) and dynamic (e.g.
target) properties. You could consider return values such as the object
created at a new call join point a "product" of the join point.
Eric Bodden wrote:
> Ok, I see the connection. So do I understand correctly, that technically it
> would actually be possible to expose the object in this specific context,
> but since such arguments are only exposed when they exist while entering
> *and* leaving the joinpoint, they are not exposed?
> Cheers,
> Eric
|
|
| |
Re: PointCut and Advice to "new" object [message #585777 is a reply to message #46023] |
Thu, 13 January 2005 09:50  |
Eclipse User |
|
|
|
I got it worked. Thanks very much, Eric.
pointcut mypointcut(Caller caller):
this(caller) && call (NewInstance.new(..));
after (Caller caller) returning (NewInstance ni): mypointcut(caller)
{
..
}
In this advice, the thisJoinPoint.getTarget() returns NULL. Tried the
before and around advices, the same result. Should not it be the "caller"?
Eric Bodden wrote:
> On Wed, 12 Jan 2005 14:37:46 +0000 (UTC), Harry Sheng wrote:
>> How should I write the pointcut and advice? It seems I could only get
>> either one instance, not both.
> You need a call pointcut with after returning advice and can then expose
> the caller using this(a) and the new Object using target(b) I believe...
> Eric
|
|
|
Re: PointCut and Advice to "new" object [message #585829 is a reply to message #46052] |
Sat, 15 January 2005 15:42  |
Eclipse User |
|
|
|
On Thu, 13 Jan 2005 14:50:33 +0000 (UTC), Harry Sheng wrote:
> In this advice, the thisJoinPoint.getTarget() returns NULL. Tried the
> before and around advices, the same result. Should not it be the "caller"?
No. For a call pointcut the target is the object being called. However, in
this specific case, due to a compiler limitation, the called object is not
yet known (since it is still about to be created). Thus you will get null.
Eric
--
Eric Bodden, ICQ: 12656220, http://www.bodden.de, PGP: BB465582
Arithmetic Coding - educational example code and more
http://ac.bodden.de/
|
|
|
Re: PointCut and Advice to "new" object [message #585883 is a reply to message #46168] |
Mon, 17 January 2005 04:28  |
Eclipse User |
|
|
|
I don't think this is a compiler limitation unless you consider
clairvoyance i.e. knowing in advance what object is to be allocated a
genuine feature ;-). It is my understanding that constructor invocations
have the semantics of static method invocations in AspectJ hence no
target. BTW Harry you might consider posting questions like this to the
aspectj-users: https://dev.eclipse.org/mailman/listinfo/aspectj-users
Eric Bodden wrote:
> On Thu, 13 Jan 2005 14:50:33 +0000 (UTC), Harry Sheng wrote:
>> In this advice, the thisJoinPoint.getTarget() returns NULL. Tried the
>> before and around advices, the same result. Should not it be the "caller"?
> No. For a call pointcut the target is the object being called. However, in
> this specific case, due to a compiler limitation, the called object is not
> yet known (since it is still about to be created). Thus you will get null.
> Eric
|
|
| |
Re: PointCut and Advice to "new" object [message #585910 is a reply to message #46315] |
Mon, 17 January 2005 08:49  |
Eclipse User |
|
|
|
Please see this thread
( http://dev.eclipse.org/mhonarc/lists/aspectj-dev/msg01149.ht ml)
concerning return values at join points, especially Gregor's response. The
object created by a call to new is not a property of the join point either.
Eric Bodden wrote:
> On Mon, 17 Jan 2005 09:28:14 +0000 (UTC), Matthew Webster wrote:
>> I don't think this is a compiler limitation unless you consider
>> clairvoyance i.e. knowing in advance what object is to be allocated a
>> genuine feature ;-).
> In an *after* advice, the object should be known, shouldn't it?
> Eric
|
|
|
Re: PointCut and Advice to "new" object [message #585930 is a reply to message #46344] |
Mon, 17 January 2005 12:09  |
Eclipse User |
|
|
|
On Mon, 17 Jan 2005 13:49:00 +0000 (UTC), Matthew Webster wrote:
> Please see this thread
> ( http://dev.eclipse.org/mhonarc/lists/aspectj-dev/msg01149.ht ml)
> concerning return values at join points, especially Gregor's response. The
> object created by a call to new is not a property of the join point either.
Ok, I see the connection. So do I understand correctly, that technically it
would actually be possible to expose the object in this specific context,
but since such arguments are only exposed when they exist while entering
*and* leaving the joinpoint, they are not exposed?
Cheers,
Eric
--
Eric Bodden, ICQ: 12656220, http://www.bodden.de, PGP: BB465582
Arithmetic Coding Revealed - a comprehensive guide to AC
http://bodden.de/studies/publications/pub_ac_en/
|
|
|
Re: PointCut and Advice to "new" object [message #585956 is a reply to message #46403] |
Tue, 18 January 2005 03:41  |
Eclipse User |
|
|
|
Join points have both static (e.g. declaring type) and dynamic (e.g.
target) properties. You could consider return values such as the object
created at a new call join point a "product" of the join point.
Eric Bodden wrote:
> Ok, I see the connection. So do I understand correctly, that technically it
> would actually be possible to expose the object in this specific context,
> but since such arguments are only exposed when they exist while entering
> *and* leaving the joinpoint, they are not exposed?
> Cheers,
> Eric
|
|
|
Goto Forum:
Current Time: Sun Jun 08 09:06:37 EDT 2025
Powered by FUDForum. Page generated in 0.06194 seconds
|