[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aspectj-users] Inner classes query
|
Thanks Wes, I guess I'd better stick to convention then! ;-)
I was wondering why my pointcuts were not working and it was surprise to
see the trace but I guess thats another powerful part of AspectJ, the
ability to view the currently executing joinpoints. Really handy at times
especially when you're not 100% sure how to write the correct syntax.
----- Original Message -----
From: "Wes Isberg" <wes@xxxxxxxxxxxxxx>
To: <aspectj-users@xxxxxxxxxxx>
Sent: Monday, October 06, 2003 7:10 PM
Subject: Re: [aspectj-users] Inner classes query
> Isn't that just the convention for Java inner classes,
> to supply the enclosing instance as the first parameter?
>
> e.g., for
> class Outer {
> class Inner{}
> }
>
> the bytecode invocation would be to
>
> Outer$Inner."<init>":(LOuter;)V
>
> (There must be a VM/JLS entry on point.)
>
> Note that this affects the join point signature and pointcut
> matching. For example, this pointcut would not match:
>
> call(Outer.Inner.new())
>
> but this would:
>
> call(Outer.Inner.new(Outer))
>
> and if you print thisJoinPoint.getSignature(), it will
> show a parameter of type Outer.
>
> So: I think this is a case where AspectJ is doing the
> right thing in following the Java model, but that most
> Java developers don't realize there is an implicit
> argument for the enclosing instance, unless they have
> constructed instances of inner classes like this:
>
> Outer o = new Outer();
> Inner i = o.new Inner();
>
> I don't think we can or should omit the parameter,
> and emitting warnings would be hard. But we can
> document this, probably along with some of the
> other gotcha's with nested classes.
>
> Other solutions?
>
> Wes
>
> neil loughran wrote:
> > Why does the trace for the aspect Foo below show execution(Foo.Bar(Foo,
String)) when I was expecting Foo.Bar(String) ?
> >
> > When I move the inner class outside the aspect, I get the expected
behaviour execution(Bar(String))
> >
> > I'm sure I'm missing something :-)
> >
> > Thanks
> > Neil
> >
> >
> > aspect Foo
> > {
> >
> > after(String s) : args(s) && call(public void myMethod(String))
> > {
> > process(s);
> > }
> >
> >
> > public void process(String s)
> > {
> > Bar p = new Bar(s); // trace on this line of code
> > }
> >
> > class Bar
> > {
> > public Bar(String s)
> > {
> >
> > }
> > }
> > }
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> http://dev.eclipse.org/mailman/listinfo/aspectj-users