2009-10-31 38 views
1

我想出了以下用於跟蹤方法進入/退出的切入點。它沒有壞,也做我想要的,但是:1-我覺得它看起來笨拙或可能更優雅;和2-我不知道它是否防彈。有沒有辦法改善這個切入點?

// tracing the execution of all methods except: 
// - toString and descendants 
// - methods identified with @NotTraced and descendants 
pointcut theMethod() : 
     within(*.*) && 
     !within(tracing.*) 
     && execution(* *(..)) 
     && !adviceexecution() 
     && !cflow(adviceexecution()) 
     && !execution(String *.toString()) 
     && !cflow(execution(String *.toString())) 
     && !execution(@NotTraced * *(..)) 
     && !cflow(execution(@NotTraced * *(..))); 

有什麼想法?

回答

1

這遠比它需要的複雜。

我將其分解成兩個部分:

  1. 所有方法調用異常 的toString()
  2. 所有方法調用異常 @NotTraced和它的後代。

然後,您可以使用&&使兩個切入點具有相同的方面。

這樣你可以有更多的靈活性,以防你需要在其他地方使用其中的一種。

我會從非常簡單的開始,在Eclipse中使用AJDT來監視哪些連接點受到影響,以便獲得所需的最小值。

現在,看起來你在這裏有冗餘,例如!adviceexecution()!cflow(adviceexecution),因爲你有三個不同的地方cflow和執行重複。

AJDT將成爲您的朋友,因爲很難準確地確定您可能會排除的內容,例如。

保持它非常簡單,以避免任何不必要的影響。