You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CFlowPoints.java 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import org.aspectj.testing.Tester;
  2. public class CFlowPoints {
  3. public static void main(String[] args){
  4. new Test().go(2);
  5. Tester.checkEqual(Test.callsPerCFlow, 2+1, "3 call for each cflow");
  6. Test.callsPerCFlow = 0;
  7. new Test().go(3);
  8. Tester.checkEqual(Test.callsPerCFlow, 3+2+1, "6 call for each cflow");
  9. try {
  10. Each.aspectOf();
  11. Tester.checkFailed("should have thrown exception");
  12. } catch (org.aspectj.lang.NoAspectBoundException exc) {
  13. // this is what we want
  14. }
  15. }
  16. }
  17. class Test {
  18. static int cflowObjects = 0;
  19. static int callsPerCFlow = 0;
  20. Object lastEachCFlow = null;
  21. void go(int n) {
  22. for (int i=0; i<n; i++) foo("i", "i");
  23. if (n >= 0) go(n-1);
  24. Tester.check(Each.aspectOf() != lastEachCFlow, "unique eachcflows");
  25. lastEachCFlow = Each.aspectOf();
  26. }
  27. void foo(String s1, String s2){}
  28. }
  29. aspect A {
  30. pointcut root(int x): target(Test) && call(void go(int)) && args(x);
  31. pointcut flow(int x): cflow(root(x));
  32. before(): root(int) && !cflow(root(int)) {
  33. Tester.checkEqual(Test.callsPerCFlow, 0, "top call");
  34. }
  35. before(String s1, int y, String s2):
  36. flow(y) && target(Test) && target(Object)
  37. && call(void *(String,String))
  38. && args(s1,s2)
  39. {
  40. Test.callsPerCFlow++;
  41. Tester.checkEqual(s1, s2, "extra parameters");
  42. }
  43. }
  44. aspect Each percflow(flowCut()) {
  45. pointcut flowCut(): target(Test) && call(void go(int));
  46. }