[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[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