Skip to main content

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

Thanks again Ramnivas,
 
I'm not sure thats exacly what I need as I think it gives an aspect instance for each C.new call..
 
I suddenly had a flash of inspiration and remembered the Inner Aspect
 
 static aspect Inner {
 
 after() : call (C.new())
  {
  System.out.println("new C ");
  }
  }
 
And this appears to work as I'd like. :-)
 
Cheers
Neil
 
 
----- Original Message -----
From: "Ramnivas Laddad" <ramnivas@xxxxxxxxx>
To: <aspectj-users@xxxxxxxxxxx>
Sent: Monday, September 08, 2003 3:51 PM
Subject: Re: [aspectj-users] perthis Question

> Change your aspect declaration as follows:
>
> aspect MyAspect perthis (execution(Foo.new()) || execution(C.new(..))
>
> -Ramnivas
>
> --- neil loughran <
n.loughran@xxxxxxxxxxxxxxx> wrote:
> > Thanks Ramnivas,
> >
> > Can I somehow extend the perthis aspect to also capture the C.new
> > instances
> > made inside the aspect or am I completely off track here?
> >
> > Cheers
> > Neil
> > ----- Original Message -----
> > From: "Ramnivas Laddad" <
ramnivas@xxxxxxxxx>
> > To: <
aspectj-users@xxxxxxxxxxx>
> > Sent: Monday, September 08, 2003 3:15 PM
> > Subject: 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
> > > _______________________________________________
> > > aspectj-users mailing list
> > >
aspectj-users@xxxxxxxxxxx
> > > http://dev.eclipse.org/mailman/listinfo/aspectj-users
> >
> > _______________________________________________
> > aspectj-users mailing list
> >
aspectj-users@xxxxxxxxxxx
> > http://dev.eclipse.org/mailman/listinfo/aspectj-users
>
>
> __________________________________
> Do you Yahoo!?
> Yahoo! SiteBuilder - Free, easy-to-use web site design software
>
http://sitebuilder.yahoo.com
> _______________________________________________
> aspectj-users mailing list
>
aspectj-users@xxxxxxxxxxx
> http://dev.eclipse.org/mailman/listinfo/aspectj-users

Back to the top