選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

PR528.java 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import org.aspectj.testing.Tester;
  2. import org.aspectj.testing.Tester;
  3. /**
  4. * @testcase PR#528 10rc1 error in return type (verify error if -usejavac, compile error (missing return value) otherwise)
  5. * @testcase PR#528 10a1 unimplemented method if around advice/cflow on methods introduced by interface
  6. *
  7. * The !cflow(within(B)) winds up being the best test case so far for
  8. * the ExceptionInInitializer bug with null fields for cflow state
  9. *
  10. */
  11. public class PR528 {
  12. public static void main(String[] args) {
  13. C c = new C();
  14. c.trigger(); // toggled to true, do callback
  15. c.trigger(); // toggled to false, do trigger
  16. Tester.checkAllEvents();
  17. }
  18. static {
  19. Tester.expectEvent("test");
  20. Tester.expectEvent("test"); // called for each trigger
  21. Tester.expectEvent("callback");
  22. Tester.expectEvent("trigger");
  23. Tester.expectEvent("around 0");
  24. Tester.expectEvent("around 1");
  25. }
  26. }
  27. class C {
  28. }
  29. abstract aspect A {
  30. static boolean toggle;
  31. static int originalIndex;
  32. static int callbackIndex;
  33. static int aroundIndex;
  34. interface I {
  35. }
  36. public boolean I.test() {
  37. Tester.event("test");
  38. return (toggle = !toggle);
  39. }
  40. public void I.trigger() {
  41. Tester.event("trigger");
  42. Tester.check(0==originalIndex, "trigger called again: ");
  43. originalIndex++;
  44. }
  45. public void I.callback() {
  46. Tester.event("callback");
  47. Tester.check(0==callbackIndex, "callback called again: ");
  48. callbackIndex++;
  49. }
  50. declare parents: C implements I;
  51. }
  52. aspect B extends A {
  53. void around(I i)
  54. : target(i)
  55. && execution(public void I.trigger())
  56. && !cflow(within(B)) {
  57. Tester.event("around " + aroundIndex++);
  58. if(i.test()) {
  59. i.callback();
  60. } else {
  61. proceed(i);
  62. }
  63. }
  64. }