Monday, March 12, 2007

This Vs. Target in AspectJ

package pilot;

public aspect ConfusionKiller {
    //static pointcut
    pointcut TestThis(Helloaj2 h2) : call(public String getName())&&this(h2);    
    //dynamic pointcut
    pointcut TestTarget(Helloaj2 h2) : call(public String getName())&&target(h2);

   //这个在AJDT中是可以静态确定的,this在编译时指定Type
   //call:间接调用执行;Execution: 直接执行
    before(Helloaj2 h2): TestThis(h2) {
        System.out.println("this");        
    }
   //这个在AJDT中是一个带问号的advice形式,target在运行时判断Type
    before(Helloaj2 h2): TestTarget(h2) {
        System.out.println("target");
    }
}

No comments: