How to get an initialized instance reference from constructor pointcut?

View: New views
4 Messages — Rating Filter:   Alert me  

How to get an initialized instance reference from constructor pointcut?

by 邵津 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi, everyone.
I'm using aspectJ to help me get an initialized instance reference after its constructor called. 

At first, I wrote some code like this:

after() returning (ArrayList l): call(ArrayList.new(..))

but the reference l I got seems not be initialized yet.

This is the first rule mentioned in http://dev.eclipse.org/mhonarc/lists/aspectj-users/msg00019.html


Then I changed my code into this:

after(ArrayList l) returningthis(l) &&execution(ArrayList.new(..))

(which is written according to the second rule mentioned in msg00019)

but this time, no matched join point has been found in the program...


My question is : how can I get an initialized instance reference using AspectJ?


Thanks very much!



Vivian

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

Re: How to get an initialized instance reference from constructor pointcut?

by Tahir Akhtar :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

The second issue (no matched join points) is due to the fact that ArrayList is a JDK class and "execution" of its constructor cannot be weaved.
So, I guess, you will have to stick with the "call" point cuts when dealing with the JDK classes.

I am not sure, but I guess an "around advice" to constructor "call" might do the trick for you.

Regards
Tahir Akhtar
邵津 wrote:
Hi, everyone.
I'm using aspectJ to help me get an initialized instance reference after its constructor called. 

At first, I wrote some code like this:

after() returning (ArrayList l): call(ArrayList.new(..))

but the reference l I got seems not be initialized yet.

This is the first rule mentioned in http://dev.eclipse.org/mhonarc/lists/aspectj-users/msg00019.html


Then I changed my code into this:

after(ArrayList l) returningthis(l) &&execution(ArrayList.new(..))

(which is written according to the second rule mentioned in msg00019)

but this time, no matched join point has been found in the program...


My question is : how can I get an initialized instance reference using AspectJ?




Thanks very much!



Vivian

--
Jin Shao

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


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

Re: How to get an initialized instance reference from constructor pointcut?

by Andrew Eisenberg :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Tahir's right about the second case.

In the first case, though you need to bind the 'l' to something.  So, try this:

after() returning (ArrayList l): call(ArrayList.new(..)) && target(l) {

    ...

}




On Wed, Jul 1, 2009 at 10:36 PM, 邵津 <shaojinvivian@...> wrote:
Hi, everyone.
I'm using aspectJ to help me get an initialized instance reference after its constructor called. 

At first, I wrote some code like this:

after() returning (ArrayList l): call(ArrayList.new(..))

but the reference l I got seems not be initialized yet.

This is the first rule mentioned in http://dev.eclipse.org/mhonarc/lists/aspectj-users/msg00019.html


Then I changed my code into this:

after(ArrayList l) returningthis(l) &&execution(ArrayList.new(..))

(which is written according to the second rule mentioned in msg00019)

but this time, no matched join point has been found in the program...


My question is : how can I get an initialized instance reference using AspectJ?


Thanks very much!



Vivian

--
Jin Shao

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



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

Re: How to get an initialized instance reference from constructor pointcut?

by Andy Clement :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Unfortunately as per http://www.eclipse.org/aspectj/doc/released/progguide/semantics-joinPoints.html there is no target for the constructor call join point.  But if you remove target completely from Andrews suggestion, you get something that will work:

after() returning (ArrayList l): call(ArrayList.new(..)) {

    ...

}

Andy.

2009/7/2 Andrew Eisenberg <andrew@...>
Tahir's right about the second case.

In the first case, though you need to bind the 'l' to something.  So, try this:

after() returning (ArrayList l): call(ArrayList.new(..)) && target(l) {

    ...

}




On Wed, Jul 1, 2009 at 10:36 PM, 邵津 <shaojinvivian@...> wrote:
Hi, everyone.
I'm using aspectJ to help me get an initialized instance reference after its constructor called. 

At first, I wrote some code like this:

after() returning (ArrayList l): call(ArrayList.new(..))

but the reference l I got seems not be initialized yet.

This is the first rule mentioned in http://dev.eclipse.org/mhonarc/lists/aspectj-users/msg00019.html


Then I changed my code into this:

after(ArrayList l) returningthis(l) &&execution(ArrayList.new(..))

(which is written according to the second rule mentioned in msg00019)

but this time, no matched join point has been found in the program...


My question is : how can I get an initialized instance reference using AspectJ?


Thanks very much!



Vivian

--
Jin Shao

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



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



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