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.

AsmDeclarationsTest.java 9.2KB

15 年之前
15 年之前
15 年之前
15 年之前
15 年之前
15 年之前
15 年之前
15 年之前
15 年之前
15 年之前
15 年之前
15 年之前
15 年之前
15 年之前
15 年之前
15 年之前
15 年之前
15 年之前
15 年之前
15 年之前
15 年之前
15 年之前
15 年之前
15 年之前
15 年之前
15 年之前
15 年之前
15 年之前
15 年之前
15 年之前
15 年之前
15 年之前
15 年之前
15 年之前
15 年之前
15 年之前
15 年之前
15 年之前
15 年之前
15 年之前
15 年之前
15 年之前
15 年之前
15 年之前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /* *******************************************************************
  2. * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Eclipse Public License v 2.0
  6. * which accompanies this distribution and is available at
  7. * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
  8. *
  9. * ******************************************************************/
  10. package org.aspectj.ajde.core.tests.model;
  11. import java.io.File;
  12. import org.aspectj.ajde.core.AjdeCoreTestCase;
  13. import org.aspectj.ajde.core.TestCompilerConfiguration;
  14. import org.aspectj.asm.AsmManager;
  15. import org.aspectj.asm.IHierarchy;
  16. import org.aspectj.asm.IProgramElement;
  17. public class AsmDeclarationsTest extends AjdeCoreTestCase {
  18. // private AsmManager manager = null;
  19. private IHierarchy model = null;
  20. private final String[] files = new String[] { "ModelCoverage.java", "pkg" + File.separator + "InPackage.java" };
  21. private TestCompilerConfiguration compilerConfig;
  22. protected void setUp() throws Exception {
  23. super.setUp();
  24. initialiseProject("coverage");
  25. compilerConfig = (TestCompilerConfiguration) getCompiler().getCompilerConfiguration();
  26. compilerConfig.setProjectSourceFiles(getSourceFileList(files));
  27. compilerConfig.setNonStandardOptions("-Xset:minimalModel=false");
  28. doBuild();
  29. // manager = AsmManager.lastActiveStructureModel;
  30. model = AsmManager.lastActiveStructureModel.getHierarchy();
  31. }
  32. protected void tearDown() throws Exception {
  33. super.tearDown();
  34. compilerConfig = null;
  35. model = null;
  36. }
  37. public void testRoot() {
  38. IProgramElement root = model.getRoot();
  39. assertNotNull(root);
  40. assertEquals("Expected root to be named 'coverage' but found " + root.toLabelString(), root.toLabelString(), "coverage");
  41. }
  42. public void testAspectAccessibility() {
  43. IProgramElement packageAspect = model.findElementForType(null, "AdviceNamingCoverage");
  44. assertNotNull(packageAspect);
  45. assertEquals(IProgramElement.Accessibility.PACKAGE, packageAspect.getAccessibility());
  46. assertEquals("aspect should not have public in it's signature", "aspect AdviceNamingCoverage",
  47. packageAspect.getSourceSignature());
  48. }
  49. public void testStaticModifiers() {
  50. IProgramElement aspect = model.findElementForType(null, "ModifiersCoverage");
  51. assertNotNull(aspect);
  52. IProgramElement staticA = model.findElementForSignature(aspect, IProgramElement.Kind.FIELD, "staticA");
  53. assertTrue(staticA.getModifiers().contains(IProgramElement.Modifiers.STATIC));
  54. IProgramElement finalA = model.findElementForSignature(aspect, IProgramElement.Kind.FIELD, "finalA");
  55. assertTrue(!finalA.getModifiers().contains(IProgramElement.Modifiers.STATIC));
  56. assertTrue(finalA.getModifiers().contains(IProgramElement.Modifiers.FINAL));
  57. }
  58. public void testFileInPackageAndDefaultPackage() {
  59. IProgramElement root = model.getRoot();
  60. assertEquals(root.toLabelString(), "coverage");
  61. IProgramElement pkg = root.getChildren().get(1);
  62. assertEquals(pkg.toLabelString(), "pkg");
  63. assertEquals(pkg.getChildren().get(0).toLabelString(), "InPackage.java");
  64. assertEquals(root.getChildren().get(0).getChildren().get(0).toLabelString(),
  65. "ModelCoverage.java");
  66. }
  67. public void testDeclares() {
  68. IProgramElement node = model.getRoot();
  69. assertNotNull(node);
  70. IProgramElement aspect = model.findElementForType(null, "DeclareCoverage");
  71. assertNotNull(aspect);
  72. String label = "declare error: \"Illegal construct..\"";
  73. IProgramElement decErrNode = model.findElementForSignature(aspect, IProgramElement.Kind.DECLARE_ERROR, "declare error");
  74. assertNotNull(decErrNode);
  75. assertEquals(decErrNode.toLabelString(), label);
  76. String decWarnMessage = "declare warning: \"Illegal call.\"";
  77. IProgramElement decWarnNode = model
  78. .findElementForSignature(aspect, IProgramElement.Kind.DECLARE_WARNING, "declare warning");
  79. assertNotNull(decWarnNode);
  80. assertEquals(decWarnNode.toLabelString(), decWarnMessage);
  81. String decParentsMessage = "declare parents: implements Serializable";
  82. IProgramElement decParentsNode = model.findElementForSignature(aspect, IProgramElement.Kind.DECLARE_PARENTS,
  83. "declare parents");
  84. assertNotNull(decParentsNode);
  85. assertEquals(decParentsNode.toLabelString(), decParentsMessage);
  86. // check the next two relative to this one
  87. int declareIndex = decParentsNode.getParent().getChildren().indexOf(decParentsNode);
  88. String decParentsPtnMessage = "declare parents: extends Observable";
  89. assertEquals(decParentsPtnMessage, aspect.getChildren().get(declareIndex + 1).toLabelString());
  90. String decParentsTPMessage = "declare parents: extends Observable";
  91. assertEquals(decParentsTPMessage, aspect.getChildren().get(declareIndex + 2).toLabelString());
  92. String decSoftMessage = "declare soft: SizeException";
  93. IProgramElement decSoftNode = model.findElementForSignature(aspect, IProgramElement.Kind.DECLARE_SOFT, "declare soft");
  94. assertNotNull(decSoftNode);
  95. assertEquals(decSoftNode.toLabelString(), decSoftMessage);
  96. String decPrecMessage = "declare precedence: AdviceCoverage, InterTypeDecCoverage, <type pattern>";
  97. IProgramElement decPrecNode = model.findElementForSignature(aspect, IProgramElement.Kind.DECLARE_PRECEDENCE,
  98. "declare precedence");
  99. assertNotNull(decPrecNode);
  100. assertEquals(decPrecNode.toLabelString(), decPrecMessage);
  101. }
  102. public void testInterTypeMemberDeclares() {
  103. IProgramElement node = model.getRoot();
  104. assertNotNull(node);
  105. IProgramElement aspect = model.findElementForType(null, "InterTypeDecCoverage");
  106. assertNotNull(aspect);
  107. String fieldMsg = "Point.xxx";
  108. IProgramElement fieldNode = model.findElementForLabel(aspect, IProgramElement.Kind.INTER_TYPE_FIELD, fieldMsg);
  109. assertNotNull(fieldNode);
  110. assertEquals(fieldNode.toLabelString(), fieldMsg);
  111. String methodMsg = "Point.check(int,Line)";
  112. IProgramElement methodNode = model.findElementForLabel(aspect, IProgramElement.Kind.INTER_TYPE_METHOD, methodMsg);
  113. assertNotNull(methodNode);
  114. assertEquals(methodNode.toLabelString(), methodMsg);
  115. // TODO: enable
  116. // String constructorMsg = "Point.new(int, int, int)";
  117. // ProgramElementNode constructorNode = model.findNode(aspect, ProgramElementNode.Kind.INTER_TYPE_CONSTRUCTOR,
  118. // constructorMsg);
  119. // assertNotNull(constructorNode);
  120. // assertEquals(constructorNode.toLabelString(), constructorMsg);
  121. }
  122. public void testPointcuts() {
  123. IProgramElement node = model.getRoot();
  124. assertNotNull(node);
  125. IProgramElement aspect = model.findElementForType(null, "AdviceNamingCoverage");
  126. assertNotNull(aspect);
  127. String ptct = "named()";
  128. IProgramElement ptctNode = model.findElementForSignature(aspect, IProgramElement.Kind.POINTCUT, ptct);
  129. assertNotNull(ptctNode);
  130. assertEquals(ptctNode.toLabelString(), ptct);
  131. String params = "namedWithArgs(int,int)";
  132. IProgramElement paramsNode = model.findElementForSignature(aspect, IProgramElement.Kind.POINTCUT, params);
  133. assertNotNull(paramsNode);
  134. assertEquals(paramsNode.toLabelString(), params);
  135. }
  136. public void testAbstract() {
  137. IProgramElement node = model.getRoot();
  138. assertNotNull(node);
  139. IProgramElement aspect = model.findElementForType(null, "AbstractAspect");
  140. assertNotNull(aspect);
  141. String abst = "abPtct()";
  142. IProgramElement abstNode = model.findElementForSignature(aspect, IProgramElement.Kind.POINTCUT, abst);
  143. assertNotNull(abstNode);
  144. assertEquals(abstNode.toLabelString(), abst);
  145. }
  146. public void testAdvice() {
  147. IProgramElement node = model.getRoot();
  148. assertNotNull(node);
  149. IProgramElement aspect = model.findElementForType(null, "AdviceNamingCoverage");
  150. assertNotNull(aspect);
  151. String anon = "before(): <anonymous pointcut>";
  152. IProgramElement anonNode = model.findElementForLabel(aspect, IProgramElement.Kind.ADVICE, anon);
  153. assertNotNull(anonNode);
  154. assertEquals(anonNode.toLabelString(), anon);
  155. String named = "before(): named..";
  156. IProgramElement namedNode = model.findElementForLabel(aspect, IProgramElement.Kind.ADVICE, named);
  157. assertNotNull(namedNode);
  158. assertEquals(namedNode.toLabelString(), named);
  159. String namedWithOneArg = "around(int): namedWithOneArg..";
  160. IProgramElement namedWithOneArgNode = model.findElementForLabel(aspect, IProgramElement.Kind.ADVICE, namedWithOneArg);
  161. assertNotNull(namedWithOneArgNode);
  162. assertEquals(namedWithOneArgNode.toLabelString(), namedWithOneArg);
  163. String afterReturning = "afterReturning(int,int): namedWithArgs..";
  164. IProgramElement afterReturningNode = model.findElementForLabel(aspect, IProgramElement.Kind.ADVICE, afterReturning);
  165. assertNotNull(afterReturningNode);
  166. assertEquals(afterReturningNode.toLabelString(), afterReturning);
  167. String around = "around(int): namedWithOneArg..";
  168. IProgramElement aroundNode = model.findElementForLabel(aspect, IProgramElement.Kind.ADVICE, around);
  169. assertNotNull(aroundNode);
  170. assertEquals(aroundNode.toLabelString(), around);
  171. String compAnon = "before(int): <anonymous pointcut>..";
  172. IProgramElement compAnonNode = model.findElementForLabel(aspect, IProgramElement.Kind.ADVICE, compAnon);
  173. assertNotNull(compAnonNode);
  174. assertEquals(compAnonNode.toLabelString(), compAnon);
  175. String compNamed = "before(int): named()..";
  176. IProgramElement compNamedNode = model.findElementForLabel(aspect, IProgramElement.Kind.ADVICE, compNamed);
  177. assertNotNull(compNamedNode);
  178. assertEquals(compNamedNode.toLabelString(), compNamed);
  179. }
  180. }