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.

AjAST5Test.java 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /********************************************************************
  2. * Copyright (c) 2006 Contributors. All rights reserved.
  3. * This program and the accompanying materials are made available
  4. * under the terms of the Eclipse Public License v 2.0
  5. * which accompanies this distribution and is available at
  6. * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
  7. *
  8. * Contributors: IBM Corporation - initial API and implementation
  9. * Helen Hawkins - initital version
  10. * Matthew Webster - moved tests
  11. *******************************************************************/
  12. package org.aspectj.tools.ajc;
  13. import java.util.List;
  14. import org.aspectj.org.eclipse.jdt.core.dom.AST;
  15. import org.aspectj.org.eclipse.jdt.core.dom.AbstractTypePattern;
  16. import org.aspectj.org.eclipse.jdt.core.dom.AjAST;
  17. import org.aspectj.org.eclipse.jdt.core.dom.AjTypeDeclaration;
  18. import org.aspectj.org.eclipse.jdt.core.dom.AspectDeclaration;
  19. import org.aspectj.org.eclipse.jdt.core.dom.ChildListPropertyDescriptor;
  20. import org.aspectj.org.eclipse.jdt.core.dom.ChildPropertyDescriptor;
  21. import org.aspectj.org.eclipse.jdt.core.dom.DeclareParentsDeclaration;
  22. import org.aspectj.org.eclipse.jdt.core.dom.DefaultTypePattern;
  23. import org.aspectj.org.eclipse.jdt.core.dom.PerTypeWithin;
  24. import org.aspectj.org.eclipse.jdt.core.dom.SimplePropertyDescriptor;
  25. public class AjAST5Test extends AjASTTestCase {
  26. public void testInternalAspectDeclaration() {
  27. AjAST ajast = createAjAST();
  28. AspectDeclaration d = ajast.newAspectDeclaration();
  29. List props = AspectDeclaration.propertyDescriptors(AST.JLS3);
  30. for (Object o : props) {
  31. if (o instanceof ChildPropertyDescriptor) {
  32. ChildPropertyDescriptor element = (ChildPropertyDescriptor) o;
  33. if (element.getId().equals("perClause")) {
  34. assertNull("AspectDeclaration's " + element.getId() + " property" +
  35. "should be null since we haven't set it yet",
  36. d.getStructuralProperty(element));
  37. }
  38. } else if (o instanceof SimplePropertyDescriptor) {
  39. SimplePropertyDescriptor element = (SimplePropertyDescriptor) o;
  40. assertNotNull("AspectDeclaration's " + element.getId() + " property" +
  41. "should not be null since it is a boolean",
  42. d.getStructuralProperty(element));
  43. }
  44. }
  45. for (Object o : props) {
  46. if (o instanceof ChildPropertyDescriptor) {
  47. ChildPropertyDescriptor element = (ChildPropertyDescriptor) o;
  48. if (element.getId().equals("perClause")) {
  49. PerTypeWithin ptw = ajast.newPerTypeWithin();
  50. d.setStructuralProperty(element, ptw);
  51. assertEquals("AspectDeclaration's perClause property should" +
  52. " now be a perTypeWithin", ptw, d.getStructuralProperty(element));
  53. } else if (element.getId().equals("javadoc")) {
  54. // do nothing since makes no sense to have javadoc
  55. }
  56. } else if (o instanceof SimplePropertyDescriptor) {
  57. SimplePropertyDescriptor element = (SimplePropertyDescriptor) o;
  58. if (element.getId().equals("privileged")) {
  59. Boolean b = Boolean.TRUE;
  60. d.setStructuralProperty(element, b);
  61. assertEquals("AspectDeclaration's isPrivileged property should" +
  62. " now be a boolean", b, d.getStructuralProperty(element));
  63. }
  64. }
  65. }
  66. }
  67. public void testInternalAjTypeDeclaration() {
  68. AjAST ajast = createAjAST();
  69. AjTypeDeclaration d = ajast.newAjTypeDeclaration();
  70. List props = AjTypeDeclaration.propertyDescriptors(AST.JLS3);
  71. for (Object o : props) {
  72. if (o instanceof SimplePropertyDescriptor) {
  73. SimplePropertyDescriptor element = (SimplePropertyDescriptor) o;
  74. if (element.getId().equals("aspect")) {
  75. assertNotNull("AjTypeDeclaration's " + element.getId() + " property" +
  76. " should not be null since it is a boolean",
  77. d.getStructuralProperty(element));
  78. }
  79. }
  80. }
  81. for (Object o : props) {
  82. if (o instanceof SimplePropertyDescriptor) {
  83. SimplePropertyDescriptor element = (SimplePropertyDescriptor) o;
  84. if (element.getId().equals("aspect")) {
  85. Boolean b = Boolean.TRUE;
  86. d.setStructuralProperty(element, b);
  87. assertEquals("AjTypeDeclaration's aspect property should" +
  88. " now be a SignaturePattern", b, d.getStructuralProperty(element));
  89. }
  90. }
  91. }
  92. }
  93. public void testInternalDeclareParentsDeclaration() {
  94. AjAST ajast = createAjAST();
  95. DeclareParentsDeclaration d = ajast.newDeclareParentsDeclaration();
  96. List props = DeclareParentsDeclaration.propertyDescriptors(AST.JLS3);
  97. for (Object o : props) {
  98. if (o instanceof ChildPropertyDescriptor) {
  99. ChildPropertyDescriptor element = (ChildPropertyDescriptor) o;
  100. assertNull("DeclareParentsDeclaration's " + element.getId() + " property" +
  101. "should be null since we haven't set it yet",
  102. d.getStructuralProperty(element));
  103. } else if (o instanceof ChildListPropertyDescriptor) {
  104. ChildListPropertyDescriptor element = (ChildListPropertyDescriptor) o;
  105. assertNotNull("DeclareParentsDeclaration's " + element.getId() + " property" +
  106. "should not be null since it is a list",
  107. d.getStructuralProperty(element));
  108. assertEquals("should only be able to put TypePattern's into the list",
  109. AbstractTypePattern.class, element.getElementType());
  110. } else if (o instanceof SimplePropertyDescriptor) {
  111. SimplePropertyDescriptor element = (SimplePropertyDescriptor) o;
  112. assertNotNull("DeclareParentsDeclaration's " + element.getId() + " property" +
  113. "should not be null since it is a boolean",
  114. d.getStructuralProperty(element));
  115. } else {
  116. fail("unknown PropertyDescriptor associated with DeclareParentsDeclaration: " + o);
  117. }
  118. }
  119. for (Object o : props) {
  120. if (o instanceof ChildPropertyDescriptor) {
  121. ChildPropertyDescriptor element = (ChildPropertyDescriptor) o;
  122. if (element.getId().equals("childTypePattern")) {
  123. DefaultTypePattern dtp = ajast.newDefaultTypePattern();
  124. d.setStructuralProperty(element, dtp);
  125. assertEquals("DeclareParentsDeclaration's typePattern property should" +
  126. " now be a DefaultTypePattern", dtp, d.getStructuralProperty(element));
  127. } else if (element.getId().equals("javadoc")) {
  128. // do nothing since makes no sense to have javadoc
  129. } else {
  130. fail("unknown property for DeclareParentsDeclaration");
  131. }
  132. } else if (o instanceof SimplePropertyDescriptor) {
  133. SimplePropertyDescriptor element = (SimplePropertyDescriptor) o;
  134. if (element.getId().equals("isExtends")) {
  135. Boolean b = Boolean.TRUE;
  136. d.setStructuralProperty(element, b);
  137. assertEquals("DeclareParentsDeclaration's isExtends property should" +
  138. " now be a boolean", b, d.getStructuralProperty(element));
  139. }
  140. }
  141. }
  142. }
  143. }