扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
在本页阅读全文(共4页)
9. Lexical-structure based pointcuts
1) A lexical scope is a segment of source code. The within() pointcuts take the form of within(TypePattern) and are used to capture all the join points within the body of the specified classes and aspects, as well as any nested classes. The withincode() pointcuts take the form of either withincode(MethodSignature) or withincode(ConstrutorSignature) and are used to capture all the join points inside a lexical structure of constructor or a method, including any local classes in them.
lexical scope就是一个代码段。within() pointcut 形式是within(TypePattern) ,用来捕获声明的类、方面、还有内部类体的所有join point。withincode() pointcut的形式是withincode(MethodSignature)和withincode(ConstrutorSignature),用于捕获构造函数或方法的词法结构内的所有join point,包括它们内部的任何local classes。
2) One common usage of the within() pointcut is to exclude the join points in the aspect itself. For example, the following pointcut excludes the join point corresponding to the calls to all print methods in the java.io.PrintStream class that occur inside the TraceAspect itself:
call(*java.io.PrintStream.print*(..)) && ! within(TraceAspect)
3) this 和within的作用差不多,以下为不同点:
<1> within包含内部类,但不包含子类
<2> this包含子类,但不包含内部类
10. Argument pointcuts
These pointcuts capture join points based on the argument type of a join point. Similar to execution object pointcuts these pointcuts can be used to capture the context.
Example:
args(String, .. , int) All the join points in all methods where the first argument is of type String and last argument is of type int.
匹配所有以String为第一个参数类型,以int为最后一个参数类型的方法。
11. Control-flow based pointcuts
1) The control flow of a join point defines the flow of the program instructions that occur as a result of the invocation of the join point.
join point的控制流定义了程序指令的流程,以join point调用的结果的形式出现。
2) For example, the Account.debit() method calls Account.getBalance() as a part of its execution; the call and the excution of Account.getBalance() is said to have occurred in the Account.debit() method’s control flow, and therefore it has occurred in the control flow of the join point for the method.
例如:Account.debit()方法调用Account.getBalance()作为它执行的一部分;对Account.getBalance()进行call和execution操作都可以认为是发生在Account.debit()方法的控制流内,所以就是发生在join point的控制流内。
3) 以下是我经过实验后的一些理解:
接着上面的例子,如果Account.getBalance()中又调用了另一个方法,例如abc(),那么abc()的join point也属于Account.debit()的control-flow,也即不管经过了多少层的调用关系,用control-flow pointcut都可以判断出某个join point是否属于一个control-flow;这一点上和within()又有一定的区别,within只能判别出join point是否在一个代码块中出现过,即只能表示一层关系。
4) cflow(call(*Account.debit(..)) 任何在debit() control-flow中的join point都将被捕获,包括对debit()自身的call(即cflow()被用在了debit()自己的pointcut时的情况)
cflowbelow(call(*Account.debit(..)) 不包括对debit()自身的call
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者