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.

Aspect.java 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. /* This file is part of the compiler and core tools for the AspectJ(tm)
  2. * programming language; see http://aspectj.org
  3. *
  4. * The contents of this file are subject to the Mozilla Public License
  5. * Version 1.1 (the "License"); you may not use this file except in
  6. * compliance with the License. You may obtain a copy of the License at
  7. * either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/.
  8. *
  9. * Software distributed under the License is distributed on an "AS IS" basis,
  10. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11. * for the specific language governing rights and limitations under the
  12. * License.
  13. *
  14. * The Original Code is AspectJ.
  15. *
  16. * The Initial Developer of the Original Code is Palo Alto Research Center,
  17. * Incorporated (PARC). Portions created by PARC are are
  18. * Copyright (C) 2002 Palo Alto Research Center, Incorporated.
  19. * All Rights Reserved.
  20. *
  21. * Contributor(s):
  22. */
  23. package org.aspectj.weaver.test;
  24. import java.util.*;
  25. import org.aspectj.runtime.internal.*;
  26. import org.aspectj.runtime.internal.AroundClosure;
  27. import org.aspectj.lang.JoinPoint;
  28. public class Aspect {
  29. public static void ajc_before_0() {
  30. System.out.println("before_0");
  31. }
  32. public static void ajc_before_0(String s) {
  33. System.out.println("before_0: " + s);
  34. }
  35. public static boolean ajc_around_0(ArrayList s, AroundClosure c) throws Throwable {
  36. System.out.println("doing around, got " + s);
  37. Object ret = c.run(new Object[] {s}); // proceed(s)
  38. return ((Boolean) ret).booleanValue();
  39. }
  40. public static void ajc_before_0(java.util.ArrayList list) {
  41. System.out.println("before_0: " + list);
  42. }
  43. public static void ajc_before_method_execution() {
  44. }
  45. public static void ajc_before_method_execution(Object o) {
  46. System.out.println("before_method_execution: " + o);
  47. }
  48. public static void ajc_after_method_execution() {
  49. System.out.println("after_method_execution");
  50. }
  51. public static void ajc_after_method_execution(Object o) {
  52. System.out.println("after_method_execution: " + o);
  53. }
  54. public static void ajc_afterReturning_method_execution() {
  55. System.out.println("ajc_afterReturning_method_execution");
  56. }
  57. public static void ajc_afterReturning_method_execution(Object o) {
  58. System.out.println("afterReturning_method_execution: " + o);
  59. }
  60. public static void ajc_afterThrowing_method_execution() {
  61. System.out.println("ajc_afterThrowing_method_execution");
  62. }
  63. public static void ajc_afterThrowing_method_execution(Object o) {
  64. System.out.println("afterThrowing_method_execution: " + o);
  65. }
  66. public static Object ajc_around(AroundClosure closure) throws Throwable {
  67. Object ret = closure.run(new Object[] {});
  68. return ret;
  69. }
  70. public static Object ajc_around(AroundClosure closure, JoinPoint tjp) throws Throwable {
  71. System.out.println("thisJoinPoint: " + tjp);
  72. Object ret = closure.run(new Object[] {});
  73. return ret;
  74. }
  75. // ---
  76. public static void ajc_before_method_call() {
  77. System.out.println("before_method_call");
  78. }
  79. public static void ajc_before_method_call(Object o) {
  80. System.out.println("before_method_call: " + o);
  81. }
  82. public static void ajc_after_method_call() {
  83. System.out.println("after_method_call");
  84. }
  85. public static void ajc_after_method_call(Object o) {
  86. System.out.println("after_method_call: " + o);
  87. }
  88. public static void ajc_afterReturning_method_call() {
  89. System.out.println("ajc_afterReturning_method_call");
  90. }
  91. public static void ajc_afterReturning_method_call(Object o) {
  92. System.out.println("afterReturning_method_call: " + o);
  93. }
  94. public static void ajc_afterThrowing_method_call() {
  95. System.out.println("ajc_afterThrowing_method_call");
  96. }
  97. public static void ajc_afterThrowing_method_call(Object o) {
  98. System.out.println("afterThrowing_method_call: " + o);
  99. }
  100. public static Object ajc_around_method_call(AroundClosure closure) throws Throwable {
  101. Object ret = null;
  102. for (int i=0; i<3; i++) {
  103. System.out.println("enter: " + i);
  104. ret = closure.run(new Object[] {});
  105. }
  106. return ret;
  107. }
  108. // ----
  109. public static void ajc_before_constructor_call() {
  110. System.out.println("before_constructor_call");
  111. }
  112. public static void ajc_before_constructor_call(Object o) {
  113. System.out.println("before_constructor_call: " + o);
  114. }
  115. public static void ajc_after_constructor_call() {
  116. System.out.println("after_constructor_call");
  117. }
  118. public static void ajc_after_constructor_call(Object o) {
  119. System.out.println("after_constructor_call: " + o);
  120. }
  121. public static void ajc_afterReturning_constructor_call() {
  122. System.out.println("ajc_afterReturning_constructor_call");
  123. }
  124. public static void ajc_afterReturning_constructor_call(Object o) {
  125. System.out.println("afterReturning_constructor_call: " + o);
  126. }
  127. public static void ajc_afterThrowing_constructor_call() {
  128. System.out.println("ajc_afterThrowing_constructor_call");
  129. }
  130. public static void ajc_afterThrowing_constructor_call(Object o) {
  131. System.out.println("afterThrowing_constructor_call: " + o);
  132. }
  133. public static Object ajc_around_constructor_call(AroundClosure closure) throws Throwable {
  134. Object ret = null;
  135. for (int i=0; i<3; i++) {
  136. System.out.println("enter: " + i);
  137. ret = closure.run(new Object[] {});
  138. }
  139. return ret;
  140. }
  141. // ----
  142. public static void ajc_before_constructor_execution() {
  143. System.out.println("before_constructor_execution");
  144. }
  145. public static void ajc_before_constructor_execution(Object o) {
  146. System.out.println("before_constructor_execution: " + o);
  147. }
  148. public static void ajc_after_constructor_execution() {
  149. System.out.println("after_constructor_execution");
  150. }
  151. public static void ajc_after_constructor_execution(Object o) {
  152. System.out.println("after_constructor_execution: " + o);
  153. }
  154. public static void ajc_afterReturning_constructor_execution() {
  155. System.out.println("ajc_afterReturning_constructor_execution");
  156. }
  157. public static void ajc_afterReturning_constructor_execution(Object o) {
  158. System.out.println("afterReturning_constructor_execution: " + o);
  159. }
  160. public static void ajc_afterThrowing_constructor_execution() {
  161. System.out.println("ajc_afterThrowing_constructor_execution");
  162. }
  163. public static void ajc_afterThrowing_constructor_execution(Object o) {
  164. System.out.println("afterThrowing_constructor_execution: " + o);
  165. }
  166. public static Object ajc_around_constructor_execution(AroundClosure closure) throws Throwable {
  167. Object ret = null;
  168. for (int i=0; i<3; i++) {
  169. System.out.println("enter: " + i);
  170. ret = closure.run(new Object[] {});
  171. }
  172. return ret;
  173. }
  174. // ---
  175. public static void ajc_before_field_get() {
  176. System.out.println("before_field_get");
  177. }
  178. public static void ajc_before_field_get(Object o) {
  179. System.out.println("before_field_get: " + o);
  180. }
  181. public static void ajc_after_field_get() {
  182. System.out.println("after_field_get");
  183. }
  184. public static void ajc_after_field_get(Object o) {
  185. System.out.println("after_field_get: " + o);
  186. }
  187. public static void ajc_afterReturning_field_get() {
  188. System.out.println("afterReturning_field_get");
  189. }
  190. public static void ajc_afterReturning_field_get(Object o) {
  191. System.out.println("afterReturning_field_get: " + o);
  192. }
  193. public static void ajc_afterThrowing_field_get() {
  194. System.out.println("afterThrowing_field_get");
  195. }
  196. public static void ajc_afterThrowing_field_get(Object o) {
  197. System.out.println("afterThrowing_field_get: " + o);
  198. }
  199. public static void ajc_afterThrowing_field_get(Throwable t) {
  200. System.out.println("afterThrowing_field_get: " + t);
  201. }
  202. public static Object ajc_around_field_get(AroundClosure closure) throws Throwable {
  203. Object ret = closure.run(new Object[] {});
  204. return ret;
  205. }
  206. // ---
  207. public static void ajc_before_field_set() {
  208. System.out.println("before_field_set");
  209. }
  210. public static void ajc_before_field_set(Object o) {
  211. System.out.println("before_field_set: " + o);
  212. }
  213. public static void ajc_after_field_set() {
  214. System.out.println("after_field_set");
  215. }
  216. public static void ajc_after_field_set(Object o) {
  217. System.out.println("after_field_set: " + o);
  218. }
  219. public static void ajc_afterReturning_field_set() {
  220. System.out.println("afterReturning_field_set");
  221. }
  222. public static void ajc_afterReturning_field_set(Object o) {
  223. System.out.println("afterReturning_field_set: " + o);
  224. }
  225. public static void ajc_afterThrowing_field_set() {
  226. System.out.println("afterThrowing_field_set");
  227. }
  228. public static void ajc_afterThrowing_field_set(Object o) {
  229. System.out.println("afterThrowing_field_set: " + o);
  230. }
  231. public static void ajc_afterThrowing_field_set(Throwable t) {
  232. System.out.println("afterThrowing_field_set: " + t);
  233. }
  234. public static Object ajc_around_field_set(AroundClosure closure) throws Throwable {
  235. Object ret = closure.run(new Object[] {});
  236. return ret;
  237. }
  238. // don't call this method for callee-side call join points
  239. public static void ajc_before(JoinPoint.StaticPart tjp) {
  240. System.out.println("before: " + tjp);
  241. if (tjp.getSourceLocation() == null) {
  242. throw new RuntimeException("didn't want null");
  243. }
  244. System.out.println(" loc: " + tjp.getSourceLocation());
  245. }
  246. public static void ajc_before(JoinPoint tjp) {
  247. System.out.println("before: " + tjp + " this = " + tjp.getThis() +
  248. " target = " + tjp.getTarget() +
  249. " args = " + Arrays.asList(tjp.getArgs()));
  250. }
  251. // per object stuff
  252. private static Map objects = new HashMap();
  253. public static void ajc$perObjectBind(Object o) {
  254. if (objects.containsKey(o)) return;
  255. objects.put(o, new Aspect());
  256. }
  257. public static boolean hasAspect(Object o) {
  258. return objects.containsKey(o);
  259. }
  260. public static Aspect aspectOf(Object o) {
  261. return (Aspect) objects.get(o);
  262. }
  263. // per cflow stuff
  264. public static void ajc$perCflowPush() {
  265. ajc$perCflowStack.pushInstance(new Aspect());
  266. }
  267. public static boolean hasAspect() {
  268. return ajc$perCflowStack.isValid();
  269. }
  270. public static Aspect aspectOf() {
  271. if (ajc$perSingletonInstance != null) return ajc$perSingletonInstance;
  272. return (Aspect) ajc$perCflowStack.peekInstance();
  273. }
  274. public static CFlowStack ajc$perCflowStack = new CFlowStack();
  275. // non-static methods
  276. public static Aspect ajc$perSingletonInstance = new Aspect();
  277. public void ajc_before() {
  278. System.out.println("before in: " + this);
  279. }
  280. public static CFlowStack ajc$cflowStack$0 = new CFlowStack();
  281. }