如何使用Java将变量发送到Aspect?

时间:2015-07-15 06:59:38

标签: java eclipse aspectj ajdt

我想知道是否有办法从main函数中获取变量并在方面中使用它。我知道before()after()建议会在methodeOne之前和之后执行,但他们如何获得VAR1和/或VAR2

public class AOPdemo {

    public static void main(String[] args) {
        AOPdemo aop = new AOPdemo();
        aop.methodeOne(5);//Call of the function wrapped in the aspect
        int VAR1;
        //VAR1 variable im trying to send to the aspect
    }
    public void methodeOne(int VAR2){
        //VAR2 another variable i'm trying to send to the aspect
        System.out.println("method one");
    }
}
public aspect myAspect {
    pointcut function():
    call(void AOPdemo.methode*(..));

    after(): function(){
        int VAR1;//Trying to get this variables
        int VAR2;
        System.out.println("aspect after...");  
    }

    before(): function(){
        System.out.println("...aspect before");
    }
}

0 个答案:

没有答案