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

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