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.

AroundCalls.java 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import org.aspectj.testing.Tester;
  2. public class AroundCalls {
  3. public static void main(String[] args) { test(); }
  4. public static void test() {
  5. //Tester.checkEqual(new C().m(), "abc:2", "many arounds");
  6. Tester.checkEqual(new C().m(), "acb:2", "many arounds");
  7. }
  8. }
  9. class C {
  10. public String m() {
  11. return new D().m1("a", 0);
  12. }
  13. }
  14. class D {
  15. public String m1(String s, int x) { return s + ":" + x; }
  16. }
  17. aspect A {
  18. String around(D d, String as, int ax):
  19. call(String D.m1(String,int)) &&
  20. args(as,ax) &&
  21. target(d)
  22. //receptions(String d.m1(as, ax))
  23. {
  24. //System.out.println(as + " : " + d + " : " + ax);
  25. return proceed(d, as + "c", ax + 1);
  26. }
  27. String around(String as/*, C c1*/, D d1, int ax):
  28. within(C) &&
  29. target(d1) && call(String m1(String,int)) && args(as,ax)
  30. //instanceof(c1) && callsto(instanceof(d1) && receptions(String m1(as, ax)))
  31. {
  32. //System.out.println(as + " : " + c1 + " : " + d1 + " : " + ax);
  33. return proceed(as + "b", /*c1,*/ d1, ax + 1);
  34. }
  35. }