2012-12-22 37 views
2

-n參數假設我定義這種形式通話繼續進行AspectJ中

* *.*(..) 

的切入點,我想定義around建議,我怎麼能調用與參數的任意數量的繼續?

我想過使用反射和thisJoinPoint.getArgs(),但在嘗試之前,我想知道是否有一個乾淨和簡單的方法。

+0

@LihO,而「意見」可能是AOP專用術語,標記爲,是會被人濫用來這裏是爲了「建議」。如果您必須堅持標籤存在,請主動對其進行警告或找到另一種方式來表達不會被無知標籤者濫用的想法。將濫用標籤的人的類型不是讀取和理解標籤wiki節選的類型,告訴他們不要使用它。 – Charles

回答

3

這是一個常見的誤解,proceed採用與匹配模式的方法相同的參數。但是,proceed需要參數建議規定。

例子:

class C { 
    public void foo(int i, int j, char c) { 
     System.out.println("T.foo() " + i*j + " " + c); 
    } 
} 

class Context { 
    public int bar = 7; 
    public void doStuff() { 
     C c = new C(); 
     c.foo(2, 3, 'x'); 
    } 
} 

一個方面:

public aspect MyAspect { 

    pointcut AnyCall() : 
     call(* *.*(..)) && !within(MyAspect); 

    void around(Context c) : AnyCall() && this(c) { 
     if (c.bar > 5) 
      proceed(c); // based on "around(Context c)" 
    }  
}