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.

AroundAll.java 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. import java.util.*;
  2. import org.aspectj.testing.Tester;
  3. public class AroundAll {
  4. public static void main(String[] args) {
  5. new C();
  6. new C("9");
  7. //A.printLog();
  8. A.checkLog();
  9. }
  10. }
  11. class C extends SuperC {
  12. static final int i;
  13. final int x;
  14. int y = 42;
  15. static {
  16. i = 23;
  17. }
  18. C(String s) {
  19. this(Integer.valueOf(s).intValue());
  20. A.log("C(" + s + ")");
  21. A.log("y = " + y);
  22. }
  23. C(int i) {
  24. super(i);
  25. x = i;
  26. i = i+1;
  27. //System.out.println(i + 1);
  28. A.log("x = " + x);
  29. }
  30. C() {
  31. this("2");
  32. A.log("C()");
  33. }
  34. }
  35. class SuperC {
  36. SuperC(int x) {
  37. A.log("SuperC(" + x + ")");
  38. }
  39. }
  40. aspect A {
  41. static String[] expectedSteps = new String[] {
  42. "enter staticinitialization(AroundAll.<clinit>)",
  43. "exit staticinitialization(AroundAll.<clinit>)",
  44. "enter execution(void AroundAll.main(String[]))",
  45. "enter call(C())",
  46. "enter staticinitialization(SuperC.<clinit>)",
  47. "exit staticinitialization(SuperC.<clinit>)",
  48. "enter staticinitialization(C.<clinit>)",
  49. "enter set(int C.i)",
  50. "exit set(int C.i)",
  51. "exit staticinitialization(C.<clinit>)",
  52. "enter call(Integer java.lang.Integer.valueOf(String))",
  53. "exit call(Integer java.lang.Integer.valueOf(String))",
  54. "enter call(int java.lang.Integer.intValue())",
  55. "exit call(int java.lang.Integer.intValue())",
  56. "enter initialization(SuperC(int))",
  57. "enter execution(SuperC.<init>)",
  58. "exit execution(SuperC.<init>)",
  59. "enter execution(SuperC(int))",
  60. "SuperC(2)",
  61. "exit execution(SuperC(int))",
  62. "exit initialization(SuperC(int))",
  63. "enter initialization(C())",
  64. "enter execution(C.<init>)",
  65. "enter set(int C.y)",
  66. "exit set(int C.y)",
  67. "exit execution(C.<init>)",
  68. "enter execution(C(int))",
  69. "enter set(int C.x)",
  70. "exit set(int C.x)",
  71. "enter get(int C.x)",
  72. "exit get(int C.x)",
  73. "x = 2",
  74. "exit execution(C(int))",
  75. "enter execution(C(String))",
  76. "C(2)",
  77. "enter get(int C.y)",
  78. "exit get(int C.y)",
  79. "y = 42",
  80. "exit execution(C(String))",
  81. "exit initialization(C())",
  82. "enter execution(C())",
  83. "C()",
  84. "exit execution(C())",
  85. "exit call(C())",
  86. "enter call(C(String))",
  87. "enter call(Integer java.lang.Integer.valueOf(String))",
  88. "exit call(Integer java.lang.Integer.valueOf(String))",
  89. "enter call(int java.lang.Integer.intValue())",
  90. "exit call(int java.lang.Integer.intValue())",
  91. "enter initialization(SuperC(int))",
  92. "enter execution(SuperC.<init>)",
  93. "exit execution(SuperC.<init>)",
  94. "enter execution(SuperC(int))",
  95. "SuperC(9)",
  96. "exit execution(SuperC(int))",
  97. "exit initialization(SuperC(int))",
  98. "C.new(9)",
  99. "enter initialization(C(String))",
  100. "enter execution(C.<init>)",
  101. "enter set(int C.y)",
  102. "exit set(int C.y)",
  103. "exit execution(C.<init>)",
  104. "enter execution(C(int))",
  105. "enter set(int C.x)",
  106. "exit set(int C.x)",
  107. "enter get(int C.x)",
  108. "exit get(int C.x)",
  109. "x = 9",
  110. "exit execution(C(int))",
  111. "enter execution(C(String))",
  112. "C(91)",
  113. "enter get(int C.y)",
  114. "exit get(int C.y)",
  115. "y = 42",
  116. "exit execution(C(String))",
  117. "exit initialization(C(String))",
  118. "exit call(C(String))",
  119. };
  120. static List logList = new ArrayList();
  121. static void printLog() {
  122. for (Iterator i = logList.iterator(); i.hasNext(); ) {
  123. System.out.println(" \"" + i.next() + "\", ");
  124. }
  125. }
  126. static void checkLog() {
  127. Tester.checkEqual(expectedSteps, A.logList.toArray(), "steps");
  128. Tester.checkEqual(A.logList, expectedSteps, "steps");
  129. }
  130. static void log(String s) {
  131. logList.add(s);
  132. }
  133. static boolean test() { return true; }
  134. // one minimal version
  135. // before(): this(Runnable) && call(* intValue()) {
  136. //
  137. // }
  138. // void around(String s): initialization(C.new(String)) && args(s) && if(s.equals("9")) {
  139. // log("C.new(9)");
  140. // proceed(s+"1");
  141. // }
  142. Object around(): //initialization(C.new(String)) {
  143. if(test()) && !within(A) && !call(* A.*(..)) && !initialization(new(..)) && !preinitialization(new(..)) {
  144. A.log("enter " + thisJoinPoint);
  145. Object ret = proceed();
  146. A.log("exit " + thisJoinPoint);
  147. //proceed();
  148. //System.err.println("run twice");
  149. return ret;
  150. }
  151. }