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.

CallsTo.java 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import org.aspectj.testing.Tester;
  2. public class CallsTo {
  3. public static void main(String[] args) {
  4. Tester.clearNotes();
  5. //System.out.println("cleared events");
  6. //Tester.printEvents();
  7. C c = new C();
  8. Tester.checkAndClear
  9. ("ca-newC",
  10. "new C");
  11. c.m("a");
  12. Tester.checkAndClear
  13. ("re-all re-C ca-all ca-C ",
  14. "c.m");
  15. c.m_C("b");
  16. Tester.checkAndClear
  17. ("re-all re-C ca-all ca-C ",
  18. "c.m_C");
  19. c = new SubC();
  20. Tester.checkAndClear
  21. ("ca-newC",
  22. "new SubC");
  23. c.m("c");
  24. Tester.checkAndClear
  25. ("re-all re-C re-SubC ca-all ca-C ca-SubC ca-inst(SubC)",
  26. "subc.m");
  27. c.m_C("d");
  28. Tester.checkAndClear
  29. ("re-all re-C re-SubC ca-all ca-C ca-SubC ca-inst(SubC)",
  30. "subc.m_C");
  31. SubC subC = new SubC();
  32. Tester.checkAndClear
  33. ("ca-newC",
  34. "new SubC");
  35. subC.m("e");
  36. Tester.checkAndClear
  37. ("re-all re-C re-SubC ca-all ca-C ca-SubC ca-inst(SubC)",
  38. "subc.m");
  39. subC.m_C("f");
  40. Tester.checkAndClear
  41. ("re-all re-C re-SubC ca-all ca-C ca-SubC ca-inst(SubC)",
  42. "subc.m_C");
  43. subC.m_SubC();
  44. Tester.checkAndClear
  45. ("re-all re-SubC ca-all ca-SubC",
  46. "subc.m_SubC");
  47. }
  48. }
  49. class C {
  50. public void m(String s1) {}
  51. public void m_C(String s2) {}
  52. }
  53. class SubC extends C {
  54. public void m(String s3) {}
  55. public void m_SubC() {}
  56. }
  57. aspect A {
  58. // pointcut allReceptions(): receptions(void *(..)) && instanceof(C);
  59. // pointcut receptionsInC(String s): receptions(void C.*(s));
  60. // pointcut receptionsInSubC(): receptions(void SubC.*(..));
  61. pointcut allcall(): call(void *(..)) && target(C+);
  62. pointcut callInC(String s): call(void C+.*(String)) && args(s);
  63. pointcut callInSubC(): call(void *(..)) && target(SubC);
  64. before(): allcall() { note("re-all"); }
  65. before(String s): callInC(s) { note("re-C"); }
  66. before(): callInSubC() { note("re-SubC"); }
  67. before(): allcall() { note("ca-all"); }
  68. before(String s): callInC(s) { note("ca-C"); }
  69. before(): callInSubC() { note("ca-SubC"); }
  70. before(): call(void C.*(..)) && target(SubC) { note("ca-inst(SubC)"); }
  71. // not implemented
  72. // before(OnSubC o): call(void C.*(..)) && (hasaspect(OnSubC) && target(o)) {
  73. // note("ca-asp(SubC)");
  74. // }
  75. before(): call(C+.new(..)) { note("ca-newC"); }
  76. private final static void note(String msg) {
  77. Tester.note(msg);
  78. }
  79. }
  80. aspect OnSubC /**of eachobject(instanceof(SubC))*/ {
  81. }