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

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



Back to the top