Skip to main content

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

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");
  }
 }

Back to the top