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.

StaticMethodsShouldNotReceiveInstanceofAdvice.java 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import org.aspectj.testing.*;
  2. import java.util.*;
  3. public class StaticMethodsShouldNotReceiveInstanceofAdvice {
  4. public static void main(String[] args) {
  5. ClassWithStaticMethods.staticMethod();
  6. Tester.checkAllEvents();
  7. }
  8. static {
  9. Tester.expectEventsInString("good0");
  10. }
  11. }
  12. class ClassWithStaticMethods {
  13. public static void staticMethod() {}
  14. }
  15. aspect PutsAdviceOnStaticMethods {
  16. static void bad(Object msg) { Tester.check(false, "Shouldn't have seen: " + msg); }
  17. static void good(String msg) { Tester.event(msg); }
  18. // These shouldn't run
  19. pointcut bad0(): this(ClassWithStaticMethods) && execution(void staticMethod());
  20. pointcut bad1(ClassWithStaticMethods c): this(c) && execution(void staticMethod());
  21. pointcut bad2(): target(ClassWithStaticMethods) && call(void staticMethod());
  22. pointcut bad3(ClassWithStaticMethods c): target(c) && call(void staticMethod());
  23. pointcut bad4(): target(*) && call(void ClassWithStaticMethods.staticMethod());
  24. pointcut bad5(ClassWithStaticMethods c): target(c) && call(void staticMethod());
  25. before(): bad0() { bad("bad0:" + thisJoinPoint); }
  26. before(ClassWithStaticMethods c): bad1(c) { bad("bad1:" + thisJoinPoint); }
  27. before(): bad2() { bad("bad2:" + thisJoinPoint); }
  28. before(ClassWithStaticMethods c): bad3(c) { bad("bad3:" + thisJoinPoint); }
  29. before(): bad4() { bad("bad4:" + thisJoinPoint); }
  30. before(ClassWithStaticMethods c): bad5(c) { bad("bad5:" + thisJoinPoint); }
  31. // This should run
  32. pointcut good0(): execution(void ClassWithStaticMethods.staticMethod());
  33. before(): good0() { good("good0"); }
  34. }