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.

AbstractCflows.java 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import org.aspectj.testing.Tester;
  2. public class AbstractCflows {
  3. public static void main(String[] args) {
  4. C c = new C();
  5. c.enter(1, 2);
  6. c.enter1(3);
  7. Tester.checkEvents(expected);
  8. }
  9. private static final String[] expected = {
  10. "enter(1, 2)",
  11. "CflowX: call(void C.body()); i = 1",
  12. "CflowY: call(void C.body()); i = 2",
  13. "PerCflowX: call(void C.body())",
  14. "PerCflowY: call(void C.body())",
  15. "BODY",
  16. "CflowX: call(void C.body()); i = 1",
  17. "CflowY: call(void C.body()); i = 2",
  18. "PerCflowX: call(void C.body())",
  19. "PerCflowY: call(void C.body())",
  20. "BODY",
  21. "enter1(3)",
  22. "Cflow3: call(void C.body()); i = 3",
  23. "PerCflow3: call(void C.body())",
  24. "BODY",
  25. };
  26. }
  27. class C {
  28. public void enter(int x, int y) {
  29. Tester.event("enter(" + x + ", " + y + ")");
  30. body();
  31. body();
  32. }
  33. public void enter1(int i) {
  34. Tester.event("enter1(" + i + ")");
  35. body();
  36. }
  37. public void body() {
  38. Tester.event("BODY");
  39. }
  40. }
  41. abstract aspect CflowBase {
  42. abstract pointcut entry(int i);
  43. pointcut flow(int x): cflow(entry(x));
  44. pointcut body(): call(* body());
  45. before(int i): body() && flow(i) {
  46. Tester.event(this.getClass().getName() + ": " + thisJoinPoint + "; i = " + i);
  47. }
  48. }
  49. aspect CflowY extends CflowBase {
  50. pointcut entry(int y): args(*, y) && call(void enter(int, int));
  51. }
  52. aspect CflowX extends CflowBase {
  53. pointcut entry(int x): args(x, *) && call(void enter(int, int));
  54. }
  55. aspect Cflow3 extends CflowBase {
  56. pointcut entry(int i): args(i) && call(void enter1(int));
  57. }
  58. abstract aspect PerCflowBase percflow(entry(int)) {
  59. abstract pointcut entry(int i);
  60. pointcut body(): call(* body());
  61. before(): body() {
  62. Tester.event(this.getClass().getName() + ": " + thisJoinPoint);
  63. }
  64. }
  65. aspect PerCflowY extends PerCflowBase {
  66. pointcut entry(int y): args(*, y) && call(void enter(int, int));
  67. }
  68. aspect PerCflowX extends PerCflowBase {
  69. pointcut entry(int x): args(x, *) && call(void enter(int, int));
  70. }
  71. aspect PerCflow3 extends PerCflowBase {
  72. pointcut entry(int i): args(i) && call(void enter1(int));
  73. }