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.

CallNotTarget.java 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import org.aspectj.testing.*;
  2. /** @testcase PR#661 !target with second advice on casted call */
  3. public class CallNotTarget {
  4. public static void main (String args []) {
  5. //new B().go(); // remove cast to avoid bug
  6. ((I) new B()).go();
  7. Tester.checkAllEvents();
  8. doit(new B());
  9. doit(new A());
  10. }
  11. static {
  12. Tester.expectEvent("A.before");
  13. Tester.expectEvent("A.before-not");
  14. Tester.expectEvent("Aspect.before-not");
  15. Tester.expectEvent("go");
  16. }
  17. static void doit(I i) {
  18. Tester.check(i != null, "null i");
  19. //System.out.println(i);
  20. }
  21. }
  22. interface I { public void go (); }
  23. class A implements I {
  24. public void go () { Tester.check(false, "A"); }
  25. }
  26. class B implements I {
  27. public void go () { Tester.event("go"); }
  28. }
  29. aspect Aspect {
  30. pointcut pc() : call(void I.go()); // same result if pointcut not named
  31. before () : pc() { // remove this advice to avoid bug
  32. Tester.event("A.before");
  33. }
  34. before () : pc() && !target (A) { // change to !target(String) to avoid bug
  35. Tester.event("A.before-not");
  36. }
  37. before () : pc() && !target (Aspect) { // change to !target(String) to avoid bug
  38. Tester.event("Aspect.before-not");
  39. }
  40. // before(): call(void doit(I)) && !args(A) {
  41. // System.out.println("doit !A");
  42. // }
  43. }