扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
在本页阅读全文(共4页)
要想理解join point和pointcut的不同,可以把pointcut想成明确了织入的规则,而join point则声明了符合这些规则的情况(即什么情况下运用织入的规则)。
l 笔记要点
1. In AspectJ, pointcut can be either anonymous or named.
aspectj中,poincut可以是匿名的,也可以是命名的。
2. Notice that the name of the pointcut is at the left of the colon and pointcut definition is at the right. The pointcut definition is syntax that identifies the join points where you want to insert some action.
注意,pointcut的名字应位于冒号的左侧,而pointcut的定义在冒号的右侧。point cut的定义明确了你想在哪个join point插入一些动作。
3. Three wildcard notations are available in AspectJ:
1) * denotes any number of characters expect the period.
2) .. denotes any number of characters including any number of period.
3) + denotes any subclass or subinerface of a given type.
Example:
*Account Types with a name ending with Account such as SavingsAccout and CheckingAccount
java.*.Data Types Data in any direct subpackages of the java package, such as java.util.Data and java.sql.Data.
java..* Any type inside the java package or all of its direct subpackage, such as java.awt and java.util, as well as indirect subpackages such as java.awt.event and java.util.logging
以下是AspectJ中的三个通配符:
1) * 表示匹配任意数量的字符,除了句号(.)
2) .. 表示比配包含句号在内的任意数量的字符。
3) + 表示比配任意给定的类型的子类和子接口。
例子:
*Account 匹配以Account结尾的类型名,例如SavingsAccout和
CheckingAccount
java.*.Data 匹配java包下的直接子包下的Data类型,例如java.util.Data和java.sql.Data(注:但不能是java.a.b.Data, 因为*不能包含句号嘛)
java..* 匹配java包下任意类型或者其所有直接子包,例如java.awt和java.util,也可匹配其非直接子包,例如java.awt.event和java.util.logging
4. Please note that in method signatures, the wildcard .. used to denote any type and number of arguments taken by a method.
Example:
*java.io.Reader.read(char[],.. )
Any read() method in the Reader class irrespective of type and number of arguments to the method as long as the first argument type is char[]. In this case, it will mach read(char[]) and read(char[], int, int), but not read().
请注意在method signatures中,通配符..被用于表示匹配包含任意类型和任意数量的参数的方法。
例子:
*java.io.Reader.read(char[],.. )
Reader类中的任何read()方法,无论参数是什么类型,数量如何,只要其首参数是char[]类型,就可以匹配。这种情况下,它可以匹配read(char[]),也可以匹配read(char[], int, int),但不能匹配read()。
5. The execution join point is on the method body itself.
执行类型的join point是方法体本身。
Example:
In this code snippet, the point for the execution of the debit() method is the whole method body. This means that we can write advice for this join point to the applied before, after, and around the body.
在这个程序小片段里,debit()方法的执行类型joint point是整个方法体。这意味着我们可以为它写符合要求的advice(通知),包括before、after、around。(注:关于advice,将在下一篇中介绍)
6. The method call join point occurs at the place where this method is being invoked.
方法调用的join point放生在方法被引用的地方。
Example:
Account account = …...;
account.debit(100); //debit() method call join point
Note that the code that forms the arguments is not a part of the join point. For example, if the debit() method is called in the statement account.debit(Currend.round(100.2345)), the call Current.round(100.2345) is not part of the debit() method call join point.
注意,代码形式的参数不是call join point的一部分。例如如果debit()方法以如下形式调用,account.debit(Currend.round(100.2345)),那么Current.round(100.2345)不是其method call join point的一部分。
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者