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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  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.List;
  14. import junit.framework.Test;
  15. import org.aspectj.apache.bcel.classfile.JavaClass;
  16. import org.aspectj.apache.bcel.classfile.LocalVariable;
  17. import org.aspectj.apache.bcel.classfile.LocalVariableTable;
  18. import org.aspectj.apache.bcel.classfile.Method;
  19. import org.aspectj.asm.AsmManager;
  20. import org.aspectj.asm.IHierarchy;
  21. import org.aspectj.asm.IProgramElement;
  22. import org.aspectj.testing.Utils;
  23. import org.aspectj.testing.XMLBasedAjcTestCase;
  24. public class Ajc163Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
  25. public void testGenericMethodBridging_pr251326() {
  26. runTest("itd anonymous inner class in wrong package");
  27. }
  28. public void testOrderingRepetitive_pr259279() {
  29. runTest("ordering repetitive method");
  30. }
  31. public void testOrderingRepetitive_pr259279_2() {
  32. runTest("ordering repetitive method - 2");
  33. }
  34. public void testExtendingASI_pr252722() {
  35. runTest("extending AbstractSecurityInterceptor");
  36. }
  37. public void testExtendingASI_pr252722_2() {
  38. runTest("extending AbstractSecurityInterceptor - 2");
  39. }
  40. public void testExtendingASI_pr252722_3() {
  41. runTest("extending AbstractSecurityInterceptor - 3");
  42. }
  43. public void testExtendingASI_pr252722_4() {
  44. runTest("extending AbstractSecurityInterceptor - 4");
  45. }
  46. public void testGetNode_pr258653() {
  47. runTest("getNode");
  48. }
  49. public void testAtTargetPlus_pr255856() {
  50. runTest("attarget with plus");
  51. }
  52. public void testNonNullAtArgs_pr257833() {
  53. runTest("param annos and at args");
  54. }
  55. public void testIncorrectArgOrdering_pr219419() {
  56. runTest("incorrect arg ordering anno style");
  57. }
  58. public void testIncorrectArgOrdering_pr219419_2() {
  59. runTest("incorrect arg ordering anno style - 2");
  60. }
  61. public void testIncorrectArgOrdering_pr219419_3() {
  62. runTest("incorrect arg ordering anno style - 3");
  63. }
  64. // similar to 3 but parameters other way round
  65. public void testIncorrectArgOrdering_pr219419_4() {
  66. runTest("incorrect arg ordering anno style - 4");
  67. }
  68. // similar to 3 but also JoinPoint passed into advice
  69. public void testIncorrectArgOrdering_pr219419_5() {
  70. runTest("incorrect arg ordering anno style - 5");
  71. }
  72. public void testDecpAnnoStyle_pr257754() {
  73. runTest("decp anno style");
  74. }
  75. public void testDecpAnnoStyle_pr257754_2() {
  76. runTest("decp anno style - 2");
  77. }
  78. public void testPoorAtAjIfMessage_pr256458() {
  79. runTest("poor ataj if message - 1");
  80. }
  81. public void testPoorAtAjIfMessage_pr256458_2() {
  82. runTest("poor ataj if message - 2");
  83. }
  84. /*
  85. * public void testInheritedAnnotations_pr128664() { runTest("inherited annotations"); }
  86. *
  87. * public void testInheritedAnnotations_pr128664_2() { runTest("inherited annotations - 2"); }
  88. */
  89. public void testGetMethodNull_pr154427() {
  90. runTest("getMethod returning null");
  91. }
  92. public void testItdOnAnonInner_pr171042() {
  93. runTest("itd on anonymous inner");
  94. }
  95. public void testMixedStyles_pr213751() {
  96. runTest("mixed styles");
  97. }
  98. public void testHandles_pr249216c24() {
  99. runTest("handles - escaped square brackets");
  100. IHierarchy top = AsmManager.lastActiveStructureModel.getHierarchy();
  101. IProgramElement ipe = null;
  102. ipe = findElementAtLine(top.getRoot(), 4);// public java.util.List<String> Ship.i(List<String>[][] u)
  103. assertEquals("<{Handles.java'Handles)Ship.i)\\[\\[QList\\<QString;>;", ipe.getHandleIdentifier());
  104. ipe = findElementAtLine(top.getRoot(), 7);// public java.util.List<String> Ship.i(Set<String>[][] u)
  105. assertEquals("<{Handles.java'Handles)Ship.i)\\[\\[QSet\\<QString;>;", ipe.getHandleIdentifier());
  106. // public java.util.Set<String> i(java.util.Set<String>[][] u)
  107. ipe = findElementAtLine(top.getRoot(), 10);
  108. assertEquals("<{Handles.java'Handles~i~\\[\\[Qjava.util.Set\\<QString;>;", ipe.getHandleIdentifier());
  109. ipe = findElementAtLine(top.getRoot(), 13);// public java.util.Set<String> i(java.util.Set<String>[][] u,int i) {
  110. assertEquals("<{Handles.java'Handles~i~\\[\\[Qjava.util.Set\\<QString;>;~I", ipe.getHandleIdentifier());
  111. ipe = findElementAtLine(top.getRoot(), 16);// public java.util.Set<String> i2(java.util.Set<? extends
  112. // Collection<String>>[][] u) {
  113. assertEquals("<{Handles.java'Handles~i2~\\[\\[Qjava.util.Set\\<+QCollection\\<QString;>;>;", ipe.getHandleIdentifier());
  114. ipe = findElementAtLine(top.getRoot(), 19);// public java.util.Set<String> i3(java.util.Set<? extends
  115. // Collection<String[]>>[][] u)
  116. assertEquals("<{Handles.java'Handles~i3~\\[\\[Qjava.util.Set\\<+QCollection\\<\\[QString;>;>;", ipe.getHandleIdentifier());
  117. ipe = findElementAtLine(top.getRoot(), 22);
  118. assertEquals("<{Handles.java'Handles~i4~Qjava.util.Set\\<+QCollection\\<QString;>;>;", ipe.getHandleIdentifier());
  119. ipe = findElementAtLine(top.getRoot(), 25);
  120. assertEquals("<{Handles.java'Handles~i5~Qjava.util.Set\\<*>;", ipe.getHandleIdentifier());
  121. }
  122. public void testFQType_pr256937() {
  123. runTest("fully qualified return type");
  124. IHierarchy top = AsmManager.lastActiveStructureModel.getHierarchy();
  125. IProgramElement itd = findElementAtLine(top.getRoot(), 10);
  126. String type = itd.getCorrespondingType(true);
  127. assertEquals("java.util.List<java.lang.String>", type);
  128. itd = findElementAtLine(top.getRoot(), 16);
  129. type = itd.getCorrespondingType(true);
  130. assertEquals("java.util.List<java.lang.String>", type);
  131. }
  132. private IProgramElement findElementAtLine(IProgramElement whereToLook, int line) {
  133. if (whereToLook == null) {
  134. return null;
  135. }
  136. if (whereToLook.getSourceLocation() != null && whereToLook.getSourceLocation().getLine() == line) {
  137. return whereToLook;
  138. }
  139. List<IProgramElement> kids = whereToLook.getChildren();
  140. for (IProgramElement object: kids) {
  141. if (object.getSourceLocation() != null && object.getSourceLocation().getLine() == line) {
  142. return object;
  143. }
  144. IProgramElement gotSomething = findElementAtLine(object, line);
  145. if (gotSomething != null) {
  146. return gotSomething;
  147. }
  148. }
  149. return null;
  150. }
  151. public void testParameterAnnotationsOnITDs_pr256669() { // regular itd
  152. runTest("parameter annotations on ITDs");
  153. }
  154. public void testParameterAnnotationsOnITDs_pr256669_2() { // static itd
  155. runTest("parameter annotations on ITDs - 2");
  156. }
  157. public void testParameterAnnotationsOnITDs_pr256669_3() { // multiple parameters
  158. runTest("parameter annotations on ITDs - 3");
  159. }
  160. public void testParameterAnnotationsOnITDs_pr256669_4() { // itd on interface
  161. runTest("parameter annotations on ITDs - 4");
  162. }
  163. public void testOrderingIssue_1() {
  164. runTest("ordering issue");
  165. }
  166. public void testOrderingIssue_2() {
  167. runTest("ordering issue - 2");
  168. }
  169. // public void testGenericPointcuts_5() {
  170. // runTest("generic pointcuts - 5");
  171. // }
  172. public void testGenericPointcuts_1() {
  173. runTest("generic pointcuts - 1");
  174. }
  175. public void testGenericPointcuts_2() {
  176. runTest("generic pointcuts - 2");
  177. }
  178. public void testGenericPointcuts_3() {
  179. runTest("generic pointcuts - 3");
  180. }
  181. public void testGenericPointcuts_4() {
  182. runTest("generic pointcuts - 4");
  183. }
  184. public void testDontAddMethodBodiesToInterface_pr163005() {
  185. runTest("do not add method bodies to an interface");
  186. }
  187. public void testDontAddMethodBodiesToInterface_pr163005_2() {
  188. runTest("do not add method bodies to an interface - 2");
  189. }
  190. public void testDontAddMethodBodiesToInterface_pr163005_3() {
  191. runTest("do not add method bodies to an interface - 3");
  192. }
  193. public void testMissingLocalVariableTableEntriesOnAroundAdvice_pr173978() throws Exception {
  194. runTest("missing local variable table on around advice");
  195. JavaClass jc = Utils.getClassFrom(ajc.getSandboxDirectory().getAbsolutePath(), "Test");
  196. Method[] ms = jc.getMethods();
  197. Method m = null;
  198. for (int i = 0; i < ms.length; i++) {
  199. if (ms[i].getName().equals("sayHello")) {
  200. m = ms[i];
  201. }
  202. }
  203. if (m.getLocalVariableTable() == null) {
  204. fail("Local variable table should not be null");
  205. }
  206. assertEquals(2, m.getLocalVariableTable().getLocalVariableTable().length);
  207. // LocalVariableTable:
  208. // Start Length Slot Name Signature
  209. // 0 12 0 this LTest;
  210. // 0 12 1 message Ljava/lang/String;
  211. LocalVariable lv = m.getLocalVariableTable().getLocalVariable(0);
  212. assertNotNull(lv);
  213. assertEquals("this", lv.getName());
  214. assertEquals(0, lv.getStartPC(), 0);
  215. assertEquals(12, lv.getLength(), 12);
  216. assertEquals("LTest;", lv.getSignature());
  217. lv = m.getLocalVariableTable().getLocalVariable(1);
  218. assertNotNull(lv);
  219. assertEquals("message", lv.getName());
  220. assertEquals(0, lv.getStartPC(), 0);
  221. assertEquals(12, lv.getLength(), 12);
  222. assertEquals("Ljava/lang/String;", lv.getSignature());
  223. // print(m.getLocalVariableTable());
  224. }
  225. public void testTerminateAfterCompilation_pr249710() {
  226. runTest("terminateAfterCompilation");
  227. }
  228. public void testItdCCE_pr250091() {
  229. runTest("itd cce");
  230. }
  231. public void testBreakingRecovery_pr226163() {
  232. runTest("breaking recovery");
  233. }
  234. public void testGenericMethodConversions_pr250632() {
  235. runTest("type conversion in generic itd");
  236. }
  237. public void testGenericMethodBridging_pr250493() {
  238. runTest("bridge methods for generic itds");
  239. }
  240. public void testGenericFieldBridging_pr252285() {
  241. runTest("bridge methods for generic itd fields");
  242. }
  243. public static Test suite() {
  244. return XMLBasedAjcTestCase.loadSuite(Ajc163Tests.class);
  245. }
  246. protected File getSpecFile() {
  247. return getClassResource("ajc163.xml");
  248. }
  249. // ---
  250. private void print(LocalVariableTable localVariableTable) {
  251. LocalVariable[] lvs = localVariableTable.getLocalVariableTable();
  252. for (int i = 0; i < lvs.length; i++) {
  253. LocalVariable localVariable = lvs[i];
  254. System.out.println(localVariable);
  255. }
  256. }
  257. }