Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

CounterTest05.java 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. public class CounterTest05 {
  2. /*
  3. * Here we have an abstract pointcut that is used within a cflow. In the two concrete sub-aspects
  4. * we make the abstract pointcut concrete. The aim of the test is to ensure we do not share
  5. * the cflow counter objects, since the pointcut within the cflow() in each case points at a
  6. * different 'entry' point. The count should be 10 when we finish. If it is 8 we have shared
  7. * a counter.
  8. */
  9. public static void main(String []argv) {
  10. print();
  11. print();
  12. below1();
  13. System.err.println("ctr="+A.ctr);
  14. if (A.ctr!=10)
  15. throw new RuntimeException("Counter should be 10 but is "+A.ctr);
  16. }
  17. public static void below1() {
  18. print();
  19. print();
  20. below2();
  21. }
  22. public static void below2() {
  23. print();
  24. print();
  25. }
  26. public static void print() {}
  27. }
  28. abstract aspect A {
  29. public static int ctr = 0;
  30. abstract pointcut abs();
  31. pointcut p(): call(* print(..)) && cflow(abs());
  32. before(): p() {
  33. A.ctr++;
  34. }
  35. }
  36. aspect B extends A {
  37. pointcut abs(): execution(* main(..)); // ctr increases by 6
  38. }
  39. aspect C extends A {
  40. pointcut abs(): execution(* below1(..)); // ctr increases by 4
  41. }