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.

BackdoorMethods.java 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import org.aspectj.testing.Tester;
  2. import org.aspectj.testing.Tester;
  3. public class BackdoorMethods {
  4. public static void main(String[] args) {
  5. new BackdoorMethods().realMain(args);
  6. }
  7. public void realMain(String[] args) {
  8. new _A().a();
  9. new _B().a();
  10. new _C().a();
  11. new _D().a();
  12. Tester.checkAllEvents();
  13. }
  14. static {
  15. for (char c = 'A'; c <= 'D'; c++) {
  16. String n = "_"+c+".";
  17. Tester.expectEvent(n+"a");
  18. if (c != 'D') Tester.expectEvent(n+"f");
  19. Tester.expectEvent(n+"g");
  20. Tester.expectEvent("before."+n+"a");
  21. if (c != 'D') Tester.expectEvent("before."+n+"g");
  22. }
  23. }
  24. }
  25. class O {
  26. public void a() { Tester.event(n("a")); }
  27. protected String n() { return getClass().getName() + "."; }
  28. protected String n(Object s) { return n() + s; }
  29. }
  30. class A extends O { public void f() { Tester.event(n("f")); } }
  31. class B extends O { void f() { Tester.event(n("f")); } }
  32. class C extends O { protected void f() { Tester.event(n("f")); } }
  33. class D extends O { private void f() { Tester.event(n("f")); } }
  34. class _A extends O { public void g() { Tester.event(n("g")); } }
  35. class _B extends O { void g() { Tester.event(n("g")); } }
  36. class _C extends O { protected void g() { Tester.event(n("g")); } }
  37. class _D extends O { private void g() { Tester.event(n("g")); } }
  38. privileged aspect Aspect {
  39. declare parents: _A extends A;
  40. declare parents: _B extends B;
  41. declare parents: _C extends C;
  42. declare parents: _D extends D;
  43. before(_A o): target(o) && call(void g()) { o.f(); n(o,"g"); }
  44. before(_B o): target(o) && call(void g()) { o.f(); n(o,"g"); }
  45. before(_C o): target(o) && call(void g()) { o.f(); n(o,"g"); }
  46. before(_A o): target(o) && call(void a()) { o.g(); n(o,"a"); }
  47. before(_B o): target(o) && call(void a()) { o.g(); n(o,"a"); }
  48. before(_C o): target(o) && call(void a()) { o.g(); n(o,"a"); }
  49. before(_D o): target(o) && call(void a()) { o.g(); n(o,"a"); }
  50. private static void n(Object o, String m) {
  51. Tester.event("before." + o.getClass().getName() + "." + m);
  52. }
  53. }