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.

AroundVoid.java 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import org.aspectj.testing.Tester;
  2. public class AroundVoid {
  3. public static void main(String[] args) {
  4. C c = new C();
  5. try {
  6. c.m1();
  7. } catch (RuntimeException exc) {
  8. Tester.event("caught RuntimeException");
  9. }
  10. c.m2();
  11. c.m3(true);
  12. c.m4(true);
  13. try {
  14. c.m5();
  15. } catch (ArithmeticException exc) {
  16. Tester.event("caught ArithmeticException");
  17. }
  18. c.m6();
  19. //Tester.printEvents();
  20. Tester.checkEventsFromFile("AroundVoid.out");
  21. }
  22. }
  23. class C {
  24. void m1() {
  25. throw new RuntimeException("m1");
  26. }
  27. void m2() {
  28. Tester.event("m2");
  29. }
  30. void m3(boolean test) {
  31. if (test) {
  32. return;
  33. } else {
  34. return;
  35. }
  36. }
  37. void m4(boolean test) {
  38. if (test) {
  39. return;
  40. } else {
  41. Tester.event("false");
  42. }
  43. }
  44. void m5() {
  45. while (true) {
  46. int x = 0;
  47. int y = 2/x;
  48. throw new ArithmeticException();
  49. }
  50. }
  51. void m6() {}
  52. }
  53. aspect A {
  54. Object around(): execution(void C.m*(..)) {
  55. Tester.event(thisJoinPoint.toShortString());
  56. return proceed();
  57. }
  58. }