您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

FormalMatching.java 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import org.aspectj.lang.*;
  2. import org.aspectj.testing.*;
  3. public class FormalMatching {
  4. public static void main(String[] args) {
  5. new FormalMatching().realMain(args);
  6. }
  7. public void realMain(String[] args) {
  8. call_v();
  9. call_vI(0);
  10. call_vII(0,1);
  11. call_i();
  12. call_iI(0);
  13. call_iII(0,1);
  14. Tester.checkAllEvents();
  15. }
  16. static String[] methods = {
  17. "call_v", "call_vI", "call_vII",
  18. "call_i", "call_iI", "call_iII",
  19. };
  20. static {
  21. for (int i = 0; i < methods.length; i++) {
  22. Tester.expectEvent(methods[i]);
  23. Tester.expectEvent(methods[i] + "-advice");
  24. }
  25. }
  26. void call_v () { Tester.event("call_v"); }
  27. void call_vI (int i0) { Tester.event("call_vI"); }
  28. void call_vII(int i0, int i1) { Tester.event("call_vII"); }
  29. int call_i () { Tester.event("call_i"); return 0; }
  30. int call_iI (int i0) { Tester.event("call_iI"); return 0; }
  31. int call_iII(int i0, int i1) { Tester.event("call_iII"); return 0; }
  32. }
  33. aspect Aspect {
  34. pointcut args0(Object o): call(* call*()) && target(o);
  35. pointcut args1(Object o, int i0): call(* call*(int)) && target(o) && args(i0);
  36. pointcut args2(Object o, int i0, int i1): call(* call*(int,int)) && target(o) && args(i0, i1);
  37. before(Object o): args0(o) { a(thisJoinPoint); }
  38. before(Object o, int i0): args1(o,i0) { a(thisJoinPoint); }
  39. before(Object o, int i0, int i1): args2(o,i0,i1) { a(thisJoinPoint); }
  40. static void a(JoinPoint jp) {
  41. Tester.event(jp.getSignature().getName() + "-advice");
  42. }
  43. }