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.

Test3.java 969B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package test;
  2. import org.aspectj.lang.*;
  3. import org.aspectj.lang.reflect.*;
  4. public class Test3 {
  5. public static void main(String[] args) throws Exception {
  6. Test3 a = new Test3();
  7. a.foo(-3);
  8. }
  9. public void foo(int i) {
  10. this.x=i;
  11. }
  12. int x;
  13. }
  14. aspect Log {
  15. pointcut assign(Object newval, Object targ):
  16. set(* test..*) && args(newval) && target(targ);
  17. before(Object newval, Object targ): assign(newval,targ) {
  18. Signature sign = thisJoinPoint.getSignature();
  19. System.out.println(targ.toString() + "." + sign.getName() + ":=" + newval);
  20. }
  21. /*
  22. }
  23. // Different error message if you divide into two aspects
  24. aspect Tracing {
  25. */
  26. pointcut tracedCall():
  27. call(* test..*(..))/* && !within(Tracing)*/ && !within(Log);
  28. after() returning (Object o): tracedCall() {
  29. // Works if you comment out either of these two lines
  30. thisJoinPoint.getSignature();
  31. System.out.println(thisJoinPoint);
  32. }
  33. }