Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] How to?


Because cflow() and cflowbelow() take a pointcut, you can expose the context with the this(), target() and args() pointcuts:

public aspect Analizer {
 pointcut testsFlow(Object testCase) :
     call(* MyClass.myMethod(..)) &&
     cflow(execution (* junit.framework.TestCase+.test*()) && this(testCase));
 
 before(Object testCase) : testsFlow(testCase) {
   System.out.println(testCase); // not working, must print "testM"...
 }

}


I don't have an example in front of me unfortunately, but I think that's close.

cheers,
-adrian.
--
Adrian Powell
Centre for IBM e-Business Innovation :: Vancouver
apowell@xxxxxxxxxx / 604-297-3194



André Dantas Rocha <ad-rocha@xxxxxxxxxx>
Sent by: aspectj-users-admin@xxxxxxxxxxx

11/13/2004 08:57 PM

Please respond to
aspectj-users

To
<aspectj-users@xxxxxxxxxxx>
cc
Subject
[aspectj-users] How to?





Hi,
 
I'd like to print the TestCase name from witch myMethod is called (not directly, but in the TestCase control-flow).
Is it possible via pointcut declaration? my code is shown below...
 
public class MyClass {
  void xx() { myMethod(); }
  void myMethod() {...}
}
 
public void testM() {
  new MyClass().xx();
}
 
public aspect Analizer {
 pointcut testsFlow() :
     call(* MyClass.myMethod(..)) &&
     cflow(execution (* junit.framework.TestCase+.test*()));
 
 before() : testsFlow() {
   System.out.println(thisJoinPoint); // not working, must print "testM"...
 }

}
 
Thanks,
 
André

Back to the top