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.

DeclareParentsDeclaration.java 8.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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 - iniital version
  10. *******************************************************************/
  11. package org.aspectj.org.eclipse.jdt.core.dom;
  12. import java.util.ArrayList;
  13. import java.util.List;
  14. /**
  15. * DeclareParentsDeclaration DOM AST node.
  16. *
  17. * Has everything a DeclareDeclaration has plus:
  18. * a TypePattern called 'childTypePattern'
  19. * a boolean called 'isExtends'
  20. * a TypePattern list called 'typePatternsList'
  21. */
  22. public class DeclareParentsDeclaration extends DeclareDeclaration {
  23. public static final ChildPropertyDescriptor JAVADOC_PROPERTY =
  24. internalJavadocPropertyFactory(DeclareParentsDeclaration.class);
  25. public static final ChildPropertyDescriptor CHILD_TYPE_PATTERN_PROPERTY =
  26. new ChildPropertyDescriptor(DeclareParentsDeclaration.class, "childTypePattern", AbstractTypePattern.class, MANDATORY, NO_CYCLE_RISK); //$NON-NLS-1$
  27. public static final SimplePropertyDescriptor IS_EXTENDS_PROPERTY =
  28. new SimplePropertyDescriptor(DeclareParentsDeclaration.class, "isExtends", boolean.class, MANDATORY); //$NON-NLS-1$
  29. public static final ChildListPropertyDescriptor PARENTS_TYPE_PATTERNS_LIST_PROPERTY =
  30. new ChildListPropertyDescriptor(DeclareParentsDeclaration.class, "typePatternsList", AbstractTypePattern.class, NO_CYCLE_RISK); //$NON-NLS-1$
  31. private static final List PROPERTY_DESCRIPTORS_2_0;
  32. private static final List PROPERTY_DESCRIPTORS_3_0;
  33. static {
  34. List propertyList = new ArrayList(4);
  35. createPropertyList(DeclareParentsDeclaration.class, propertyList);
  36. addProperty(JAVADOC_PROPERTY, propertyList);
  37. addProperty(CHILD_TYPE_PATTERN_PROPERTY, propertyList);
  38. addProperty(IS_EXTENDS_PROPERTY, propertyList);
  39. addProperty(PARENTS_TYPE_PATTERNS_LIST_PROPERTY, propertyList);
  40. PROPERTY_DESCRIPTORS_2_0 = reapPropertyList(propertyList);
  41. propertyList = new ArrayList(4);
  42. createPropertyList(DeclareParentsDeclaration.class, propertyList);
  43. addProperty(JAVADOC_PROPERTY, propertyList);
  44. addProperty(CHILD_TYPE_PATTERN_PROPERTY, propertyList);
  45. addProperty(IS_EXTENDS_PROPERTY, propertyList);
  46. addProperty(PARENTS_TYPE_PATTERNS_LIST_PROPERTY, propertyList);
  47. PROPERTY_DESCRIPTORS_3_0 = reapPropertyList(propertyList);
  48. }
  49. private boolean isExtends;
  50. private AbstractTypePattern childTypePattern;
  51. protected ASTNode.NodeList parentTypePatterns =new ASTNode.NodeList(PARENTS_TYPE_PATTERNS_LIST_PROPERTY);
  52. DeclareParentsDeclaration(AST ast) {
  53. this(ast,false);
  54. }
  55. DeclareParentsDeclaration(AST ast, boolean isExtends) {
  56. super(ast);
  57. this.isExtends = isExtends;
  58. }
  59. ASTNode clone0(AST target) {
  60. DeclareParentsDeclaration result = new DeclareParentsDeclaration(target/*,declareDecl*/);
  61. result.setSourceRange(this.getStartPosition(), this.getLength());
  62. result.setJavadoc(
  63. (Javadoc) ASTNode.copySubtree(target, getJavadoc()));
  64. result.setChildTypePattern(
  65. (AbstractTypePattern) ASTNode.copySubtree(target, getChildTypePattern()));
  66. result.setExtends(isExtends());
  67. result.parentTypePatterns().addAll(
  68. ASTNode.copySubtrees(target, parentTypePatterns()));
  69. return result;
  70. }
  71. final boolean subtreeMatch0(ASTMatcher matcher, Object other) {
  72. // dispatch to correct overloaded match method
  73. return ((AjASTMatcher)matcher).match(this, other);
  74. }
  75. /* (omit javadoc for this method)
  76. * Method declared on ASTNode.
  77. */
  78. void accept0(ASTVisitor visitor) {
  79. if (visitor instanceof AjASTVisitor) {
  80. boolean visitChildren = ((AjASTVisitor)visitor).visit(this);
  81. if (visitChildren) {
  82. // visit children in normal left to right reading order
  83. acceptChild(visitor, getJavadoc());
  84. acceptChild(visitor, getChildTypePattern());
  85. acceptChildren(visitor, this.parentTypePatterns);
  86. }
  87. ((AjASTVisitor)visitor).endVisit(this);
  88. }
  89. }
  90. /* (omit javadoc for this method)
  91. * Method declared on BodyDeclaration.
  92. *
  93. * There are no modifiers declared for DeclareErrorDeclaration -
  94. * therefore we don't do anything with this
  95. */
  96. SimplePropertyDescriptor internalModifiersProperty() {
  97. return internalModifiersPropertyFactory(DeclareErrorDeclaration.class);
  98. }
  99. /* (omit javadoc for this method)
  100. * Method declared on BodyDeclaration.
  101. *
  102. * There are no modifiers declared for DeclareErrorDeclaration -
  103. * therefore we don't do anything with this
  104. */
  105. ChildListPropertyDescriptor internalModifiers2Property() {
  106. return internalModifiers2PropertyFactory(DeclareErrorDeclaration.class);
  107. }
  108. /* (omit javadoc for this method)
  109. * Method declared on BodyDeclaration.
  110. */
  111. ChildPropertyDescriptor internalJavadocProperty() {
  112. return JAVADOC_PROPERTY;
  113. }
  114. /**
  115. * Returns a list of structural property descriptors for this node type.
  116. * Clients must not modify the result.
  117. *
  118. * @param apiLevel the API level; one of the
  119. * <code>AST.JLS&ast;</code> constants
  120. * @return a list of property descriptors (element type:
  121. * {@link StructuralPropertyDescriptor})
  122. * @since 3.0
  123. */
  124. public static List propertyDescriptors(int apiLevel) {
  125. if (apiLevel == AST.JLS2_INTERNAL) {
  126. return PROPERTY_DESCRIPTORS_2_0;
  127. } else {
  128. return PROPERTY_DESCRIPTORS_3_0;
  129. }
  130. }
  131. /* (omit javadoc for this method)
  132. * Method declared on ASTNode.
  133. */
  134. final List internalStructuralPropertiesForType(int apiLevel) {
  135. return propertyDescriptors(apiLevel);
  136. }
  137. /* (omit javadoc for this method)
  138. * Method declared on ASTNode.
  139. */
  140. final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) {
  141. if (property == JAVADOC_PROPERTY) {
  142. if (get) {
  143. return getJavadoc();
  144. } else {
  145. setJavadoc((Javadoc) child);
  146. return null;
  147. }
  148. }
  149. if (property == CHILD_TYPE_PATTERN_PROPERTY) {
  150. if (get) {
  151. return getChildTypePattern();
  152. } else {
  153. setChildTypePattern((AbstractTypePattern) child);
  154. return null;
  155. }
  156. }
  157. // allow default implementation to flag the error
  158. return super.internalGetSetChildProperty(property, get, child);
  159. }
  160. /* (omit javadoc for this method)
  161. * Method declared on ASTNode.
  162. */
  163. boolean internalGetSetBooleanProperty(SimplePropertyDescriptor property, boolean get, boolean value) {
  164. if (property == IS_EXTENDS_PROPERTY) {
  165. if (get) {
  166. return isExtends();
  167. } else {
  168. setExtends(value);
  169. return false;
  170. }
  171. }
  172. return super.internalGetSetBooleanProperty(property,get,value);
  173. }
  174. /* (omit javadoc for this method)
  175. * Method declared on ASTNode.
  176. */
  177. List internalGetChildListProperty(ChildListPropertyDescriptor property) {
  178. if (property == PARENTS_TYPE_PATTERNS_LIST_PROPERTY) {
  179. return parentTypePatterns();
  180. }
  181. // allow default implementation to flag the error
  182. return super.internalGetChildListProperty(property);
  183. }
  184. /**
  185. * Returns the live ordered list of parent type patterns for this
  186. * declare precedence.
  187. *
  188. * @return the live list of parent type patterns
  189. * (element type: <code>TypePattern</code>)
  190. */
  191. public List parentTypePatterns() {
  192. return this.parentTypePatterns;
  193. }
  194. public AbstractTypePattern getChildTypePattern(){
  195. return childTypePattern;
  196. }
  197. public void setChildTypePattern(AbstractTypePattern typePattern) {
  198. if (typePattern == null) {
  199. throw new IllegalArgumentException();
  200. }
  201. ASTNode oldChild = this.childTypePattern;
  202. preReplaceChild(oldChild, typePattern, CHILD_TYPE_PATTERN_PROPERTY);
  203. this.childTypePattern = typePattern;
  204. postReplaceChild(oldChild, typePattern, CHILD_TYPE_PATTERN_PROPERTY);
  205. }
  206. /**
  207. * Returns whether this declareParents declares an extends
  208. * or implements.
  209. *
  210. * @return <code>true</code> if this is an extends declaration,
  211. * and <code>false</code> if this is an implements declaration
  212. */
  213. public boolean isExtends() {
  214. return this.isExtends;
  215. }
  216. /**
  217. * Sets whether this declareParents declares an extends or implements.
  218. *
  219. * @param isExtends <code>true</code> for an extends declaration,
  220. * and <code>false</code> for an implements declaration
  221. */
  222. public void setExtends(boolean isExtends) {
  223. preValueChange(IS_EXTENDS_PROPERTY);
  224. this.isExtends = isExtends;
  225. postValueChange(IS_EXTENDS_PROPERTY);
  226. }
  227. }