Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

DisjunctVarBinding.java 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. class A {
  2. void m() {
  3. System.out.println("A");
  4. }
  5. }
  6. class B extends A {
  7. void m() {
  8. System.out.println("B");
  9. }
  10. }
  11. aspect IfPointcut {
  12. after(A a, B b) returning:
  13. execution(* foo(*,*)) &&
  14. (args(b,a) || args(a,b)) {
  15. System.out.println("Woven");
  16. }
  17. }
  18. public class DisjunctVarBinding {
  19. public static void foo(A a, A b) {
  20. a.m();
  21. b.m();
  22. }
  23. public static void main(String[] args) {
  24. A a = new A();
  25. B b = new B();
  26. foo(b,a);
  27. }
  28. }
  29. /* Example to illustrate a problem with variable
  30. binding and (||) in pointcuts. When run, this program produces
  31. java.lang.ClassCastException immediately after
  32. the call to "foo".
  33. The reason is that the instance tests inherent
  34. in the pointcut are done separately from the
  35. variable binding.
  36. Decompiled, the code produced for the relevant call
  37. to "foo" is as follows:
  38. --------------------------------------------------
  39. DisjunctVarBinding.foo(r5, r4);
  40. label_0:
  41. {
  42. if (r5 instanceof B == false)
  43. {
  44. if (r4 instanceof B == false)
  45. {
  46. break label_0;
  47. }
  48. }
  49. IfPointcut.aspectOf().ajc$afterReturning$IfPointcut$26d(r5, (B) r4);
  50. }
  51. --------------------------------------------------
  52. It should however read something like this, using the instance
  53. tests to determine the appropriate variable binding
  54. --------------------------------------------------
  55. DisjunctVarBinding.foo(r5,r4);
  56. if (r4 instanceof B)
  57. IfPointcut.aspectOf().ajc$afterReturning$IfPointcut$26d(r5, (B)r4)
  58. else if (r5 instanceof A)
  59. IfPointcut.aspectOf().ajc$afterReturning$IfPointcut$26d(r4,(B)r5)
  60. --------------------------------------------------
  61. */