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.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import org.aspectj.lang.annotation.*;
  2. import org.aspectj.lang.*;
  3. @Aspect
  4. public class Code3 {
  5. @Around(value = "args(s) && target(targeto) && call(* Foo.run1(String))")
  6. public void first(ProceedingJoinPoint proceedingJoinPoint, Foo targeto, String s) throws Throwable {
  7. System.out.println("first: binding target, just passing everything through: target=Foo(1)");
  8. proceedingJoinPoint.proceed(new Object[]{ targeto, s});
  9. }
  10. @Around(value = "args(s) && this(thiso) && target(targeto) && call(* run2(String))")
  11. public void second(ProceedingJoinPoint proceedingJoinPoint, Foo thiso, Foo targeto, String s) throws Throwable {
  12. System.out.println("second: binding this and target, just passing everything through: this=Foo(0) target=Foo(1)");
  13. proceedingJoinPoint.proceed(new Object[]{ thiso, targeto, s});
  14. }
  15. @Around(value = "args(s) && this(thiso) && call(* run3(String))")
  16. public void third(ProceedingJoinPoint proceedingJoinPoint, Foo thiso, String s) throws Throwable {
  17. System.out.println("third: binding this, just passing everything through: this=Foo(0)");
  18. proceedingJoinPoint.proceed(new Object[]{ thiso, s});
  19. }
  20. @Around(value = "args(s) && this(thiso) && call(* run4(String))")
  21. public void fourth(ProceedingJoinPoint proceedingJoinPoint, Foo thiso, String s) throws Throwable {
  22. System.out.println("fourth: binding this, switching from Foo(0) to Foo(3)");
  23. proceedingJoinPoint.proceed(new Object[]{ new Foo(3), s});
  24. }
  25. @Around(value = "args(s) && target(targeto) && call(* run5(String))")
  26. public void fifth(ProceedingJoinPoint proceedingJoinPoint, Foo targeto, String s) throws Throwable {
  27. System.out.println("fifth: binding target, switching from Foo(1) to Foo(4)");
  28. proceedingJoinPoint.proceed(new Object[]{ new Foo(4), s});
  29. }
  30. @Around(value = "args(s) && this(thiso) && target(targeto) && call(* run6(String))")
  31. public void sixth(ProceedingJoinPoint proceedingJoinPoint, Foo thiso, Foo targeto, String s) throws Throwable {
  32. System.out.println("sixth: binding this and target, switching them around (before this=Foo(0) target=Foo(1))");
  33. proceedingJoinPoint.proceed(new Object[]{ targeto, thiso, s});
  34. }
  35. public static void main(String []argv) {
  36. new Foo(0).execute1();
  37. new Foo(0).execute2();
  38. new Foo(0).execute3();
  39. new Foo(0).execute4();
  40. new Foo(0).execute5();
  41. new Foo(0).execute6();
  42. }
  43. }
  44. class Foo {
  45. int i;
  46. public Foo(int i) {
  47. this.i = i;
  48. }
  49. public void execute1() { new Foo(1).run1("abc"); }
  50. public void execute2() { new Foo(1).run2("abc"); }
  51. public void execute3() { new Foo(1).run3("abc"); }
  52. public void execute4() { new Foo(1).run4("abc"); }
  53. public void execute5() { new Foo(1).run5("abc"); }
  54. public void execute6() { new Foo(1).run6("abc"); }
  55. public void run1(String s) { System.out.println("Executing run("+s+") on "+this.toString()); }
  56. public void run2(String s) { System.out.println("Executing run("+s+") on "+this.toString()); }
  57. public void run3(String s) { System.out.println("Executing run("+s+") on "+this.toString()); }
  58. public void run4(String s) { System.out.println("Executing run("+s+") on "+this.toString()); }
  59. public void run5(String s) { System.out.println("Executing run("+s+") on "+this.toString()); }
  60. public void run6(String s) { System.out.println("Executing run("+s+") on "+this.toString()); }
  61. public String toString() {
  62. return ("Foo(i="+i+")");
  63. }
  64. }