AspectJ指向特定方法中的方法调用的切入点 [英] AspectJ pointcut to method call in specific methods
本文介绍了AspectJ指向特定方法中的方法调用的切入点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想创建一个切入点,以将特定方法的调用作为目标.
采取以下措施:
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());
在此处查找切入点参考 >
I want to create a pointcut to target a call to a method from specific methods.
take the following:
class Parent {
public foo() {
//do something
}
}
class Child extends Parent {
public bar1() {
foo();
}
public bar2() {
foo();
}
public bar3() {
foo();
}
}
I would like to have a point cut on the call to foo() in methods bar1() and bar3()
I was thinking something like
pointcut fooOperation(): call(public void Parent.foo() && (execution(* Child.bar1()) || execution(* Child.bar3()) );
before() : fooOperation() {
//do something else
}
however, that doesnt seem to work. any ideas?
thanks
解决方案
Maybe withincode
will work:
call(public void Parent.foo()) && (withincode(* Child.bar1()) || withincode(* Child.bar3()) );
Alternatively you could try the cflow
pointcut:
pointcut bar1(): call(* Child.bar1());
pointcut bar3(): call(* Child.bar3());
call(public void Parent.foo()) && (cflow(bar1()) || cflow(bar3());
Look here for a pointcut reference
这篇关于AspectJ指向特定方法中的方法调用的切入点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文