Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [aspectj-users] Getting the name that matched c_* in call(* C+.f_*(..)) && cflow(call(t C+.c_*(..)));

John M. Adams said:

    Say, I have a pointcut like:

    call(* Entity+.f_*(..)) && cflow(call(void Entity+.c_*(..)));

    The code below uses thisJoinPoint to gets this, target and, the name
    matching f_*.  How can I get the name matching c_*?

You can't do this via 'thisJoinPoint', because it only describes the
current join point, it doesn't talk about the pointcut that matched
the join point. And in your pointcut, the joinpoint you are at is a
call to some f_* method defined on Entity+. You are within the control
flow of a call to some c_*, but you are not actually at that join point.

AspectJ could conceviably be extended to give you this kind of
reflective information. I don't immediatlely recall someone asking
for it before. But I think it would need to be in some other object,
like thisAdvice or something. I believe it would violate the conceptual
structure of the language to put it in thisJoinPoint.  Of course
adding something like 'thisAdvice' at this stage would be questionable,
since it could break existing code. So we'd have to find some other
way to do it.

You can simulate the functionality you want by doing something like:

aspect Foo {

  ThreadLocalStack stack = new ThreadLocalStack();

  pointcut foo(): call(   foo   );
  pointcut bar(): call(   bar   );

  before(): foo() { stack.push(thisJoinPoint); }
  after():  foo() { stack.pop():               }

  before(): bar() && cflow(foo()) {
     JoinPoint fooPoint = (JoinPoint)stack.top();
     JoinPoint barPoint = thisJoinPoint;

     << your code goes here  >>

  }

}



Back to the top