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.

Ajc170Tests.java 8.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. /*******************************************************************************
  2. * Copyright (c) 2008-2012 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.ajc170;
  12. import org.aspectj.apache.bcel.classfile.Field;
  13. import org.aspectj.apache.bcel.classfile.JavaClass;
  14. import org.aspectj.testing.XMLBasedAjcTestCase;
  15. import org.aspectj.weaver.TypeFactory;
  16. import org.aspectj.weaver.UnresolvedType;
  17. import org.aspectj.weaver.World;
  18. import org.aspectj.weaver.internal.tools.StandardPointcutExpressionImpl;
  19. import org.aspectj.weaver.patterns.Pointcut;
  20. import org.aspectj.weaver.patterns.PointcutRewriter;
  21. import org.aspectj.weaver.reflect.ReflectionWorld;
  22. import org.aspectj.weaver.tools.StandardPointcutParser;
  23. import junit.framework.Test;
  24. /**
  25. * @author Andy Clement
  26. */
  27. public class Ajc170Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
  28. // public void testLostAnnos_377130() {
  29. // runTest("missing annos on priv aspects");
  30. // }
  31. //
  32. // public void testLostAnnos_377130_2() {
  33. // runTest("missing annos on priv aspects - 2");
  34. // }
  35. public void testCovariantGenerics382435_1() {
  36. runTest("covariant generic itds 1");
  37. }
  38. public void testCovariantGenerics382435_2() {
  39. runTest("covariant generic itds 2");
  40. }
  41. public void testCovariantGenericsItd382189_1() {
  42. runTest("covariant generics 1");
  43. }
  44. public void testCovariantGenericsItd382189_2() {
  45. runTest("covariant generics 2");
  46. }
  47. public void testCovariantGenericsItd382189_3() {
  48. runTest("covariant generics 3");
  49. }
  50. public void testCovariantGenericsItd382189() {
  51. runTest("covariant generics");
  52. }
  53. public void testGenericAspectAround382723() {
  54. runTest("generic aspect");
  55. }
  56. public void testGenericAspectAround382723_2() {
  57. runTest("generic aspect 2");
  58. }
  59. public void testGenericAspectAround382723_3() {
  60. runTest("generic aspect 3");
  61. }
  62. public void testGenericAspectAround382723_4() {
  63. runTest("generic aspect 4");
  64. }
  65. public void testAttributeErrorJ7() {
  66. runTest("attribute issue with J7");
  67. }
  68. public void testSwitchOnEnum() {
  69. runTest("switch on enum");
  70. }
  71. public void testDecAtFieldOrderingLTW1() {
  72. runTest("dec at field ordering ltw 1");
  73. }
  74. public void testDecAtFieldOrdering1() {
  75. runTest("dec at field ordering 1");
  76. }
  77. // public void testDecAtFieldOrdering2() {
  78. // runTest("dec at field ordering 2");
  79. // }
  80. public void testXmlDefsDeclareAnnoType() {
  81. runTest("xml defined dec anno - type");
  82. }
  83. public void testXmlDefsDeclareAnnoMethod() {
  84. runTest("xml defined dec at method");
  85. }
  86. // anno not runtime vis
  87. public void testXmlDefsDeclareAnnoMethod2() {
  88. runTest("xml defined dec at method 2");
  89. }
  90. public void testXmlDefsDeclareAnnoField() {
  91. runTest("xml defined dec at field");
  92. }
  93. public void testXmlDefsDeclareAnnoFieldVariants1() {
  94. runTest("xml defined dec anno - variants 1");
  95. }
  96. public void testXmlDefsDeclareAnnoFieldVariants2() {
  97. runTest("xml defined dec anno - variants 2");
  98. }
  99. public void testXmlDefsDeclareAnnoFieldMultipleValues() {
  100. runTest("xml defined dec anno - multiple values");
  101. }
  102. public void testXmlDefsDeclareAnnoFieldMultipleValuesAndSpaces() {
  103. runTest("xml defined dec anno - multiple values and spaces");
  104. }
  105. public void testPointcutExpense_374964() {
  106. // check a declaring type being specified causes the call() to be considered cheaper than this()
  107. World world = new ReflectionWorld(true, getClass().getClassLoader());
  108. StandardPointcutParser pointcutParser = StandardPointcutParser.getPointcutParserSupportingAllPrimitives(world);
  109. StandardPointcutExpressionImpl pointcutExpression = (StandardPointcutExpressionImpl)pointcutParser.parsePointcutExpression("call(* *(..)) && this(Object)");
  110. Pointcut pc = pointcutExpression.getUnderlyingPointcut();
  111. Pointcut newp = new PointcutRewriter().rewrite(pc);
  112. // no declaring type so this() is considered cheaper
  113. assertEquals("(this(java.lang.Object) && call(* *(..)))",newp.toString());
  114. pointcutExpression = (StandardPointcutExpressionImpl)pointcutParser.parsePointcutExpression("call(* String.*(..)) && this(Object)");
  115. pc = pointcutExpression.getUnderlyingPointcut();
  116. newp = new PointcutRewriter().rewrite(pc);
  117. // declaring type, so call() is cheaper
  118. assertEquals("(call(* java.lang.String.*(..)) && this(java.lang.Object))",newp.toString());
  119. pointcutExpression = (StandardPointcutExpressionImpl)pointcutParser.parsePointcutExpression("this(Object) && call(* *(..)) && call(* String.*(..))");
  120. pc = pointcutExpression.getUnderlyingPointcut();
  121. newp = new PointcutRewriter().rewrite(pc);
  122. // more complex example, mix of them
  123. assertEquals("((call(* java.lang.String.*(..)) && this(java.lang.Object)) && call(* *(..)))",newp.toString());
  124. }
  125. public void testBCExceptionAnnoDecp_371998() {
  126. runTest("BCException anno decp");
  127. }
  128. public void testTransientTjpFields()throws Exception {
  129. runTest("transient tjp fields");
  130. JavaClass jc = getClassFrom(ajc.getSandboxDirectory(), "Code");
  131. Field[] fs = jc.getFields();
  132. //private static final org.aspectj.lang.JoinPoint$StaticPart ajc$tjp_0 [Synthetic]
  133. //private static final org.aspectj.lang.JoinPoint$StaticPart ajc$tjp_1 [Synthetic]
  134. for (Field f: fs) {
  135. if (!f.isTransient()) {
  136. fail("Field should be transient: "+f);
  137. }
  138. }
  139. }
  140. public void testGenericsWithTwoTypeParamsOneWildcard() {
  141. UnresolvedType ut;
  142. ut = TypeFactory.createTypeFromSignature("LFoo<**>;");
  143. assertEquals(2,ut.getTypeParameters().length);
  144. ut = TypeFactory.createTypeFromSignature("LFoo<***>;");
  145. assertEquals(3,ut.getTypeParameters().length);
  146. ut = TypeFactory.createTypeFromSignature("LFoo<TP;*+Ljava/lang/String;>;");
  147. assertEquals(2,ut.getTypeParameters().length);
  148. ut = TypeFactory.createTypeFromSignature("LFoo<*+Ljava/lang/String;TP;>;");
  149. assertEquals(2,ut.getTypeParameters().length);
  150. ut = TypeFactory.createTypeFromSignature("LFoo<*+Ljava/lang/String;TP;>;");
  151. assertEquals(2,ut.getTypeParameters().length);
  152. ut = TypeFactory.createTypeFromSignature("LFoo<*TT;>;");
  153. assertEquals(2,ut.getTypeParameters().length);
  154. ut = TypeFactory.createTypeFromSignature("LFoo<[I>;");
  155. assertEquals(1,ut.getTypeParameters().length);
  156. ut = TypeFactory.createTypeFromSignature("LFoo<[I[Z>;");
  157. assertEquals(2,ut.getTypeParameters().length);
  158. }
  159. public void testPerThis() {
  160. runTest("perthis");
  161. }
  162. public void testPerTarget() {
  163. runTest("pertarget");
  164. }
  165. public void testPerCflow() {
  166. runTest("percflow");
  167. }
  168. public void testPerTypeWithin() {
  169. runTest("pertypewithin");
  170. }
  171. // not specifying -1.7
  172. public void testDiamond1() {
  173. runTest("diamond 1");
  174. }
  175. public void testDiamond2() {
  176. runTest("diamond 2");
  177. }
  178. public void testDiamondItd1() {
  179. runTest("diamond itd 1");
  180. }
  181. public void testLiterals1() {
  182. runTest("literals 1");
  183. }
  184. public void testLiterals2() {
  185. runTest("literals 2");
  186. }
  187. public void testLiteralsItd1() {
  188. runTest("literals itd 1");
  189. }
  190. public void testStringSwitch1() {
  191. runTest("string switch 1");
  192. }
  193. public void testStringSwitch2() {
  194. runTest("string switch 2");
  195. }
  196. public void testMultiCatch1() {
  197. runTest("multi catch 1");
  198. }
  199. public void testMultiCatch2() {
  200. runTest("multi catch 2");
  201. }
  202. public void testMultiCatchWithHandler1() {
  203. runTest("multi catch with handler 1");
  204. }
  205. public void testMultiCatchAspect1() {
  206. runTest("multi catch aspect 1");
  207. }
  208. // public void testMultiCatchWithHandler2() {
  209. // runTest("multi catch with handler 2");
  210. // }
  211. public void testSanity1() {
  212. runTest("sanity 1");
  213. }
  214. public void testMissingImpl_363979() {
  215. runTest("missing impl");
  216. }
  217. public void testMissingImpl_363979_2() {
  218. runTest("missing impl 2");
  219. }
  220. public void testStackOverflow_364380() {
  221. runTest("stackoverflow");
  222. }
  223. // public void testTryResources1() {
  224. // runTest("try resources 1");
  225. // }
  226. //
  227. // public void testTryResources2() {
  228. // runTest("try resources 2");
  229. // }
  230. // ---
  231. public static Test suite() {
  232. return XMLBasedAjcTestCase.loadSuite(Ajc170Tests.class);
  233. }
  234. @Override
  235. protected java.net.URL getSpecFile() {
  236. return getClassResource("ajc170.xml");
  237. }
  238. }