Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] perthis Question

This has to do with "implicit limiting of join points"
for per- aspects. In case of perthis()  aspect, the adivce
in the aspect will limit the join points captured to where 
'this' matches the one specified in perthis() association
specification.

In you example, it means it will match only join points
where 'this instanceof Foo' is true. 

-Ramnivas

--- neil loughran <n.loughran@xxxxxxxxxxxxxxx> wrote:
> Hello,
> 
> I'm having problems using the perthis construct.
> 
> The code below shows how an aspect "MyAspect" can be associated with
> each Foo object.
> 
> However, the after advice relating to calls of C.new don't appear to
> work.  
> 
> Yet remove the perthis construct and it works correctly.. 
> 
> Can anyone tell me what the reason is behind this behaviour?
> 
> Thanks
> Neil 
> 
> 
> 
> class A
>  {
>   
>  public static void main(String args[])
>  {
>   Foo a=new Foo();  
>   Foo b=new Foo();    
>   }
>  }
> 
> 
>  
> class Foo
>  {
>  public Foo() 
>   { 
>   new Bar("Hello"); 
>   } 
>  }
> 
>  
> class Bar
>  {
>  public Bar(String s)
>   {
>   System.out.println(s);
>   }
>  }
> 
>  
> aspect MyAspect perthis (execution(Foo.new()))
>  {
>  private int count = 0;
>  after(String s) : args(s) && call(Bar.new(String))
>   {
>   System.out.println("new Bar "+count);
>   count++;
>   new C();
>   }
>  
>  after() : call (C.new())
>   {
>   System.out.println("new C ");
>   }
>  }
> 
> class C
>  {
>  public void methodC()
>   {
>   System.out.println("C");
>   }
>  }


=====
Ramnivas Laddad
Author, AspectJ in Action
http://www.manning.com/laddad
http://www.amazon.com/exec/obidos/ASIN/1930110936

__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com


Back to the top