Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] get a object not "this" or "target"

You need to use the wormhole design pattern (described in AspectJ in Action :-)) that goes something like:

public aspect WormholeAspect {
   pointcut callerSpace(<caller context>)
            : <caller pointcut>;
   pointcut calleeSpace(<callee context>)
           : <callee pointcut>;
 
   pointcut wormhole(<caller context>, <callee context>)
           : cflow(callerSpace(<caller context>))
              && calleeSpace(<callee context>);

    // advices to wormhole
    around(<caller context>, <callee context>)
       : wormhole(<caller context>, <callee context>) {
           ... advice body
    }
}

-Ramnivas

On Fri, Feb 29, 2008 at 8:08 AM, Heping Zhang <phoenix.zhp@xxxxxxxxx> wrote:
hi, say I have the following classes:
 
public class A {
  B b = new B();
  private void ma() {
    b.mb();
 }
}
public class B {
  C b = new C();
 private void ma() {
   for(something){
     c.mc();
   }
 }
}
 
Now I want to catch the join point of calling to --or executing -- C.mc and  get the object of class A who on the top of the call stack, like this:
 private pointcut p(int thisDone,Object iWantA) :
  call(* C.mc(..)) &&
  cflowbelow(execution(* A.ma()))
  && args(byte[], int, thisDone)
  && this(iWantA);
 
I know this won't work. I can only get b when use this. But how can I get a? Can any one give me some suggestion?

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



Back to the top