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.

Ajc163Tests.java 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. /*******************************************************************************
  2. * Copyright (c) 2008 Contributors
  3. * All rights reserved. This program and the accompanying materials
  4. * are made available under the terms of the Eclipse Public License v1.0
  5. * which accompanies this distribution, and is available at
  6. * http://www.eclipse.org/legal/epl-v10.html
  7. *
  8. * Contributors:
  9. * Andy Clement - initial API and implementation
  10. *******************************************************************************/
  11. package org.aspectj.systemtest.ajc163;
  12. import java.io.File;
  13. import java.util.Iterator;
  14. import java.util.List;
  15. import junit.framework.Test;
  16. import org.aspectj.apache.bcel.classfile.JavaClass;
  17. import org.aspectj.apache.bcel.classfile.LocalVariable;
  18. import org.aspectj.apache.bcel.classfile.LocalVariableTable;
  19. import org.aspectj.apache.bcel.classfile.Method;
  20. import org.aspectj.asm.AsmManager;
  21. import org.aspectj.asm.IHierarchy;
  22. import org.aspectj.asm.IProgramElement;
  23. import org.aspectj.testing.Utils;
  24. import org.aspectj.testing.XMLBasedAjcTestCase;
  25. public class Ajc163Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
  26. // public void testGenericMethodBridging_pr251326() {
  27. // runTest("itd anonymous inner class in wrong package");
  28. // }
  29. public void testOrderingRepetitive_pr259279() {
  30. runTest("ordering repetitive method");
  31. }
  32. public void testOrderingRepetitive_pr259279_2() {
  33. runTest("ordering repetitive method - 2");
  34. }
  35. public void testExtendingASI_pr252722() {
  36. runTest("extending AbstractSecurityInterceptor");
  37. }
  38. public void testExtendingASI_pr252722_2() {
  39. runTest("extending AbstractSecurityInterceptor - 2");
  40. }
  41. public void testExtendingASI_pr252722_3() {
  42. runTest("extending AbstractSecurityInterceptor - 3");
  43. }
  44. public void testExtendingASI_pr252722_4() {
  45. runTest("extending AbstractSecurityInterceptor - 4");
  46. }
  47. public void testGetNode_pr258653() {
  48. runTest("getNode");
  49. }
  50. public void testAtTargetPlus_pr255856() {
  51. runTest("attarget with plus");
  52. }
  53. public void testNonNullAtArgs_pr257833() {
  54. runTest("param annos and at args");
  55. }
  56. // public void testAtAspectJDecp_pr164016() {
  57. // runTest("ataspectj decp");
  58. // }
  59. public void testIncorrectArgOrdering_pr219419() {
  60. runTest("incorrect arg ordering anno style");
  61. }
  62. public void testIncorrectArgOrdering_pr219419_2() {
  63. runTest("incorrect arg ordering anno style - 2");
  64. }
  65. public void testIncorrectArgOrdering_pr219419_3() {
  66. runTest("incorrect arg ordering anno style - 3");
  67. }
  68. // similar to 3 but parameters other way round
  69. public void testIncorrectArgOrdering_pr219419_4() {
  70. runTest("incorrect arg ordering anno style - 4");
  71. }
  72. // similar to 3 but also JoinPoint passed into advice
  73. public void testIncorrectArgOrdering_pr219419_5() {
  74. runTest("incorrect arg ordering anno style - 5");
  75. }
  76. public void testDecpAnnoStyle_pr257754() {
  77. runTest("decp anno style");
  78. }
  79. public void testDecpAnnoStyle_pr257754_2() {
  80. runTest("decp anno style - 2");
  81. }
  82. public void testPoorAtAjIfMessage_pr256458() {
  83. runTest("poor ataj if message - 1");
  84. }
  85. public void testPoorAtAjIfMessage_pr256458_2() {
  86. runTest("poor ataj if message - 2");
  87. }
  88. /*
  89. * public void testInheritedAnnotations_pr128664() { runTest("inherited annotations"); }
  90. *
  91. * public void testInheritedAnnotations_pr128664_2() { runTest("inherited annotations - 2"); }
  92. */
  93. public void testGetMethodNull_pr154427() {
  94. runTest("getMethod returning null");
  95. }
  96. public void testItdOnAnonInner_pr171042() {
  97. runTest("itd on anonymous inner");
  98. }
  99. public void testMixedStyles_pr213751() {
  100. runTest("mixed styles");
  101. }
  102. public void testHandles_pr249216c24() {
  103. runTest("handles - escaped square brackets");
  104. IHierarchy top = AsmManager.lastActiveStructureModel.getHierarchy();
  105. IProgramElement ipe = null;
  106. ipe = findElementAtLine(top.getRoot(), 4);// public java.util.List<String> Ship.i(List<String>[][] u)
  107. assertEquals("<{Handles.java}Handles)Ship.i)\\[\\[Qjava.util.List\\<QString;>;", ipe.getHandleIdentifier());
  108. ipe = findElementAtLine(top.getRoot(), 7);// public java.util.List<String> Ship.i(Set<String>[][] u)
  109. assertEquals("<{Handles.java}Handles)Ship.i)\\[\\[Qjava.util.Set\\<QString;>;", ipe.getHandleIdentifier());
  110. // public java.util.Set<String> i(java.util.Set<String>[][] u)
  111. ipe = findElementAtLine(top.getRoot(), 10);
  112. assertEquals("<{Handles.java}Handles~i~\\[\\[Qjava.util.Set\\<QString;>;", ipe.getHandleIdentifier());
  113. ipe = findElementAtLine(top.getRoot(), 13);// public java.util.Set<String> i(java.util.Set<String>[][] u,int i) {
  114. assertEquals("<{Handles.java}Handles~i~\\[\\[Qjava.util.Set\\<QString;>;~I", ipe.getHandleIdentifier());
  115. ipe = findElementAtLine(top.getRoot(), 16);// public java.util.Set<String> i(java.util.Set<String>[][] u,int i) {
  116. assertEquals("<{Handles.java}Handles~i2~\\[\\[Qjava.util.Set\\<+QCollection\\<QString;>;>;", ipe.getHandleIdentifier());
  117. ipe = findElementAtLine(top.getRoot(), 19);// public java.util.Set<String> i3(java.util.Set<? extends
  118. // Collection<String[]>>[][] u)
  119. assertEquals("<{Handles.java}Handles~i3~\\[\\[Qjava.util.Set\\<+QCollection\\<\\[QString;>;>;", ipe.getHandleIdentifier());
  120. ipe = findElementAtLine(top.getRoot(), 22);
  121. assertEquals("<{Handles.java}Handles~i4~Qjava.util.Set\\<+QCollection\\<QString;>;>;", ipe.getHandleIdentifier());
  122. ipe = findElementAtLine(top.getRoot(), 25);
  123. assertEquals("<{Handles.java}Handles~i5~Qjava.util.Set\\<*>;", ipe.getHandleIdentifier());
  124. }
  125. public void testFQType_pr256937() {
  126. runTest("fully qualified return type");
  127. IHierarchy top = AsmManager.lastActiveStructureModel.getHierarchy();
  128. IProgramElement itd = findElementAtLine(top.getRoot(), 10);
  129. String type = itd.getCorrespondingType(true);
  130. assertEquals("java.util.List<java.lang.String>", type);
  131. itd = findElementAtLine(top.getRoot(), 16);
  132. type = itd.getCorrespondingType(true);
  133. assertEquals("java.util.List<java.lang.String>", type);
  134. }
  135. private IProgramElement findElementAtLine(IProgramElement whereToLook, int line) {
  136. if (whereToLook == null) {
  137. return null;
  138. }
  139. if (whereToLook.getSourceLocation() != null && whereToLook.getSourceLocation().getLine() == line) {
  140. return whereToLook;
  141. }
  142. List kids = whereToLook.getChildren();
  143. for (Iterator iterator = kids.iterator(); iterator.hasNext();) {
  144. IProgramElement object = (IProgramElement) iterator.next();
  145. if (object.getSourceLocation() != null && object.getSourceLocation().getLine() == line) {
  146. return object;
  147. }
  148. IProgramElement gotSomething = findElementAtLine(object, line);
  149. if (gotSomething != null) {
  150. return gotSomething;
  151. }
  152. }
  153. return null;
  154. }
  155. public void testParameterAnnotationsOnITDs_pr256669() { // regular itd
  156. runTest("parameter annotations on ITDs");
  157. }
  158. public void testParameterAnnotationsOnITDs_pr256669_2() { // static itd
  159. runTest("parameter annotations on ITDs - 2");
  160. }
  161. public void testParameterAnnotationsOnITDs_pr256669_3() { // multiple parameters
  162. runTest("parameter annotations on ITDs - 3");
  163. }
  164. public void testParameterAnnotationsOnITDs_pr256669_4() { // itd on interface
  165. runTest("parameter annotations on ITDs - 4");
  166. }
  167. public void testOrderingIssue_1() {
  168. runTest("ordering issue");
  169. }
  170. public void testOrderingIssue_2() {
  171. runTest("ordering issue - 2");
  172. }
  173. // public void testGenericPointcuts_5() {
  174. // runTest("generic pointcuts - 5");
  175. // }
  176. public void testGenericPointcuts_1() {
  177. runTest("generic pointcuts - 1");
  178. }
  179. public void testGenericPointcuts_2() {
  180. runTest("generic pointcuts - 2");
  181. }
  182. public void testGenericPointcuts_3() {
  183. runTest("generic pointcuts - 3");
  184. }
  185. public void testGenericPointcuts_4() {
  186. runTest("generic pointcuts - 4");
  187. }
  188. // public void testBrokenLVT_pr194314_1() throws Exception {
  189. // runTest("broken lvt - 1");
  190. // JavaClass jc = Utils.getClassFrom(ajc.getSandboxDirectory().getAbsolutePath(), "Service");
  191. // Method[] ms = jc.getMethods();
  192. // Method m = null;
  193. // for (int i = 0; i < ms.length; i++) {
  194. // if (ms[i].getName().equals("method_aroundBody1$advice")) {
  195. // m = ms[i];
  196. // }
  197. // }
  198. // if (m.getLocalVariableTable() == null) {
  199. // fail("Local variable table should not be null");
  200. // }
  201. // System.out.println(m.getLocalVariableTable());
  202. // LocalVariable[] lvt = m.getLocalVariableTable().getLocalVariableTable();
  203. // assertEquals(8, lvt.length);
  204. // }
  205. //
  206. // public void testBrokenLVT_pr194314_2() throws Exception {
  207. // runTest("broken lvt - 2");
  208. // JavaClass jc = Utils.getClassFrom(ajc.getSandboxDirectory().getAbsolutePath(), "Service");
  209. // Method[] ms = jc.getMethods();
  210. // Method m = null;
  211. // for (int i = 0; i < ms.length; i++) {
  212. // if (ms[i].getName().equals("method_aroundBody1$advice")) {
  213. // m = ms[i];
  214. // }
  215. // }
  216. // if (m.getLocalVariableTable() == null) {
  217. // fail("Local variable table should not be null");
  218. // }
  219. // System.out.println(m.getLocalVariableTable());
  220. // LocalVariable[] lvt = m.getLocalVariableTable().getLocalVariableTable();
  221. // assertEquals(8, lvt.length);
  222. // // assertEquals(2, m.getLocalVariableTable().getLocalVariableTable().length);
  223. //
  224. // // Before I've started any work on this:
  225. // // LocalVariable(start_pc = 0, length = 68, index = 0:ServiceInterceptorCodeStyle this)
  226. // // LocalVariable(start_pc = 0, length = 68, index = 1:org.aspectj.runtime.internal.AroundClosure ajc_aroundClosure)
  227. // // LocalVariable(start_pc = 0, length = 68, index = 2:org.aspectj.lang.JoinPoint thisJoinPoint)
  228. // // LocalVariable(start_pc = 9, length = 59, index = 3:Object[] args)
  229. // // LocalVariable(start_pc = 21, length = 47, index = 4:long id)
  230. //
  231. // // Method signature:
  232. // // private static final void method_aroundBody1$advice(Service, long, org.aspectj.lang.JoinPoint,
  233. // // ServiceInterceptorCodeStyle, org.aspectj.runtime.internal.AroundClosure, org.aspectj.lang.JoinPoint);
  234. // //
  235. // // Service, JoinPoint, ServiceInterceptorCodeStyle, AroundClosure, JoinPoint
  236. //
  237. // // args should be in slot 7 and the long in position 8
  238. //
  239. // }
  240. public void testDontAddMethodBodiesToInterface_pr163005() {
  241. runTest("do not add method bodies to an interface");
  242. }
  243. public void testDontAddMethodBodiesToInterface_pr163005_2() {
  244. runTest("do not add method bodies to an interface - 2");
  245. }
  246. public void testDontAddMethodBodiesToInterface_pr163005_3() {
  247. runTest("do not add method bodies to an interface - 3");
  248. }
  249. public void testMissingLocalVariableTableEntriesOnAroundAdvice_pr173978() throws Exception {
  250. runTest("missing local variable table on around advice");
  251. JavaClass jc = Utils.getClassFrom(ajc.getSandboxDirectory().getAbsolutePath(), "Test");
  252. Method[] ms = jc.getMethods();
  253. Method m = null;
  254. for (int i = 0; i < ms.length; i++) {
  255. if (ms[i].getName().equals("sayHello")) {
  256. m = ms[i];
  257. }
  258. }
  259. if (m.getLocalVariableTable() == null) {
  260. fail("Local variable table should not be null");
  261. }
  262. assertEquals(2, m.getLocalVariableTable().getLocalVariableTable().length);
  263. // LocalVariableTable:
  264. // Start Length Slot Name Signature
  265. // 0 12 0 this LTest;
  266. // 0 12 1 message Ljava/lang/String;
  267. LocalVariable lv = m.getLocalVariableTable().getLocalVariable(0);
  268. assertNotNull(lv);
  269. assertEquals("this", lv.getName());
  270. assertEquals(0, lv.getStartPC(), 0);
  271. assertEquals(12, lv.getLength(), 12);
  272. assertEquals("LTest;", lv.getSignature());
  273. lv = m.getLocalVariableTable().getLocalVariable(1);
  274. assertNotNull(lv);
  275. assertEquals("message", lv.getName());
  276. assertEquals(0, lv.getStartPC(), 0);
  277. assertEquals(12, lv.getLength(), 12);
  278. assertEquals("Ljava/lang/String;", lv.getSignature());
  279. // print(m.getLocalVariableTable());
  280. }
  281. public void testTerminateAfterCompilation_pr249710() {
  282. runTest("terminateAfterCompilation");
  283. }
  284. public void testItdCCE_pr250091() {
  285. runTest("itd cce");
  286. }
  287. public void testBreakingRecovery_pr226163() {
  288. runTest("breaking recovery");
  289. }
  290. public void testGenericMethodConversions_pr250632() {
  291. runTest("type conversion in generic itd");
  292. }
  293. public void testGenericMethodBridging_pr250493() {
  294. runTest("bridge methods for generic itds");
  295. }
  296. public void testGenericFieldBridging_pr252285() {
  297. runTest("bridge methods for generic itd fields");
  298. }
  299. public static Test suite() {
  300. return XMLBasedAjcTestCase.loadSuite(Ajc163Tests.class);
  301. }
  302. protected File getSpecFile() {
  303. return new File("../tests/src/org/aspectj/systemtest/ajc163/ajc163.xml");
  304. }
  305. // ---
  306. private void print(LocalVariableTable localVariableTable) {
  307. LocalVariable[] lvs = localVariableTable.getLocalVariableTable();
  308. for (int i = 0; i < lvs.length; i++) {
  309. LocalVariable localVariable = lvs[i];
  310. System.out.println(localVariable);
  311. }
  312. }
  313. }