Steve, I know you've raised a related bugzilla, but thought I'd comment.
> I'm having a hard time matching the join point with the super... any thoughts? You aren't going crazy, at the moment super calls are not joinpoints (so not matchable by pointcuts). This is a deliberate thing (I can see the decision in the code) but the reasoning is lost in the midsts of time unfortunately! So compiling this: class Foo { public void m() { } } class Bar extends Foo { public void m2() { super.m(); m(); } } aspect X { before(): call(* *(..)) { } } The first call to m() from m2() will not match, the second one will. cheers, Andy On 2 December 2011 01:42, Frank Pavageau <frank.pavag...@gmail.com> wrote: > Hi Steve. > > On Fri, Dec 2, 2011 at 3:50 AM, Steve Ash <stevem...@gmail.com> wrote: >> I would like to create an aspect to declare an error if a particular method >> is called on the super from a subtype. Something like: >> >> public class SuperClass { >> public final void dontCallThisFromBase() { } >> } >> >> public class BaseClass extends SuperClass { >> public void doSomething() { >> super.dontCallThisFromBase(); // would love to be a compiler error >> } >> } > > Note that you don't need to use super here, since you're not > overriding the method. > >> public class UnrelatedClass { >> public void unrelatedMethod() { >> new SuperClass().dontCallThisFromBase(); // this is ok >> } >> } >> >> I'm having a hard time matching the join point with the super... any >> thoughts? Or should this work and I'm just doing something stupid? >> >> I first wanted to create a general @CantCallFromSubclass attribute that I >> could throw on the declaration of dontCallThisFromBase() -- but that doesn't >> seem to be possible... so plan B was just creating a specific aspect for >> this specific case.. but I'm running into trouble there too. > > For the specific case, I'd say something like > within(SuperClass+) && !within(SuperClass) && call(* > SuperClass.dontCallThisFromBase()) > > For a less specific case, you could use > within(SuperClass+) && !within(SuperClass) && > call(@CantCallFromSubclass * SuperClass.*()) > but you're still limited to the SuperClass hierarchy. > > If you want to be even more generic, you might be able to use an > abstract generic aspect (I've never used it though, and I'm not sure > it's compatible with within()), but you'd still need to explicitely > declare a concrete aspect for each hierarchy. > > Frank > _______________________________________________ > aspectj-users mailing list > aspectj-users@eclipse.org > https://dev.eclipse.org/mailman/listinfo/aspectj-users _______________________________________________ aspectj-users mailing list aspectj-users@eclipse.org https://dev.eclipse.org/mailman/listinfo/aspectj-users