So far we have talked very little about pointcuts, but there are several syntax keywords that allow capturing different joinpoints.
Here is the whole list: Pointcuts, but I will point out some that are very useful (and used):
call(MethodPattern): whenever a method is called. MethodPattern is an expression (containing wildcards) that may capture different sets. For instance public int C.m(String) is a method pattern capturing the public method m of class C that receives one argument of type String. We can also define the following * *.*(..) which represents, any method of any class of any type with any set of arguments. Something in the middle could be * Cl*.me*(String, ..) which captures methods (of any type) that begin with me, of classes that start with Cl and receive at least one String argument (as the first argument).
execution (MethodPattern), is similar but represents when we are in the class of the method pattern. To observe the difference between call and execution let's consider the following example:
1. class MainClass {
2. public static void main(){
3. C o1 = new C();
4. o1.m();
5. }
6. }
1. class C {
2. public void m(){
3. }
4. }
the call pointcut matches the location at MainClass, line 4; while the execution pointcut matches the execution within C that is, between lines 2 and 3 of class C.
No comments:
Post a Comment