Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] catching methods *not* calling a specific method?

Hi -

> Is it possible to have a static pointcut that would
> flag methods whose implementations do *not* call
> another, specified method? <snip>

No.  You can't pick out "missing" join points staticly with AspectJ.

Staticly, you can help an audit by detecting all the method-executions
that should call (your pointcut below) (or all the calls not 
within such methods, if it's only to be called from such methods:

  call (* MySuperClass+.wantedMethod()) 
    && !withincode(* MySuperClass+.someMethod*(..))

).

Dynamically, you can test and flag on returning from someMethod() 
if it never called wantedMethod(..):

// untested, but perhaps gives you the idea
// try also using percflow or around advice :)
aspect A { 
  pointcut callingMethod() : execution(* MySuperClass+.someMethod*(..));
  pointcut wantedCall() : call(* MySuperClass+.wantedMethod*(..))
     && withincode(* MySuperClass+.someMethod*(..));

  before() : callingMethod() { push(); }
  after() returning : wantedCall() { hit(); }
  after() returning : callingMethod() && if (!wasHit()) {
     throw new Error("failed to call ...");
  }
  after() : callingMethod() { pop(); }

  // implementation 
  static ThreadLocal flag = new ThreadLocal() {
     public Object initialValue() { return new Stack(); }
  };
  // these use ThreadLocal stack to push/pop boolean
  static void push() {..} // push Boolean.FALSE 
  static void hit() {..} // push Boolean.TRUE
  static void pop() {..}  // pop
  static boolean wasHit() {..} // peek, error if null
}

Hope this helps-
Wes


> ------------Original Message------------
> From: Razvan <razvan_peteanu@xxxxxxxxxx>
> To: aspectj-users@xxxxxxxxxxx
> Date: Wed, Nov-10-2004 11:36 AM
> Subject: [aspectj-users] catching methods *not* calling a specific method?
>
> Hello,
> 
> Is it possible to have a static pointcut that would
> flag methods whose implementations do *not* call
> another, specified method? Some akin to:
> 
> execution (* MySuperClass+.someMethod*(..)) && !(call
> (* MySuperClass+.wantedMethod()) );
> 
> (which doesn't work).
> 
> I'm not very sure it's possible, whether
> wantedMethod() is called depends on the program flow.
> In my case it's a linear flow (and no exceptions), but
> this is still a particular case of program flow.
> 
> Thanks,
> Razvan
> 
> PS (yeah, instead of checking the call, the better way
> would be to add an aspect making the call, but I
> cannot do that right now within my project's
> constraints).
> 
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> http://dev.eclipse.org/mailman/listinfo/aspectj-users
> 




Back to the top