[英]AspectJ pointcut to method call in specific methods
我想創建一個切入點來定位從特定方法對方法的調用。
采取以下措施:
class Parent {
public foo() {
//do something
}
}
class Child extends Parent {
public bar1() {
foo();
}
public bar2() {
foo();
}
public bar3() {
foo();
}
}
我想在方法 bar1() 和 bar3() 中對 foo() 的調用有個切入點
我在想類似的東西
pointcut fooOperation(): call(public void Parent.foo() && (execution(* Child.bar1()) || execution(* Child.bar3()) );
before() : fooOperation() {
//do something else
}
但是,這似乎不起作用。 有任何想法嗎?
謝謝
也許withincode
會起作用:
call(public void Parent.foo()) && (withincode(* Child.bar1()) || withincode(* Child.bar3()) );
或者,您可以嘗試cflow
切入點:
pointcut bar1(): call(* Child.bar1());
pointcut bar3(): call(* Child.bar3());
call(public void Parent.foo()) && (cflow(bar1()) || cflow(bar3());
在此處查找切入點參考
想想你想要的不是執行執行子句(它有一個額外的缺點是需要為每個新的調用者添加),而是使用目標,例如:
target(Child) && call(public void Parent.foo()).
有點令人驚訝的是,我發現 eclipse 文檔中的切入點指南非常有用。 他們在這里。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.