While I'd argue that withincode is based on lexical structure, it's
certainly a little surprising the way that signature matching works for it
(i.e., lexically contained in any method that defines or overrides).

By the way, using within(Type) && withincode(* foo()) is simpler, but it
does exclude matches of ITD's where withincode(* Type.foo()) would match,
but within(Type) might well not!

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Linton Ye
Sent: Tuesday, July 11, 2006 11:43 AM
To: [email protected]
Subject: [aspectj-users] Re: withincode and overriden methods

thanks Ron and Matthew,

yes, that's indeed the solution based on the current semantics of 
withincode in AspectJ.

Just like what I understood "within" as opposed to "this", I tended to 
see "withincode" as opposed to "execution" in the same way, i.e. the 
former is just about the lexical structure and won't touch sub-classes, 
and the latter is about the code being executed and thus will match 
sub-classes.

But "picking out execution of implementing methods on an interface" is 
indeed a good use case of the current semantics of withincode.  Maybe we 
should say withincode is not purely lexical structure based?

Ron Bodkin wrote:
> Hi Linton,
> 
> I think it's important that withincode matches statically on signatures in
> the same way that execution and call do, i.e., based on the "declaring
> type". This leads to matches for overriding methods as you've observed,
> which I think was the right choice (e.g., it makes it easy to pick out
> execution of implementing methods on an interface). Regardless this is now
> the established semantics for AspectJ and I definitely think it shouldn't
> change.
> 
> However, for your requirement you could use:
> 
> withincode(void Foo.bar()) && !withincode(void (Foo+ && !Foo).bar()) 
> 
> to express the notion of within only the implementation of bar defined on
> Foo but not in overriding methods, without having to enumerate the
> subtypes...
> 
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of Linton Ye
> Sent: Monday, July 10, 2006 10:57 AM
> To: [email protected]
> Subject: [aspectj-users] withincode and overriden methods
> 
> Hi All,
> 
> Please see the following code, say, I would like to capture join points 
> inside the Foo.bar() method ONLY, not in any of the overridden versions.
> 
> However, only pointcut 3 works.  Pointcut 1 and 2 matches bar methods 
> defined in both Foo and SubFoo.
> 
> Compared to this, within pointcut works more like what I expected, as in 
> pointcut 4, within(Foo) only matches join points in class Foo, not in 
> any of its subclasses, e.g. SubFoo.
> 
> Since withincode and within are used to match join points based on the 
> lexical structure of the program, it seems more reasonable not to 
> implicitly include the subclasses.  To match subclasses, we can just use 
> withincode(void Foo+.bar()).
> 
> Any comments will be appreciated.
> 
> public class Withincode {
>       public static void main(String[] args) {
>               Foo f = new SubFoo();
>               f.bar();
>       }       
>       static void log(Object...objects) {
>               for(Object o:objects)
>                       System.out.print(o);
>               System.out.println();
>       }       
>       static class Foo {
>               public void bar() {
>                       log("Foo");
>               }
>       }       
>       static class SubFoo extends Foo {
>               public void bar() {
>                       log("SubFoo");
>               }
>       }       
>       static aspect SomeAspect {
>               // 1
>               before():withincode(void Foo.bar()){}
>               // 2
>               before():withincode(void (Foo && !SubFoo).bar()){}
>               // 3
>               before():!withincode(void SubFoo.bar())
>                       &&withincode(void Foo.bar()){}
>               // 4
>               before():within(Foo) {  }
>       }
> }
> 
> thanks,
> linton
> 
> _______________________________________________
> aspectj-users mailing list
> [email protected]
> https://dev.eclipse.org/mailman/listinfo/aspectj-users

_______________________________________________
aspectj-users mailing list
[email protected]
https://dev.eclipse.org/mailman/listinfo/aspectj-users


_______________________________________________
aspectj-users mailing list
[email protected]
https://dev.eclipse.org/mailman/listinfo/aspectj-users

Reply via email to