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.

PR353d.java 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. public class PR353d {
  2. public static void main(String[] args) {
  3. new PR353d().go();
  4. }
  5. void go() {
  6. System.out.println("\ni..."); I i = new I() { public void f(PR353d d) {} }; i.f(this);
  7. System.out.println("\na..."); A a = new A(); a.f(this);
  8. System.out.println("\nb..."); B b = new B(); b.f(this);
  9. System.out.println("\nc..."); C c = new C(); c.f(this);
  10. System.out.println("\nd..."); D d = new D(); d.f(this);
  11. System.out.println("\ne..."); E e = new E(); e.f(this);
  12. }
  13. }
  14. interface I {
  15. public void f(PR353d d);
  16. }
  17. class A {
  18. public void f(PR353d d) { System.out.println("A.f"); }
  19. }
  20. class B extends A {}
  21. class C extends A {
  22. public void f(PR353d d) { System.out.println("C.f"); }
  23. }
  24. class D extends A implements I {}
  25. class E extends A implements I {
  26. public void f(PR353d d) { System.out.println("E.f"); }
  27. }
  28. aspect Aspect {
  29. pointcut f(): receptions(* *(PR353d));
  30. pointcut all(): f();
  31. pointcut anoB(A a): f() && instanceof(a) && !instanceof(B);
  32. pointcut anoC(A a): f() && instanceof(a) && !instanceof(C);
  33. pointcut anoD(A a): f() && instanceof(a) && !instanceof(D);
  34. pointcut anoE(A a): f() && instanceof(a) && !instanceof(E);
  35. pointcut noA(): f() && !instanceof(A);
  36. pointcut noB(): f() && !instanceof(B);
  37. pointcut noC(): f() && !instanceof(C);
  38. pointcut noD(): f() && !instanceof(D);
  39. pointcut noE(): f() && !instanceof(E);
  40. static before(): all() { System.out.println("all: " + thisJoinPoint.className); }
  41. static before(): noA() { System.out.println("noA: " + thisJoinPoint.className); }
  42. static before(A a): anoB(a) { System.out.println("anoB: " + thisJoinPoint.className); }
  43. static before(A a): anoC(a) { System.out.println("anoC: " + thisJoinPoint.className); }
  44. static before(): noB() { System.out.println("noB: " + thisJoinPoint.className); }
  45. static before(): noC() { System.out.println("noC: " + thisJoinPoint.className); }
  46. static before(A a): anoD(a) { System.out.println("anoD: " + thisJoinPoint.className); }
  47. static before(A a): anoE(a) { System.out.println("anoE: " + thisJoinPoint.className); }
  48. static before(): noD() { System.out.println("noD: " + thisJoinPoint.className); }
  49. static before(): noE() { System.out.println("noE: " + thisJoinPoint.className); }
  50. }