Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [aspectj-users] withincode and overriden methods


Linton,

Or perhaps:

                 // 5
                 before():withincode(void Foo.bar()) && within(Foo){}

Matthew Webster
AOSD Project
Java Technology Centre, MP146
IBM Hursley Park, Winchester,  SO21 2JN, England
Telephone: +44 196 2816139 (external) 246139 (internal)
Email: Matthew Webster/UK/IBM @ IBMGB, matthew_webster@xxxxxxxxxx
http://w3.hursley.ibm.com/~websterm/



"Ron Bodkin" <rbodkin@xxxxxxxxxxxxxx>
Sent by: aspectj-users-bounces@xxxxxxxxxxx

10/07/2006 20:16

Please respond to
aspectj-users@xxxxxxxxxxx

To
<aspectj-users@xxxxxxxxxxx>
cc
Subject
RE: [aspectj-users] withincode and overriden methods





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: aspectj-users-bounces@xxxxxxxxxxx
[mailto:aspectj-users-bounces@xxxxxxxxxxx] On Behalf Of Linton Ye
Sent: Monday, July 10, 2006 10:57 AM
To: aspectj-users@xxxxxxxxxxx
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
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users


_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users


Back to the top