Sunday, June 1, 2014

Aspect-oriented Programming (AOP) - Static Pointcuts - Exercises



Try writing the following pointcuts statically capturing some joinpoints:

(According to the posts AOP - Pointcuts 1AOP - Pointcuts 2)
  1. The pointcut that captures any call to any int method containing the word "Method" in its name. For example:
class C{
  public static void main(){
      D d = new D();
1.    d.thisMethodIsCool();
  }
}

class D{
  public int thisMethodIsCool(){
2.    System.out.println("within the cool method");
  }
}

The pointcut should match the call in line 1 of class C.



pointcut callMethod(): call(int *.*Method*(..))


  1. The same as before but now capture the execution of the method, i.e., when the eecution flow is within line 2 of class D.

pointcut executeMethod(): execution(int *.*Method*(..))



  1. This pointcut should match whenever a String field named "name" is set

pointcut setName(): set(String *.name)

No comments:

Post a Comment