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.

Binkley2.java 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import java.util.*;
  2. import org.aspectj.lang.*;
  3. import org.aspectj.lang.reflect.*;
  4. import org.aspectj.testing.*;
  5. public class Binkley2 {
  6. public static void main(String[] args) {
  7. // catch the static init early
  8. C c = new C();
  9. Art.enable = true;
  10. Ar.enable = false;
  11. new C().foo();
  12. Art.enable = false;
  13. Ar.enable = true;
  14. new C().foo();
  15. Post.checkAll();
  16. }
  17. }
  18. class C {
  19. public int x = 0;
  20. public void foo()
  21. {
  22. x = 1;
  23. x = 2;
  24. }
  25. }
  26. class Post {
  27. static List haves = new Vector();
  28. static String[] wants = new String[] {
  29. "preinitialization(C())-Ar-0",
  30. "initialization(C())-Ar-0",
  31. "execution(C())-Ar-0",
  32. "set(C.x)-Ar-0",
  33. "execution(C.foo())-Ar-0",
  34. "set(C.x)-Ar-0",
  35. "set(C.x)-Ar-0",
  36. "preinitialization(C())-Art-0",
  37. "initialization(C())-Art-0",
  38. "execution(C())-Art-1",
  39. "set(C.x)-Art-2",
  40. "execution(C.foo())-Art-0",
  41. "set(C.x)-Art-1",
  42. "set(C.x)-Art-2",
  43. };
  44. static void post(JoinPoint jp, String name, int num) {
  45. //System.out.println("have: " + jp.toShortString() + "-" + name + "-" + num);
  46. haves.add(jp.toShortString() + "-" + name + "-" + num);
  47. }
  48. static void checkAll() {
  49. Tester.checkEqual(haves, wants, "haves != wants");
  50. }
  51. }
  52. aspect Ar percflow(pc()){
  53. pointcut pc() : within(C) ;
  54. int count = 0;
  55. static boolean enable = false;
  56. before(): pc() {
  57. if ( enable ) {
  58. Post.post(thisJoinPoint, "Ar", count++);
  59. }
  60. }
  61. }
  62. /*
  63. * I'm trying to simulate eachcflowrootop.
  64. */
  65. aspect Art percflow(Art.pc() && !cflowbelow(Art.pc()))
  66. {
  67. pointcut pc() : within(C) ;
  68. //pointcut pctop(): pc() && !cflow(pc()); (see above)
  69. int count = 0;
  70. static boolean enable = false;
  71. before(): pc() {
  72. if ( enable ) {
  73. Post.post(thisJoinPoint, "Art", count++);
  74. }
  75. }
  76. }