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.

pr119749.aj 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import java.lang.annotation.ElementType;
  2. import java.lang.annotation.Retention;
  3. import java.lang.annotation.RetentionPolicy;
  4. import java.lang.annotation.Target;
  5. import org.aspectj.lang.JoinPoint;
  6. public aspect pr119749 {
  7. // not inherited
  8. @Retention(RetentionPolicy.RUNTIME)
  9. @Target(ElementType.METHOD)
  10. @interface Me { String value() default "Me"; }
  11. static class C {
  12. @Me()
  13. void m() throws Exception {}
  14. }
  15. static class D extends C{
  16. void m() {}
  17. }
  18. static class E {
  19. D d(){return null;}
  20. C c(){return null;}
  21. static aspect A {
  22. declare warning: execution(C E.*()) : "C E.*()"; //L26
  23. declare warning: execution(D E.*()) : "D E.*()"; // L25
  24. }
  25. }
  26. public static void main(String[] args) {
  27. C c = new C();
  28. D d = new D();
  29. C cd = d;
  30. try {c.m();} catch (Exception e) {}
  31. try {cd.m();} catch (Exception e) {}
  32. d.m();
  33. }
  34. static aspect A {
  35. static void log(JoinPoint jp, Object o) {
  36. System.out.println("" + jp + ": " + o);
  37. }
  38. pointcut scope() : within(pr119749);
  39. pointcut execMe() :execution(@Me void m()) && scope(); // L17
  40. pointcut execEx() :execution(void m() throws Exception) && scope(); // L17
  41. pointcut execAnyEx() :execution(* *(..) throws Exception) && scope(); // L17
  42. pointcut callEx() :call(void m() throws Exception) && scope(); // L37,38
  43. declare warning : execMe() : "aa @Me void m()";
  44. declare warning : execEx() : "aa void m() throws Exception";
  45. declare warning : execAnyEx() : "aa * *(..) throws Exception";
  46. declare warning : callEx() : "aa call void m() throws Exception";
  47. before(Me me) : @annotation(me) && execMe() {
  48. log(thisJoinPoint, "execMe[" + me.value() + "]");
  49. }
  50. before() : execEx() {
  51. log(thisJoinPoint, "execEx");
  52. }
  53. }
  54. }