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 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. "initialization(C())-Ar-0",
  30. "execution(C.<init>)-Ar-0",
  31. "set(C.x)-Ar-0",
  32. "execution(C())-Ar-0",
  33. "execution(C.foo())-Ar-0",
  34. "set(C.x)-Ar-0",
  35. "set(C.x)-Ar-0",
  36. "initialization(C())-Art-0",
  37. "execution(C.<init>)-Art-1",
  38. "set(C.x)-Art-2",
  39. "execution(C())-Art-3",
  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. haves.add(jp.toShortString() + "-" + name + "-" + num);
  46. }
  47. static void checkAll() {
  48. Tester.checkEqual(haves, wants, "haves != wants");
  49. }
  50. }
  51. aspect Ar percflow(pc()){
  52. pointcut pc() : within(C) ;
  53. int count = 0;
  54. static boolean enable = false;
  55. before(): pc() {
  56. if ( enable ) {
  57. Post.post(thisJoinPoint, "Ar", count++);
  58. }
  59. }
  60. }
  61. /*
  62. * I'm trying to simulate eachcflowrootop.
  63. */
  64. aspect Art percflow(Art.pc() && !cflowbelow(Art.pc()))
  65. {
  66. pointcut pc() : within(C) ;
  67. //pointcut pctop(): pc() && !cflow(pc()); (see above)
  68. int count = 0;
  69. static boolean enable = false;
  70. before(): pc() {
  71. if ( enable ) {
  72. Post.post(thisJoinPoint, "Art", count++);
  73. }
  74. }
  75. }