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.

A7.java 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Bind the this on a call and change it with proceed... makes no difference
  2. import org.aspectj.lang.ProceedingJoinPoint;
  3. import org.aspectj.lang.annotation.*;
  4. @Aspect
  5. public class A7 {
  6. N newN = new N();
  7. @Around("call(void M.method(String)) && args(p) && this(t)")
  8. public void a( ProceedingJoinPoint pjp, N t,String p) throws Throwable {
  9. System.err.println("advice from ataj aspect");
  10. pjp.proceed(new Object[]{newN,"faked"});
  11. }
  12. public static void main(String []argv) {
  13. N.main(argv);
  14. }
  15. }
  16. class N {
  17. public static void main( String[] args ) {
  18. N n = new N();
  19. n.methodCaller("real");
  20. }
  21. public void methodCaller(String param) {
  22. M m = new M("1");
  23. m.method(param);
  24. }
  25. }
  26. class M {
  27. String prefix;
  28. public M(String prefix) { this.prefix = prefix; }
  29. public void method(String s) { System.err.println(prefix+s); }
  30. }
  31. /*
  32. class M {
  33. String prefix;
  34. public M(String prefix) { this.prefix = prefix; }
  35. public static void main( String[] args ) {
  36. M m = new M("1");
  37. m.methodCaller("real");
  38. }
  39. public void methodCaller(String param) {
  40. method(param);
  41. }
  42. public void method(String s) { System.err.println(prefix+s); }
  43. }
  44. */