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.

IndeterminateHandlerArg.java 3.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import org.aspectj.testing.Tester;
  2. import org.aspectj.lang.*;
  3. import org.aspectj.lang.reflect.*;
  4. /** @testcase PR#764 binding handler args with indeterminate prefix and suffix */
  5. public class IndeterminateHandlerArg {
  6. public static void main (String[] args) {
  7. Throwable throwable = new Throwable("throwable");
  8. Error error = new Error("error");
  9. RuntimeException runtime = new RuntimeException("runtime") {
  10. RuntimeException f() { return this; }
  11. }.f();
  12. try { throw error; }
  13. catch (Error e) { A.event(e.getMessage()); }
  14. try { throw throwable; }
  15. catch (Throwable e) { A.event(e.getMessage()); }
  16. try { throw error; }
  17. catch (Throwable e) { A.event(e.getMessage()); }
  18. try { throw runtime; }
  19. catch (Throwable e) { A.event(e.getMessage()); }
  20. try { throw runtime; }
  21. catch (RuntimeException e) { A.event(e.getMessage()); }
  22. Tester.checkEventsFromFile("IndeterminateHandlerArg.events");
  23. }
  24. }
  25. aspect A {
  26. void e(String label, JoinPoint jp) {
  27. e(label, jp, (Throwable) jp.getArgs()[0]);
  28. }
  29. void e(String label, JoinPoint jp, Throwable t) {
  30. String m = jp.toLongString()
  31. + ": " + t.getClass().getName()
  32. + " - " + t.getMessage()
  33. + " @ " + label;
  34. event(m);
  35. }
  36. static void event(String m) {
  37. Tester.event(m);
  38. }
  39. pointcut hd() : withincode(static void main(..)) && handler(*);
  40. before (Throwable t) : hd() && args(t) { e("before Throwable", thisJoinPoint, t); }
  41. before (Error t) : hd() && args(t) { e("before Error", thisJoinPoint, t); }
  42. before () : hd() && args(Throwable) { e("before args(Throwable)", thisJoinPoint); }
  43. before () : hd() && args(Error) { e("before args(Error)", thisJoinPoint); }
  44. before () : hd() && args(Throwable,..) { e("before args(Throwable,..)", thisJoinPoint); }
  45. before () : hd() && args(..,Throwable) { e("before args(..,Throwable)", thisJoinPoint); }
  46. before () : hd() && args(Error,..) { e("before args(Error,..)", thisJoinPoint); }
  47. before () : hd() && args(..,Error) { e("before args(..,Error)", thisJoinPoint); }
  48. before (Throwable t) : hd() && args(t,..) { e("before Throwable,..", thisJoinPoint, t); }
  49. before (Error t) : hd() && args(t,..) { e("before Error,..", thisJoinPoint, t); }
  50. before (Throwable t) : hd() && args(..,t) { e("before ..,Throwable", thisJoinPoint, t); }
  51. before (Error t) : hd() && args(..,t) { e("before ..,Error", thisJoinPoint, t); }
  52. before () : hd() && args(Throwable,*) { Tester.check(false, "args(Throwable,*)"); }
  53. before () : hd() && args(*,Throwable) { Tester.check(false, "args(*,Throwable)"); }
  54. before () : hd() && args(Error,*) { Tester.check(false, "args(Error,*)"); }
  55. before () : hd() && args(*,Error) { Tester.check(false, "args(*,Error)"); }
  56. before (Throwable t) : hd() && args(t,*) { Tester.check(false, "args((Throwable)t,*)"); }
  57. before (Error t) : hd() && args(t,*) { Tester.check(false, "args((Error)t,*)"); }
  58. before (Throwable t) : hd() && args(*,t) { Tester.check(false, "args(*,(Throwable)t)"); }
  59. before (Error t) : hd() && args(*,t) { Tester.check(false, "args(*,(Error)t)"); }
  60. }