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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. import org.aspectj.testing.*;
  2. import java.awt.event.*;
  3. import javax.swing.*;
  4. public class Inners {
  5. public static void main(String[] args) {
  6. new Inners().realMain(args);
  7. }
  8. public void realMain(String[] args) {
  9. unincludedInterfaces();
  10. includedInterfaces();
  11. unincludedAbstractClases();
  12. includedAbstractClases();
  13. Tester.checkAllEvents();
  14. }
  15. static {
  16. // Ensure all methods run
  17. Tester.expectEventsInString("localRunnable0,localRunnable1,anonRunnable,staticInnerRunnable0" +
  18. ",innerRunnable0,staticInnerRunnable1,innerRunnable1");
  19. Tester.expectEventsInString("localStuff0,localStuff1,anonStuff,staticInnerStuff0" +
  20. ",innerStuff0,staticInnerStuff1,innerStuff1");
  21. Tester.expectEventsInString("localAbstractAction0,localAbstractAction1,,localAbstractAction2" +
  22. ",anonAbstractAction0,anonAbstractAction1," +
  23. ",staticInnerAbstractAction0,staticInnerAbstractAction1,staticInnerAbstractAction2" +
  24. ",innerAbstractAction0,innerAbstractAction1,innerAbstractAction2");
  25. Tester.expectEventsInString("localAbstractStuff0,localAbstractStuff1,,localAbstractStuff2" +
  26. ",anonAbstractStuff0,anonAbstractStuff1," +
  27. ",staticInnerAbstractStuff0,staticInnerAbstractStuff1,staticInnerAbstractStuff2" +
  28. ",innerAbstractStuff0,innerAbstractStuff1,innerAbstractStuff2");
  29. }
  30. static String s = "";
  31. static void c(Object o) {
  32. s = o + "";
  33. }
  34. static int localRunnableI = 0;
  35. private void unincludedInterfaces() {
  36. class LocalRunnable implements Runnable {
  37. public void run() { a("localRunnable" + (localRunnableI++)); }
  38. }
  39. Runnable r0 = new StaticInnerRunnable();
  40. Runnable r1 = new InnerRunnable();
  41. Runnable r2 = new LocalRunnable();
  42. Runnable r3 = new Runnable() {
  43. public void run() { a("anonRunnable"); }
  44. };
  45. StaticInnerRunnable r4 = new StaticInnerRunnable();
  46. InnerRunnable r5 = new InnerRunnable();
  47. LocalRunnable r6 = new LocalRunnable();
  48. c("ui-r0"); r0.run();
  49. c("ui-r1"); r1.run();
  50. c("ui-r2"); r2.run();
  51. c("ui-r3"); r3.run();
  52. c("ui-r4"); r4.run();
  53. c("ui-r5"); r5.run();
  54. c("ui-r6"); r6.run();
  55. }
  56. static int localStuffI = 0;
  57. private void includedInterfaces() {
  58. class LocalStuff implements Stuff {
  59. public void run() { a("localStuff" + (localStuffI++)); }
  60. }
  61. Stuff r0 = new StaticInnerStuff();
  62. Stuff r1 = new InnerStuff();
  63. Stuff r2 = new LocalStuff();
  64. Stuff r3 = new Stuff() {
  65. public void run() { a("anonStuff"); }
  66. };
  67. StaticInnerStuff r4 = new StaticInnerStuff();
  68. InnerStuff r5 = new InnerStuff();
  69. LocalStuff r6 = new LocalStuff();
  70. c("ii-r0"); r0.run();
  71. c("ii-r1"); r1.run();
  72. c("ii-r2"); r2.run();
  73. c("ii-r3"); r3.run();
  74. c("ii-r4"); r4.run();
  75. c("ii-r5"); r5.run();
  76. c("ii-r6"); r6.run();
  77. }
  78. static int localAbstractActionI = 0;
  79. private void unincludedAbstractClases() {
  80. class LocalAbstractAction extends AbstractAction {
  81. public void actionPerformed(ActionEvent e) { a("localAbstractAction" + (localAbstractActionI++)); }
  82. }
  83. AbstractAction r0 = new StaticInnerAbstractAction();
  84. AbstractAction r1 = new InnerAbstractAction();
  85. AbstractAction r2 = new LocalAbstractAction();
  86. AbstractAction r3 = new AbstractAction() {
  87. public void actionPerformed(ActionEvent e) { a("anonAbstractAction0"); }
  88. };
  89. StaticInnerAbstractAction r4 = new StaticInnerAbstractAction();
  90. InnerAbstractAction r5 = new InnerAbstractAction();
  91. LocalAbstractAction r6 = new LocalAbstractAction();
  92. ActionListener r7 = new StaticInnerAbstractAction();
  93. ActionListener r8 = new InnerAbstractAction();
  94. ActionListener r9 = new LocalAbstractAction();
  95. ActionListener r10 = new AbstractAction() {
  96. public void actionPerformed(ActionEvent e) { a("anonAbstractAction1"); }
  97. };
  98. c("ua-r0"); r0.actionPerformed(null);
  99. c("ua-r1"); r1.actionPerformed(null);
  100. c("ua-r2"); r2.actionPerformed(null);
  101. c("ua-r3"); r3.actionPerformed(null);
  102. c("ua-r4"); r4.actionPerformed(null);
  103. c("ua-r5"); r5.actionPerformed(null);
  104. c("ua-r6"); r6.actionPerformed(null);
  105. c("ua-r7"); r7.actionPerformed(null);
  106. c("ua-r8"); r8.actionPerformed(null);
  107. c("ua-r9"); r9.actionPerformed(null);
  108. c("ua-r10"); r10.actionPerformed(null);
  109. }
  110. static int localAbstractStuffI = 0;
  111. private void includedAbstractClases() {
  112. class LocalAbstractStuff extends AbstractStuff {
  113. public void run() { a("localAbstractStuff" + (localAbstractStuffI++)); }
  114. }
  115. AbstractStuff r0 = new StaticInnerAbstractStuff();
  116. AbstractStuff r1 = new InnerAbstractStuff();
  117. AbstractStuff r2 = new LocalAbstractStuff();
  118. AbstractStuff r3 = new AbstractStuff() {
  119. public void run() { a("anonAbstractStuff0"); }
  120. };
  121. StaticInnerAbstractStuff r4 = new StaticInnerAbstractStuff();
  122. InnerAbstractStuff r5 = new InnerAbstractStuff();
  123. LocalAbstractStuff r6 = new LocalAbstractStuff();
  124. Stuff r7 = new StaticInnerAbstractStuff();
  125. Stuff r8 = new InnerAbstractStuff();
  126. Stuff r9 = new LocalAbstractStuff();
  127. Stuff r10 = new AbstractStuff() {
  128. public void run() { a("anonAbstractStuff1"); }
  129. };
  130. c("ia-r0"); r0.run();
  131. c("ia-r1"); r1.run();
  132. c("ia-r2"); r2.run();
  133. c("ia-r3"); r3.run();
  134. c("ia-r4"); r4.run();
  135. c("ia-r5"); r5.run();
  136. c("ia-r6"); r6.run();
  137. c("ia-r7"); r7.run();
  138. c("ia-r8"); r8.run();
  139. c("ia-r9"); r9.run();
  140. c("ia-r10"); r10.run();
  141. }
  142. /* Implement an unincluded interface */
  143. static class StaticInnerRunnable implements Runnable {
  144. static int i = 0;
  145. public void run() { Tester.event("staticInnerRunnable" + (i++)); }
  146. }
  147. static int innerRunnableI = 0;
  148. class InnerRunnable implements Runnable {
  149. public void run() { Tester.event("innerRunnable" + (innerRunnableI++)); }
  150. }
  151. /* Implement a included interface */
  152. static class StaticInnerStuff implements Stuff {
  153. static int i = 0;
  154. public void run() { Tester.event("staticInnerStuff" + (i++)); }
  155. }
  156. static int innerStuffI = 0;
  157. class InnerStuff implements Stuff {
  158. public void run() { Tester.event("innerStuff" + (innerStuffI++)); }
  159. }
  160. /* Extend an unincluded abstract class */
  161. static class StaticInnerAbstractAction extends AbstractAction {
  162. static int i = 0;
  163. public void actionPerformed(ActionEvent e) { Tester.event("staticInnerAbstractAction" + (i++)); }
  164. }
  165. static int innerAbstractActionI = 0;
  166. class InnerAbstractAction extends AbstractAction {
  167. public void actionPerformed(ActionEvent e) { Tester.event("innerAbstractAction" + (innerAbstractActionI++)); }
  168. }
  169. /* Extend a included abstract class */
  170. static class StaticInnerAbstractStuff extends AbstractStuff {
  171. static int i = 0;
  172. public void run() { Tester.event("staticInnerAbstractStuff" + (i++)); }
  173. }
  174. static int innerAbstractStuffI = 0;
  175. class InnerAbstractStuff extends AbstractStuff {
  176. public void run() { Tester.event("innerAbstractStuff" + (innerAbstractStuffI++)); }
  177. }
  178. }
  179. aspect Aspect {
  180. static void advise(String str, int start, int num) {
  181. for (int i = start; i < num; i++) {
  182. addAll(str, i);
  183. }
  184. }
  185. static void advise(String str, int num) {
  186. advise(str, 0, num);
  187. }
  188. static void advise(String str, int[] ints) {
  189. for (int i = 0; i < ints.length; i++) {
  190. addAll(str, ints[i]);
  191. }
  192. }
  193. static void addAll(String str, int i) {
  194. Tester.expectEvent("before-" + str + "-r" + i);
  195. Tester.expectEvent("after-" + str + "-r" + i);
  196. Tester.expectEvent("around-" + str + "-r" + i);
  197. }
  198. static void add(String str) {
  199. Tester.event(str + "-" + Inners.s);
  200. }
  201. /* unincludedInterfaces */
  202. pointcut receptionsRunnable(): receptions(void run()) && instanceof(Runnable);
  203. static { advise("receptions-ui", 7); }
  204. static before(): receptionsRunnable() { add("before-receptions"); }
  205. static after(): receptionsRunnable() { add("after-receptions"); }
  206. static around() returns void: receptionsRunnable() { add("around-receptions"); proceed(); }
  207. pointcut executionsRunnable(): executions(void run()) && instanceof(Runnable);
  208. static { advise("executions-ui", 7); }
  209. static before(): executionsRunnable() { add("before-executions"); }
  210. static after(): executionsRunnable() { add("after-executions"); }
  211. static around() returns void: executionsRunnable() { add("around-executions"); proceed(); }
  212. pointcut receptionsStaticInnerRunnable(): receptions(void run()) && instanceof(Inners.StaticInnerRunnable);
  213. static { advise("receptions-ui", new int[]{0,4}); }
  214. static before(): receptionsStaticInnerRunnable() { add("before-receptions"); }
  215. static after(): receptionsStaticInnerRunnable() { add("after-receptions"); }
  216. static around() returns void: receptionsStaticInnerRunnable() { add("around-receptions"); proceed(); }
  217. pointcut executionsStaticInnerRunnable(): executions(void run()) && instanceof(Inners.StaticInnerRunnable);
  218. static { advise("executions-ui", new int[]{0,4}); }
  219. static before(): executionsStaticInnerRunnable() { add("before-executions"); }
  220. static after(): executionsStaticInnerRunnable() { add("after-executions"); }
  221. static around() returns void: executionsStaticInnerRunnable() { add("around-executions"); proceed(); }
  222. pointcut receptionsInnerRunnable(): receptions(void run()) && instanceof(Inners.InnerRunnable);
  223. static { advise("receptions-ui", new int[]{1,5}); }
  224. static before(): receptionsInnerRunnable() { add("before-receptions"); }
  225. static after(): receptionsInnerRunnable() { add("after-receptions"); }
  226. static around() returns void: receptionsInnerRunnable() { add("around-receptions"); proceed(); }
  227. pointcut executionsInnerRunnable(): executions(void run()) && instanceof(Inners.InnerRunnable);
  228. static { advise("executions-ui", new int[]{1,5}); }
  229. static before(): executionsInnerRunnable() { add("before-executions"); }
  230. static after(): executionsInnerRunnable() { add("after-executions"); }
  231. static around() returns void: executionsInnerRunnable() { add("around-executions"); proceed(); }
  232. /* includedInterfaces */
  233. pointcut receptionsStuff(): receptions(void run()) && instanceof(Stuff);
  234. static { advise("receptions-ii", 7); }
  235. static before(): receptionsStuff() { add("before-receptions"); }
  236. static after(): receptionsStuff() { add("after-receptions"); }
  237. static around() returns void: receptionsStuff() { add("around-receptions"); proceed(); }
  238. pointcut executionsStuff(): executions(void run()) && instanceof(Stuff);
  239. static { advise("executions-ii", 7); }
  240. static before(): executionsStuff() { add("before-executions"); }
  241. static after(): executionsStuff() { add("after-executions"); }
  242. static around() returns void: executionsStuff() { add("around-executions"); proceed(); }
  243. pointcut receptionsStaticInnerStuff(): receptions(void run()) && instanceof(Inners.StaticInnerStuff);
  244. static { advise("receptions-ii", new int[]{0,4}); }
  245. static before(): receptionsStaticInnerStuff() { add("before-receptions"); }
  246. static after(): receptionsStaticInnerStuff() { add("after-receptions"); }
  247. static around() returns void: receptionsStaticInnerStuff() { add("around-receptions"); proceed(); }
  248. pointcut executionsStaticInnerStuff(): executions(void run()) && instanceof(Inners.StaticInnerStuff);
  249. static { advise("executions-ii", new int[]{0,4}); }
  250. static before(): executionsStaticInnerStuff() { add("before-executions"); }
  251. static after(): executionsStaticInnerStuff() { add("after-executions"); }
  252. static around() returns void: executionsStaticInnerStuff() { add("around-executions"); proceed(); }
  253. pointcut receptionsInnerStuff(): receptions(void run()) && instanceof(Inners.InnerStuff);
  254. static { advise("receptions-ii", new int[]{1,5}); }
  255. static before(): receptionsInnerStuff() { add("before-receptions"); }
  256. static after(): receptionsInnerStuff() { add("after-receptions"); }
  257. static around() returns void: receptionsInnerStuff() { add("around-receptions"); proceed(); }
  258. pointcut executionsInnerStuff(): executions(void run()) && instanceof(Inners.InnerStuff);
  259. static { advise("executions-ii", new int[]{1,5}); }
  260. static before(): executionsInnerStuff() { add("before-executions"); }
  261. static after(): executionsInnerStuff() { add("after-executions"); }
  262. static around() returns void: executionsInnerStuff() { add("around-executions"); proceed(); }
  263. /* unincludedAbstractClases */
  264. pointcut receptionsAbstractAction():
  265. receptions(void actionPerformed(ActionEvent)) && instanceof(AbstractAction);
  266. static { advise("receptions-ua", 7); }
  267. static before(): receptionsAbstractAction() { add("before-receptions"); }
  268. static after(): receptionsAbstractAction() { add("after-receptions"); }
  269. static around() returns void: receptionsAbstractAction() { add("around-receptions"); proceed(); }
  270. pointcut executionsAbstractAction():
  271. executions(void actionPerformed(ActionEvent)) && instanceof(AbstractAction);
  272. static { advise("executions-ua", 7); }
  273. static before(): executionsAbstractAction() { add("before-executions"); }
  274. static after(): executionsAbstractAction() { add("after-executions"); }
  275. static around() returns void: executionsAbstractAction() { add("around-executions"); proceed(); }
  276. pointcut receptionsActionListener():
  277. receptions(void actionPerformed(ActionEvent)) && instanceof(ActionListener);
  278. static { advise("receptions-ua", 11); }
  279. static before(): receptionsActionListener() { add("before-receptions"); }
  280. static after(): receptionsActionListener() { add("after-receptions"); }
  281. static around() returns void: receptionsActionListener() { add("around-receptions"); proceed(); }
  282. pointcut executionsActionListener():
  283. executions(void actionPerformed(ActionEvent)) && instanceof(ActionListener);
  284. static { advise("executions-ua", 11); }
  285. static before(): executionsActionListener() { add("before-executions"); }
  286. static after(): executionsActionListener() { add("after-executions"); }
  287. static around() returns void: executionsActionListener() { add("around-executions"); proceed(); }
  288. pointcut receptionsStaticInnerAbstractAction():
  289. receptions(void actionPerformed(ActionEvent)) && instanceof(Inners.StaticInnerAbstractAction);
  290. static { advise("receptions-ua", new int[]{0,4,7}); }
  291. static before(): receptionsStaticInnerAbstractAction() { add("before-receptions"); }
  292. static after(): receptionsStaticInnerAbstractAction() { add("after-receptions"); }
  293. static around() returns void: receptionsStaticInnerAbstractAction() { add("around-receptions"); proceed(); }
  294. pointcut executionsStaticInnerAbstractAction():
  295. executions(void actionPerformed(ActionEvent)) && instanceof(Inners.StaticInnerAbstractAction);
  296. static { advise("executions-ua", new int[]{0,4,7}); }
  297. static before(): executionsStaticInnerAbstractAction() { add("before-executions"); }
  298. static after(): executionsStaticInnerAbstractAction() { add("after-executions"); }
  299. static around() returns void: executionsStaticInnerAbstractAction() { add("around-executions"); proceed(); }
  300. pointcut receptionsInnerAbstractAction():
  301. receptions(void actionPerformed(ActionEvent)) && instanceof(Inners.InnerAbstractAction);
  302. static { advise("receptions-ua", new int[]{1,5,8}); }
  303. static before(): receptionsInnerAbstractAction() { add("before-receptions"); }
  304. static after(): receptionsInnerAbstractAction() { add("after-receptions"); }
  305. static around() returns void: receptionsInnerAbstractAction() { add("around-receptions"); proceed(); }
  306. pointcut executionsInnerAbstractAction():
  307. executions(void actionPerformed(ActionEvent)) && instanceof(Inners.InnerAbstractAction);
  308. static { advise("executions-ua", new int[]{1,5,8}); }
  309. static before(): executionsInnerAbstractAction() { add("before-executions"); }
  310. static after(): executionsInnerAbstractAction() { add("after-executions"); }
  311. static around() returns void: executionsInnerAbstractAction() { add("around-executions"); proceed(); }
  312. /* includedAbstractClases */
  313. pointcut receptionsAbstractStuff(): receptions(void run()) && instanceof(AbstractStuff);
  314. static { advise("receptions-ia", 7); }
  315. static before(): receptionsAbstractStuff() { add("before-receptions"); }
  316. static after(): receptionsAbstractStuff() { add("after-receptions"); }
  317. static around() returns void: receptionsAbstractStuff() { add("around-receptions"); proceed(); }
  318. pointcut executionsAbstractStuff(): executions(void run()) && instanceof(AbstractStuff);
  319. static { advise("executions-ia", 7); }
  320. static before(): executionsAbstractStuff() { add("before-executions"); }
  321. static after(): executionsAbstractStuff() { add("after-executions"); }
  322. static around() returns void: executionsAbstractStuff() { add("around-executions"); proceed(); }
  323. pointcut receptionsStuff2(): receptions(void run()) && instanceof(Stuff);
  324. static { advise("receptions-ia", 11); }
  325. static before(): receptionsStuff2() { add("before-receptions"); }
  326. static after(): receptionsStuff2() { add("after-receptions"); }
  327. static around() returns void: receptionsStuff2() { add("around-receptions"); proceed(); }
  328. pointcut executionsStuff2(): executions(void run()) && instanceof(Stuff);
  329. static { advise("executions-ia", 11); }
  330. static before(): executionsStuff2() { add("before-executions"); }
  331. static after(): executionsStuff2() { add("after-executions"); }
  332. static around() returns void: executionsStuff2() { add("around-executions"); proceed(); }
  333. pointcut receptionsStaticInnerAbstractStuff():
  334. receptions(void run()) && instanceof(Inners.StaticInnerAbstractStuff);
  335. static { advise("receptions-ia", new int[]{0,4,7}); }
  336. static before(): receptionsStaticInnerAbstractStuff() { add("before-receptions"); }
  337. static after(): receptionsStaticInnerAbstractStuff() { add("after-receptions"); }
  338. static around() returns void: receptionsStaticInnerAbstractStuff() { add("around-receptions"); proceed(); }
  339. pointcut executionsStaticInnerAbstractStuff():
  340. executions(void run()) && instanceof(Inners.StaticInnerAbstractStuff);
  341. static { advise("executions-ia", new int[]{0,4,7}); }
  342. static before(): executionsStaticInnerAbstractStuff() { add("before-executions"); }
  343. static after(): executionsStaticInnerAbstractStuff() { add("after-executions"); }
  344. static around() returns void: executionsStaticInnerAbstractStuff() { add("around-executions"); proceed(); }
  345. pointcut receptionsInnerAbstractStuff():
  346. receptions(void run()) && instanceof(Inners.InnerAbstractStuff);
  347. static { advise("receptions-ia", new int[]{1,5,8}); }
  348. static before(): receptionsInnerAbstractStuff() { add("before-receptions"); }
  349. static after(): receptionsInnerAbstractStuff() { add("after-receptions"); }
  350. static around() returns void: receptionsInnerAbstractStuff() { add("around-receptions"); proceed(); }
  351. pointcut executionsInnerAbstractStuff():
  352. executions(void run()) && instanceof(Inners.InnerAbstractStuff);
  353. static { advise("executions-ia", new int[]{1,5,8}); }
  354. static before(): executionsInnerAbstractStuff() { add("before-executions"); }
  355. static after(): executionsInnerAbstractStuff() { add("after-executions"); }
  356. static around() returns void: executionsInnerAbstractStuff() { add("around-executions"); proceed(); }
  357. }
  358. interface Stuff {
  359. public void run();
  360. }
  361. abstract class AbstractStuff implements Stuff {
  362. public abstract void run();
  363. }