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.

HoldProceed.java 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import org.aspectj.testing.Tester;
  2. import java.util.*;
  3. public class HoldProceed {
  4. public static void main(String[] args) {
  5. C c = new C();
  6. c.m1(); c.m2(); c.m1();
  7. Tester.check("m");
  8. Tester.checkEqual(A.buf.toString(), "");
  9. A.runProceeds();
  10. Tester.checkEqual(A.buf.toString(), "m1:b:m2:m1:");
  11. A.runProceeds();
  12. Tester.checkEqual(A.buf.toString(), "m1:b:m2:m1:m1:b:m2:m1:");
  13. try {
  14. c.m3();
  15. } catch (Exception e) {
  16. Tester.check(false, "shouldn't throw anything");
  17. }
  18. try {
  19. A.runProceeds();
  20. } catch (Error err) { //??? this is an odd test for the fact that Exception is wrapped
  21. Tester.note("caught err");
  22. }
  23. Tester.check("caught err");
  24. }
  25. }
  26. class C {
  27. public void m1() {A. buf.append("m1:"); }
  28. public void m2() {A. buf.append("m2:"); }
  29. public void m3() throws Exception { throw new Exception("from m3"); }
  30. }
  31. aspect A {
  32. static StringBuffer buf = new StringBuffer();
  33. static List heldProceeds = new LinkedList();
  34. int cnt = 0;
  35. void around (): call(void C.m*()) {
  36. heldProceeds.add(new Runnable() { public void run() { proceed(); cnt++; } });
  37. class MyRun implements Runnable {
  38. public void run() { System.out.println("run"); }
  39. public void m() { Tester.note("m"); }
  40. }
  41. MyRun mr = new MyRun();
  42. mr.m();
  43. }
  44. before(): call(void C.m2()) {
  45. new Runnable() {
  46. public void run() { buf.append("b:"); }
  47. }.run();
  48. }
  49. public static void runProceeds() {
  50. for (Iterator i = heldProceeds.iterator(); i.hasNext(); ) {
  51. ((Runnable)i.next()).run();
  52. }
  53. }
  54. }