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.

MultiDispatchCf.java 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import org.aspectj.testing.Tester;
  2. public class MultiDispatchCf {
  3. public static void main(String[] args) {
  4. C c = new C();
  5. Tester.event("**** exec ****");
  6. //MultiExec.enabled = true;
  7. run(new C());
  8. Tester.event("**** call ****");
  9. //MultiExec.enabled = false;
  10. //MultiCall.enabled = true;
  11. run(new C());
  12. Tester.event("**** both=call ****");
  13. //MultiExec.enabled = true;
  14. run(new C());
  15. Tester.printEvents();
  16. }
  17. static void run(C c) {
  18. Tester.event(c.doit("s1"));
  19. Tester.event(c.doit(new Integer(10)));
  20. Tester.event(c.doit(new Double(1.25)));
  21. Object o;
  22. o = "s2"; Tester.event(c.doit(o));
  23. o = new Integer(20); Tester.event(c.doit(o));
  24. o = new Double(2.25); Tester.event(c.doit(o));
  25. }
  26. }
  27. class C {
  28. String doit(Object o) {
  29. return "did-" + o.toString();
  30. }
  31. }
  32. aspect MultiCall {
  33. pointcut t1(String s): call(String C.doit(Object)) && args(s);
  34. String around(String s): t1(s) { return proceed(s); }
  35. String around(Object o): t1(o) { return proceed(o); }
  36. pointcut m(Object o): call(String C.doit(Object)) && args(o);
  37. String getPrefix() { return "call"; }
  38. String around(String s): m(s) { //ERR
  39. return getPrefix() + "-string-" + s;
  40. }
  41. String around(Integer i): m(i) { //ERR
  42. return getPrefix() + "-integer-" + i;
  43. }
  44. String around(Double d): m(d) { //ERR
  45. return getPrefix() + "-double-" + d;
  46. }
  47. }
  48. aspect MultiCreate {
  49. pointcut make(Object o): this(o) && execution(new(..));
  50. private interface I {}
  51. declare parents: C implements I;
  52. before(I i): make(i) { //ERR: doesn't match Object
  53. System.out.println("new I: " + i);
  54. }
  55. }