[aosd-discuss] About pointcut

Kawtip Nippon kawtip at yahoo.com
Fri Aug 11 04:32:23 EST 2006


Dear all, 
   
       I'd like to ask some more questions. From this quotation from aspectj tutorials... 
  --------------------------------------------------------
  When matching method-execution join points, if the execution pointcut method signature specifies a declaring type, the pointcut will only match methods declared in that type, or methods that override methods declared in or inherited by that type. So the pointcut 

  execution(public void Middle.*())  
  picks out all method executions for public methods returning void and having no arguments that are either declared in, or inherited by, Middle, even if those methods are overridden in a subclass of Middle. So the pointcut would pick out the method-execution join point for Sub.m() in this code: 

  class Super {      protected void m() { ... }    }    class Middle extends Super {    }    class Sub extends Middle {      public void m() { ... }    }

--------------------------------

   I try to write some code to test. This is the code...

--------------------------------------------------------

class TestAccessModifiers {

 public void printA(){
  System.out.println("A");
 }
}
class Level2 extends TestAccessModifiers{
 
}
class Level3 extends Level2{
 public void printA(){
  System.out.println("Level3 protected");
 }
 public static void main(String[] args){
  Level2 l2 = new Level2();
  l2.printA();
  Level3 l3 = new Level3();
  l3.printA();
  Level2 l22 = new Level3();
  l22.printA();
 }
  }

aspect CallMethods {
 pointcut exeM(): execution(public void Level2.*());
 before(): exeM(){
  System.out.println(thisJoinPoint);
 }
 
}
  --------------------------------------------------------
       and this is the result after i run the class (using ajdt with eclipse)
--------------------------------------------------------
  A
  execution(void p8.Level3.printA())
  Level3 protected
  execution(void p8.Level3.printA())
  Level3 protected
  --------------------------------------------------------
       I questioned that why the poincut can capture Level3.printA(). I thought that it can't capture this JoinPoint and it can capture this JoinPoint if the pointcut specify that execution(public void Level2+.*()) instead (+ should make the pointcut cover methods in Level3 class).
       And I wonder that why the pointcut can't capture a joinpoint l2.printA().
   
       Thank you very much in advance for you all,
  Kawtip

 		
---------------------------------
Yahoo! Messenger with Voice. Make PC-to-Phone Calls to the US (and 30+ countries) for 2¢/min or less.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: /pipermail/discuss_aosd.net/attachments/20060811/5fe25f81/attachment.html 


More information about the discuss mailing list