Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » AspectJ » PointCut and Advice to "new" object
PointCut and Advice to "new" object [message #45974] Wed, 12 January 2005 14:37 Go to next message
harry sheng is currently offline harry shengFriend
Messages: 37
Registered: July 2009
Member
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 #46023 is a reply to message #45974] Wed, 12 January 2005 20:36 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: newsserver_mails.bodden.de

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

--
Eric Bodden, ICQ: 12656220, http://www.bodden.de, PGP: BB465582
How to remove incorrectly marked bad secotrs on NTFS...
http://bodden.de/misc/ntfsrecovery/
Re: PointCut and Advice to "new" object [message #46052 is a reply to message #46023] Thu, 13 January 2005 14:50 Go to previous messageGo to next message
harry sheng is currently offline harry shengFriend
Messages: 37
Registered: July 2009
Member
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 #46168 is a reply to message #46052] Sat, 15 January 2005 20:42 Go to previous messageGo to next message
Eclipse UserFriend
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 #46286 is a reply to message #46168] Mon, 17 January 2005 09:28 Go to previous messageGo to next message
Matthew Webster is currently offline Matthew WebsterFriend
Messages: 20
Registered: July 2009
Junior Member
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 #46315 is a reply to message #46286] Mon, 17 January 2005 12:15 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: newsserver_mails.bodden.de

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

--
Eric Bodden, ICQ: 12656220, http://www.bodden.de, PGP: BB465582
How to remove incorrectly marked bad secotrs on NTFS...
http://bodden.de/misc/ntfsrecovery/
Re: PointCut and Advice to "new" object [message #46344 is a reply to message #46315] Mon, 17 January 2005 13:49 Go to previous messageGo to next message
Matthew Webster is currently offline Matthew WebsterFriend
Messages: 20
Registered: July 2009
Junior Member
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 #46403 is a reply to message #46344] Mon, 17 January 2005 17:09 Go to previous messageGo to next message
Eclipse UserFriend
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 08:41 Go to previous message
Matthew Webster is currently offline Matthew WebsterFriend
Messages: 20
Registered: July 2009
Junior Member
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 #585764 is a reply to message #45974] Wed, 12 January 2005 20:36 Go to previous message
Eric Bodden is currently offline Eric BoddenFriend
Messages: 32
Registered: July 2009
Member
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

--
Eric Bodden, ICQ: 12656220, http://www.bodden.de, PGP: BB465582
How to remove incorrectly marked bad secotrs on NTFS...
http://bodden.de/misc/ntfsrecovery/
Re: PointCut and Advice to "new" object [message #585777 is a reply to message #46023] Thu, 13 January 2005 14:50 Go to previous message
harry sheng is currently offline harry shengFriend
Messages: 37
Registered: July 2009
Member
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 20:42 Go to previous message
Eric Bodden is currently offline Eric BoddenFriend
Messages: 32
Registered: July 2009
Member
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 09:28 Go to previous message
Matthew Webster is currently offline Matthew WebsterFriend
Messages: 20
Registered: July 2009
Junior Member
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 #585902 is a reply to message #46286] Mon, 17 January 2005 12:15 Go to previous message
Eric Bodden is currently offline Eric BoddenFriend
Messages: 32
Registered: July 2009
Member
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

--
Eric Bodden, ICQ: 12656220, http://www.bodden.de, PGP: BB465582
How to remove incorrectly marked bad secotrs on NTFS...
http://bodden.de/misc/ntfsrecovery/
Re: PointCut and Advice to "new" object [message #585910 is a reply to message #46315] Mon, 17 January 2005 13:49 Go to previous message
Matthew Webster is currently offline Matthew WebsterFriend
Messages: 20
Registered: July 2009
Junior Member
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 17:09 Go to previous message
Eric Bodden is currently offline Eric BoddenFriend
Messages: 32
Registered: July 2009
Member
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 08:41 Go to previous message
Matthew Webster is currently offline Matthew WebsterFriend
Messages: 20
Registered: July 2009
Junior Member
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
Previous Topic:Catch Exception instance in advice for handler pointcut
Next Topic:UpdateJob Exception
Goto Forum:
  


Current Time: Wed Jan 15 14:45:16 GMT 2025

Powered by FUDForum. Page generated in 0.55582 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top