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.

Driver.java 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import org.aspectj.testing.Tester;
  2. // aspect inheritance and advice, introduction
  3. public class Driver {
  4. public static void test() {
  5. C1 c1 = new C1();
  6. Tester.checkEqual(c1.foo(), "from A2", "sub-aspects");
  7. Tester.checkEqual(c1.bar(),
  8. "from A0 #2",
  9. "sub-aspects and position");
  10. // the around advice lexically in A1 runs twice, once for each concrete
  11. // sub-aspects. putting advice on a concrete pointcut in an abstract
  12. // aspect will always have this odd behavior, and possibly should be illegal
  13. Tester.checkEqual(c1.getString(),
  14. ":A2:A1:A1:C1",
  15. "multiple arounds");
  16. }
  17. public static void main(String[] args) { test(); }
  18. }
  19. class C1 {
  20. String getString() {
  21. return ":C1";
  22. }
  23. }
  24. abstract aspect A1 {
  25. String C1.foo() {
  26. return "from A1";
  27. }
  28. String C1.bar() {
  29. return "from A1";
  30. }
  31. String around():
  32. call(String C1.getString()) {
  33. return ":A1" + proceed();
  34. }
  35. }
  36. aspect A2 extends A1 {
  37. String C1.foo() {
  38. return "from A2";
  39. }
  40. String around():
  41. call(String C1.getString()) {
  42. return ":A2" + proceed();
  43. }
  44. }
  45. aspect A0 extends A1 {
  46. // multiple conflicting declarations in the same aspect are now an error
  47. //String C1.bar() {
  48. // return "from A0 #1";
  49. //}
  50. String C1.bar() {
  51. return "from A0 #2";
  52. }
  53. }