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.

CflowBelowTest.java 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import org.aspectj.testing.Tester;
  2. import java.util.*;
  3. /**
  4. * Inspired by aspect sandbox and submitted by Chris Dutchyn
  5. */
  6. public class CflowBelowTest {
  7. static final String[] expectedSteps = new String[] {
  8. "Num.fact(4) within Num.fact(5) within another Num.fact(6)",
  9. "Num.fact(3) within Num.fact(4) within another Num.fact(5)",
  10. "Num.fact(2) within Num.fact(3) within another Num.fact(4)",
  11. "Num.fact(1) within Num.fact(2) within another Num.fact(3)",
  12. };
  13. static List steps = new ArrayList();
  14. static public void main( String[] args ) {
  15. Tester.checkEqual(new Num().fact(6), 720);
  16. Tester.checkEqual(steps.toArray(), expectedSteps, "steps");
  17. }
  18. }
  19. class Num {
  20. int fact(int x) {
  21. if (x == 1)
  22. return 1;
  23. return x * fact(x - 1);
  24. }
  25. }
  26. // check that cflows of nested calls obtain correct parameters
  27. aspect CflowBelow01 {
  28. before (int x1, int x2, int x3) :
  29. call(int Num.fact(int)) && args(x1)
  30. && cflowbelow(call(int Num.fact(int)) && args(x2)
  31. && cflowbelow(call(int Num.fact(int)) && args(x3))) {
  32. CflowBelowTest.steps.add("Num.fact(" + x1 +
  33. ") within Num.fact(" + x2 +
  34. ") within another Num.fact(" + x3 + ")");
  35. }
  36. }