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.

NewFeatures.java 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*******************************************************************************
  2. * Copyright (c) 2010 Lucierna
  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. * Abraham Nevado - initial API and implementation
  10. *******************************************************************************/
  11. package org.aspectj.systemtest.ajc1610;
  12. import java.io.File;
  13. import junit.framework.Test;
  14. import org.aspectj.apache.bcel.classfile.JavaClass;
  15. import org.aspectj.apache.bcel.classfile.Method;
  16. import org.aspectj.testing.XMLBasedAjcTestCase;
  17. public class NewFeatures extends org.aspectj.testing.XMLBasedAjcTestCase {
  18. public void testMakeSJPOptimizationLDCNo() {
  19. this.runTest("makeSJP optimization - LDC - No");
  20. try {
  21. JavaClass myClass = getMyClass("B");
  22. Method preClinitMethod = getPreClinitMethod(myClass);
  23. NewFeatures.assertTrue("For 1.4 it must use classForName", preClinitMethod.getCode().toString().contains("forName"));
  24. } catch (Exception e) {
  25. NewFeatures.fail(e.toString());
  26. }
  27. }
  28. @SuppressWarnings("unused")
  29. public void testMakeSJPOptimizationCollapsedSJPYes14() {
  30. this.runTest("makeSJP optimization - Collapsed SJP - Yes 1.4");
  31. try {
  32. JavaClass myClass = getMyClass("B");
  33. } catch (Exception e) {
  34. NewFeatures.fail(e.toString());
  35. }
  36. }
  37. public void testMakeSJPOptimizationLDCYes() {
  38. this.runTest("makeSJP optimization - LDC - Yes");
  39. try {
  40. JavaClass myClass = getMyClass("B");
  41. Method preClinitMethod = getPreClinitMethod(myClass);
  42. NewFeatures.assertTrue("For 1.5 it must not use classForName", !preClinitMethod.getCode().toString()
  43. .contains("forName"));
  44. } catch (Exception e) {
  45. NewFeatures.fail(e.toString());
  46. }
  47. }
  48. public void testMakeSJPOptimizationCollapsedSJPYes() {
  49. this.runTest("makeSJP optimization - Collapsed SJP - Yes");
  50. try {
  51. JavaClass myClass = getMyClass("B");
  52. Method preClinitMethod = getPreClinitMethod(myClass);
  53. NewFeatures.assertTrue("MakedMethodSig MUST not be present",
  54. !preClinitMethod.getCode().toString().contains("makeMethodSig"));
  55. } catch (Exception e) {
  56. NewFeatures.fail(e.toString());
  57. }
  58. }
  59. public void testMakeSJPOptimizationCollapsedSJPNo() {
  60. this.runTest("makeSJP optimization - Collapsed SJP - No");
  61. try {
  62. JavaClass myClass = getMyClass("B");
  63. Method preClinitMethod = getPreClinitMethod(myClass);
  64. NewFeatures.assertTrue("MakedMethodSig required", preClinitMethod.getCode().toString().contains("makeMethodSig"));
  65. } catch (Exception e) {
  66. NewFeatures.fail(e.toString());
  67. }
  68. }
  69. public void testMakeSJPOptimizationNoExceptionNo() {
  70. this.runTest("makeSJP optimization - No Exception - No");
  71. try {
  72. JavaClass myClass = getMyClass("B");
  73. Method preClinitMethod = getPreClinitMethod(myClass);
  74. NewFeatures
  75. .assertTrue(
  76. "MakedMethodSig required",
  77. preClinitMethod
  78. .getCode()
  79. .toString()
  80. .contains(
  81. "invokevirtual org.aspectj.runtime.reflect.Factory.makeMethodSig (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Lorg/aspectj/lang/reflect/MethodSignature;"));
  82. } catch (Exception e) {
  83. NewFeatures.fail(e.toString());
  84. }
  85. }
  86. public void testMakeSJPOptimizationNoExceptionYes() {
  87. this.runTest("makeSJP optimization - No Exception - Yes");
  88. try {
  89. JavaClass myClass = getMyClass("B");
  90. Method preClinitMethod = getPreClinitMethod(myClass);
  91. NewFeatures
  92. .assertTrue(
  93. "MakedMethodSig required",
  94. preClinitMethod
  95. .getCode()
  96. .toString()
  97. .contains(
  98. "org.aspectj.runtime.reflect.Factory.makeSJP (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;I)Lorg/aspectj/lang/JoinPoint$StaticPart;"));
  99. } catch (Exception e) {
  100. NewFeatures.fail(e.toString());
  101. }
  102. }
  103. public void testMakeSJPOptimizationRemoveExtraColon() {
  104. this.runTest("makeSJP optimization - Remove Colon");
  105. try {
  106. JavaClass myClass = getMyClass("B");
  107. Method preClinitMethod = getPreClinitMethod(myClass);
  108. System.out.println(preClinitMethod.getCode().toString());
  109. NewFeatures.assertTrue("MakedMethodSig required",
  110. preClinitMethod.getCode().toString().contains("50: ldc \"java.lang.String\" (108)"));
  111. } catch (Exception e) {
  112. NewFeatures.fail(e.toString());
  113. }
  114. }
  115. // ///////////////////////////////////////
  116. private Method getPreClinitMethod(JavaClass myClass) {
  117. Method lm[] = myClass.getMethods();
  118. for (int i = 0; i < lm.length; i++) {
  119. if (lm[i].getName().equals("ajc$preClinit")) {
  120. return lm[i];
  121. }
  122. }
  123. return null;
  124. }
  125. public static Test suite() {
  126. return XMLBasedAjcTestCase.loadSuite(NewFeatures.class);
  127. }
  128. private JavaClass getMyClass(String className) throws ClassNotFoundException {
  129. return getClassFrom(ajc.getSandboxDirectory(), className);
  130. }
  131. protected File getSpecFile() {
  132. return getClassResource("newfeatures-tests.xml");
  133. }
  134. }