Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] About AspectJ pointcut


Kawtip,

Your pointcut "execution(public void Level2.*());" matches all methods defined on Level2 (including any it inherits). Level3.printA() is a method defined on Level2 but overridden in Level3. Changing the pointcut to "execution(public void Level2+.*());"  would include all methods defined (not overridden) in subclasses of Level2. If you added another method in Level3 say "public void printB()" then that would be matched by the new pointcut.

The Level2 class itself is not advised because it does not implement any methods that are matched by the pointcut. To advise instances of Level2 you would need to change your pointcut to "execution(public * TestAccessModifiers.*())" giving these results:

execution(void TestAccessModifiers.printA())
A
execution(void Level3.printA())
Level3 protected
execution(void Level3.printA())
Level3 protected

Cheers

Matthew Webster
AOSD Project
Java Technology Centre, MP146
IBM Hursley Park, Winchester,  SO21 2JN, England
Telephone: +44 196 2816139 (external) 246139 (internal)
Email: Matthew Webster/UK/IBM @ IBMGB, matthew_webster@xxxxxxxxxx
http://w3.hursley.ibm.com/~websterm/



Kawtip Nippon <kawtip@xxxxxxxxx>
Sent by: aspectj-users-bounces@xxxxxxxxxxx

12/08/2006 16:54

Please respond to
aspectj-users@xxxxxxxxxxx

To
aspectj-users@xxxxxxxxxxx
cc
Subject
[aspectj-users] About AspectJ pointcut





Dear all,

    I'd like to ask about AspectJ pointcut. 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

 


Get your email and more, right on the new Yahoo.com _______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users


Back to the top