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.

AroundCallsArgs.java 992B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import org.aspectj.testing.Tester;
  2. public class AroundCallsArgs {
  3. public static void main(String[] args) {
  4. new CL().go();
  5. //Tester.checkEqual(A.data, "CL:CP(hello)");
  6. Tester.checkEqual(A.data, "CP(hello)");
  7. }
  8. }
  9. aspect A /*of eachobject(instanceof(CL))*/ {
  10. public static String data = "";
  11. //pointcut parseCalls(CL cl, CP cp, String cmd):
  12. pointcut parseCalls(CP cp, String cmd):
  13. //calls(void cp1.parse(cmd1)) && within(cl1);
  14. (target(cp) && args(cmd) && call(void CP.parse(String))) &&
  15. within(CL);
  16. //void around(CL cl, CP cp, String cmd):
  17. void around(CP cp, String cmd):
  18. //parseCalls(cl, cp, cmd) {
  19. parseCalls(cp, cmd) {
  20. //data = cl.getClass().getName()+":"+cp.getClass().getName()+"("+cmd+")";
  21. data = cp.getClass().getName()+"("+cmd+")";
  22. //proceed(cl, cp, cmd);
  23. proceed(cp, cmd);
  24. }
  25. }
  26. class CL {
  27. void go() {
  28. new CP().parse("hello");
  29. }
  30. }
  31. class CP {
  32. void parse(String cmd) {
  33. }
  34. }