Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Exposing context in a Pointcut

#: mohan.radhakrishnan@xxxxxxxxxxxxx changed the world a bit at a time by saying on 10/3/2005 12:37 PM :#
Hi Ramnivas,

    I have a doubt about the first question/answer in the mail below.


However, suppose I don't necessarily wish to use this variable in the pointcut definition (in this(), target(), or args()), but only in the advice itself.
The solution actually uses this construct this(obj). Not sure what I am
missing.

Could you explain what this
You can use an anonymous pointcut combined with your non-exposing
pointcut.

means ?


Ramnivas's proposal is to use a named pointcut (executionOfMyCertainMethods()) which is not bound by itself to use this(), target(), etc, and later for your special advice to add the this() pointcut which will allow you access to the object (as per your initial mail: currently-executing object).

./alex
--
.w( the_mindstorm )p.


Thanks,
Mohan
-----Original Message-----
From: aspectj-users-bounces@xxxxxxxxxxx
[mailto:aspectj-users-bounces@xxxxxxxxxxx] On Behalf Of Ramnivas Laddad
Sent: Sunday, October 02, 2005 11:56 PM
To: Matt Morten; aspectj-users@xxxxxxxxxxx
Subject: Re: [aspectj-users] Exposing context in a Pointcut

Reply inline...

Matt Morten wrote:

Hello there,

I have several questions. Firstly, I would like a pointcut to expose a reference to the currently-executing object, so that I can call "wait()" on that object in my advice (think along the lines of Breakpoints). However, suppose I don't necessarily wish to use this variable in the pointcut definition (in this(), target(), or args()), but only in the advice itself. Is there any way of doing this, without getting a "[error] formal unbound in pointcut pointcut" error?
Yes. You can use an anonymous pointcut combined with your non-exposing
pointcut. Something like:

before(Object obj) : executionOfMyCertainMethods() && this(obj) {
    ...
   obj.wait();
}

Alternatively, you can use the thisJoinPoint variable available in any
advice:

before() : executionOfMyCertainMethods() {
    ...
   thisJoinPoint.getThis().wait();
}

I prefer the first form.

Secondly, I would like to have my aspect do something straight away
(unconditionaly) when it runs, so I chose to do this:

static {
 ... blah
}

However, by doing it this way, I don't have access to any context.
Thus, I am forced to create a pointcut that references the joinpoint where my "public static void main()" runs, in order to get that class.
Am i stuck to doing it this way?
You can use staticinitialization() pointcut to select join points
corresponding to class loading (hence covering all static
initialization).

My third question is this: are there / will there ever be Joinpoints for getting / setting local variables? At the moment, I am limited to only class fields, which is a bit of a limiting factor when I want to "Watch" all variables in my program.
No, there isn't a way to do this.

Thanks in advance,
Matt Morten
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users

===

Ramnivas Laddad,
Author, AspectJ in Action
http://ramnivas.com
M: (408)203-4621

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


This message is for the designated recipient only and may contain privileged, proprietary, or otherwise private information.  If you have received it in error, please notify the sender immediately and delete the original.  Any other use of the email by you is prohibited.
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users



Back to the top