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.

GenericsTests.java 9.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. package org.aspectj.systemtest.ajc150;
  2. import java.io.File;
  3. import junit.framework.Test;
  4. import org.aspectj.apache.bcel.classfile.Attribute;
  5. import org.aspectj.apache.bcel.classfile.JavaClass;
  6. import org.aspectj.apache.bcel.classfile.Signature;
  7. import org.aspectj.apache.bcel.util.ClassPath;
  8. import org.aspectj.apache.bcel.util.SyntheticRepository;
  9. import org.aspectj.testing.XMLBasedAjcTestCase;
  10. public class GenericsTests extends XMLBasedAjcTestCase {
  11. /*==========================================
  12. * Generics test plan for pointcuts.
  13. *
  14. * handler PASS
  15. * - does not permit type var spec
  16. * - does not permit generic type (fail with type not found)
  17. * - does not permit parameterized types
  18. * if PASS
  19. * - does not permit type vars
  20. * cflow PASS
  21. * - does not permit type vars
  22. * cflowbelow PASS
  23. * - does not permit type vars
  24. * @this PASS
  25. * - does not permit type vars PASS
  26. * - does not permit parameterized type PASS
  27. * @target PASS
  28. * - does not permit type vars PASS
  29. * - does not permit parameterized type PASS
  30. * @args PASS
  31. * - does not permit type vars PASS
  32. * - does not permit parameterized type PASS
  33. * @annotation PASS
  34. * - does not permit type vars PASS
  35. * - does not permit parameterized type PASS
  36. * @within, @within code - as above PASS
  37. * annotation type pattern with generic and parameterized types PASS
  38. * - just make sure that annotation interfaces can never be generic first! VERIFIED
  39. * - @Foo<T> should fail PASS
  40. * - @Foo<String> should fail PASS
  41. * - @(Foo || Bar<T>) should fail DEFERRED (not critical)
  42. * staticinitialization
  43. * - error on parameterized type
  44. * - permit parameterized type +
  45. * - wrong number of parameters in parameterized type
  46. * - generic type with one type parameter
  47. * - generic type with n type parameters
  48. * - generic type with bounds [extends, extends + i/f's]
  49. * - generic type with wrong number of type params
  50. * - wildcards in bounds
  51. * within
  52. * - as above, but allows parameterized type
  53. * - wildcards in type parameters
  54. * this
  55. * - no type vars
  56. * - parameterized types
  57. * - implements
  58. * - instanceof
  59. * target
  60. * - as this
  61. * args
  62. * - as this/target, plus...
  63. * - known static match
  64. * - known static match fail
  65. * - maybe match with unchecked warning
  66. * get & set
  67. * - parameterized type
  68. * - generic type
  69. * - return type is type variable
  70. * - return type is parameterized
  71. * initialization, preinitialization
  72. * - type variables as type params
  73. * - no join points for parameterized types
  74. * execution, withincode
  75. * - wait till we get there!
  76. * call
  77. * - wait till we get there!
  78. */
  79. public static Test suite() {
  80. return XMLBasedAjcTestCase.loadSuite(GenericsTests.class);
  81. }
  82. protected File getSpecFile() {
  83. return new File("../tests/src/org/aspectj/systemtest/ajc150/ajc150.xml");
  84. }
  85. public void testITDReturningParameterizedType() {
  86. runTest("ITD with parameterized type");
  87. }
  88. public void testPR91267_1() {
  89. runTest("NPE using generic methods in aspects 1");
  90. }
  91. public void testPR91267_2() {
  92. runTest("NPE using generic methods in aspects 2");
  93. }
  94. public void testPR91053() {
  95. runTest("Generics problem with Set");
  96. }
  97. public void testPR87282() {
  98. runTest("Compilation error on generic member introduction");
  99. }
  100. public void testPR88606() {
  101. runTest("Parameterized types on introduced fields not correctly recognized");
  102. }
  103. public void testPR97763() {
  104. runTest("ITD method with generic arg");
  105. }
  106. public void testGenericsBang_pr95993() {
  107. runTest("NPE at ClassScope.java:660 when compiling generic class");
  108. }
  109. // generic aspects
  110. public void testPR96220_GenericAspects1() {
  111. runTest("generic aspects - 1");
  112. }
  113. public void testPR96220_GenericAspects2() {
  114. runTest("generic aspects - 2");
  115. }
  116. public void testPR96220_GenericAspects3() {
  117. runTest("generic aspects - 3");
  118. }
  119. // Developers notebook
  120. // ITD of generic members
  121. public void testItdNonStaticMethod() {
  122. runTest("Parsing generic ITDs - 1");
  123. }
  124. public void testItdStaticMethod() {
  125. runTest("Parsing generic ITDs - 2");
  126. }
  127. public void testItdCtor() {
  128. runTest("Parsing generic ITDs - 3");
  129. }
  130. public void testItdComplexMethod() {
  131. runTest("Parsing generic ITDs - 4");
  132. }
  133. public void testItdNonStaticMember() {
  134. runTest("itd of non static member");
  135. }
  136. public void testItdStaticMember() {
  137. runTest("itd of static member");
  138. }
  139. // public void testItdOnGenericType() {
  140. // runTest("ITDs on generic type");
  141. // }
  142. //
  143. // public void testItdUsingTypeParameter() {
  144. // runTest("itd using type parameter");
  145. // }
  146. //
  147. // public void testItdIncorrectlyUsingTypeParameter() {
  148. // runTest("itd incorrectly using type parameter");
  149. // }
  150. // ----------------------------------------------------------------------------------------
  151. // generic declare parents tests
  152. // ----------------------------------------------------------------------------------------
  153. public void testPR96220_GenericDecp() {
  154. runTest("generic decp - simple");
  155. verifyClassSignature("Basic","Ljava/lang/Object;LJ<Ljava/lang/Double;>;LI<Ljava/lang/Double;>;");
  156. }
  157. // Both the existing type decl and the one adding via decp are parameterized
  158. public void testGenericDecpMultipleVariantsOfAParameterizedType1() {
  159. runTest("generic decp - implementing two variants #1");
  160. }
  161. // Existing type decl is raw and the one added via decp is parameterized
  162. public void testGenericDecpMultipleVariantsOfAParameterizedType2() {
  163. runTest("generic decp - implementing two variants #2");
  164. }
  165. // Existing type decl is parameterized and the one added via decp is raw
  166. public void testGenericDecpMultipleVariantsOfAParameterizedType3() {
  167. runTest("generic decp - implementing two variants #3");
  168. }
  169. // decp is parameterized but it does match the one already on the type
  170. public void testGenericDecpMultipleVariantsOfAParameterizedType4() {
  171. runTest("generic decp - implementing two variants #4");
  172. }
  173. // same as above four tests for binary weaving
  174. public void testGenericDecpMultipleVariantsOfAParameterizedType1_binaryWeaving() {
  175. runTest("generic decp binary - implementing two variants #1");
  176. }
  177. public void testGenericDecpMultipleVariantsOfAParameterizedType2_binaryWeaving() {
  178. runTest("generic decp binary - implementing two variants #2");
  179. }
  180. // Existing type decl is parameterized and the one added via decp is raw
  181. public void testGenericDecpMultipleVariantsOfAParameterizedType3_binaryWeaving() {
  182. runTest("generic decp binary - implementing two variants #3");
  183. }
  184. // decp is parameterized but it does match the one already on the type
  185. public void testGenericDecpMultipleVariantsOfAParameterizedType4_binaryWeaving() {
  186. runTest("generic decp binary - implementing two variants #4");
  187. }
  188. //
  189. // public void testGenericDecpIncorrectNumberOfTypeParams() {
  190. // runTest("generic decp - incorrect number of type parameters");
  191. // }
  192. //
  193. // public void testGenericDecpSpecifyingBounds() {
  194. // runTest("generic decp - specifying bounds");
  195. // }
  196. //
  197. // public void testGenericDecpViolatingBounds() {
  198. // runTest("generic decp - specifying bounds but breaking them");
  199. // }
  200. // need separate compilation test to verify signatures are ok
  201. //
  202. // public void testIllegalGenericDecp() {
  203. // runTest("illegal generic decp");
  204. // }
  205. //
  206. // public void testPR95992_TypeResolvingProblemWithGenerics() {
  207. // runTest("Problems resolving type name inside generic class");
  208. // }
  209. // missing tests in here:
  210. // 1. public ITDs and separate compilation - are the signatures correct for the new public members?
  211. // 2. ITDF
  212. // -- Pointcut tests...
  213. public void testHandlerWithGenerics() {
  214. runTest("handler pcd and generics / type vars");
  215. }
  216. public void testPointcutsThatDontAllowTypeVars() {
  217. runTest("pointcuts that dont allow type vars");
  218. }
  219. public void testParameterizedTypesInAtPCDs() {
  220. runTest("annotation pcds with parameterized types");
  221. }
  222. public void testAnnotationPatternsWithParameterizedTypes() {
  223. runTest("annotation patterns with parameterized types");
  224. }
  225. public void testExecutionWithRawType() {
  226. runTest("execution pcd with raw type matching");
  227. }
  228. public void testExecutionWithRawSignature() {
  229. runTest("execution pcd with raw signature matching");
  230. }
  231. public void testExecutionWithGenericDeclaringTypeAndErasedParameterTypes() {
  232. runTest("execution pcd with generic declaring type and erased parameter types");
  233. }
  234. // not passing yet...
  235. // public void testExecutionWithGenericSignature() {
  236. // runTest("execution pcd with generic signature matching");
  237. // }
  238. // --- helpers
  239. // Check the signature attribute on a class is correct
  240. private void verifyClassSignature(String classname,String sig) {
  241. try {
  242. ClassPath cp =
  243. new ClassPath(ajc.getSandboxDirectory() + File.pathSeparator + System.getProperty("java.class.path"));
  244. SyntheticRepository sRepos = SyntheticRepository.getInstance(cp);
  245. JavaClass clazz = sRepos.loadClass(classname);
  246. Signature sigAttr = null;
  247. Attribute[] attrs = clazz.getAttributes();
  248. for (int i = 0; i < attrs.length; i++) {
  249. Attribute attribute = attrs[i];
  250. if (attribute.getName().equals("Signature")) sigAttr = (Signature)attribute;
  251. }
  252. assertTrue("Failed to find signature attribute for class "+classname,sigAttr!=null);
  253. assertTrue("Expected signature to be '"+sig+"' but was '"+sigAttr.getSignature()+"'",
  254. sigAttr.getSignature().equals(sig));
  255. } catch (ClassNotFoundException e) {
  256. fail("Couldn't find class "+classname+" in the sandbox directory.");
  257. }
  258. }
  259. }