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.

DeclareSoft.java 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import org.aspectj.testing.Tester;
  2. import java.io.*;
  3. import org.aspectj.lang.*;
  4. public class DeclareSoft {
  5. public static void main(String[] args) {
  6. new C().m1();
  7. try {
  8. new C().m2();
  9. } catch (SoftException se) {
  10. Tester.note("m2-soft");
  11. }
  12. try {
  13. new C().m3();
  14. } catch (SoftException se) {
  15. Tester.check(false, "already caught");
  16. }
  17. try {
  18. new C().throwIt();
  19. } catch (SoftException se) {
  20. Tester.note("throwIt-soft");
  21. } catch (Throwable t) {
  22. Tester.check(false, "should have been softened: " + t);
  23. }
  24. try {
  25. new C().pretendsToThrow();
  26. } catch (IOException ioe) {
  27. Tester.check(false, "bad IO");
  28. }
  29. Tester.check("m2-soft");
  30. Tester.check("around-m3");
  31. }
  32. }
  33. class C {
  34. public void throwIt() throws Throwable {
  35. throw makeThrowable();
  36. }
  37. public void pretendsToThrow() throws IOException, ClassNotFoundException {
  38. }
  39. private Throwable makeThrowable() {
  40. return new Exception("make me soft");
  41. }
  42. public void m1() {
  43. }
  44. public void m2() {
  45. new File("___hi").getCanonicalPath();
  46. new FileInputStream("___bye");
  47. }
  48. public void m3() {
  49. new FileInputStream("___bye");
  50. new File("___hi").getCanonicalPath();
  51. }
  52. }
  53. aspect B {
  54. declare soft: Exception: execution(* C.throwIt());
  55. declare soft: ClassNotFoundException: call(* C.pretendsToThrow());
  56. }
  57. aspect A {
  58. declare soft: IOException: execution(* C.*(..));
  59. void around(): execution(void C.m3()) {
  60. try {
  61. proceed();
  62. } catch (IOException ioe) {
  63. Tester.note("around-m3");
  64. }
  65. }
  66. }