1 11 12 package org.eclipse.jdt.core.dom; 13 14 import java.util.ArrayList ; 15 import java.util.List ; 16 17 43 public class ForStatement extends Statement { 44 45 49 public static final ChildListPropertyDescriptor INITIALIZERS_PROPERTY = 50 new ChildListPropertyDescriptor(ForStatement.class, "initializers", Expression.class, CYCLE_RISK); 52 56 public static final ChildPropertyDescriptor EXPRESSION_PROPERTY = 57 new ChildPropertyDescriptor(ForStatement.class, "expression", Expression.class, OPTIONAL, CYCLE_RISK); 59 63 public static final ChildListPropertyDescriptor UPDATERS_PROPERTY = 64 new ChildListPropertyDescriptor(ForStatement.class, "updaters", Expression.class, CYCLE_RISK); 66 70 public static final ChildPropertyDescriptor BODY_PROPERTY = 71 new ChildPropertyDescriptor(ForStatement.class, "body", Statement.class, MANDATORY, CYCLE_RISK); 73 78 private static final List PROPERTY_DESCRIPTORS; 79 80 static { 81 List properyList = new ArrayList (5); 82 createPropertyList(ForStatement.class, properyList); 83 addProperty(INITIALIZERS_PROPERTY, properyList); 84 addProperty(EXPRESSION_PROPERTY, properyList); 85 addProperty(UPDATERS_PROPERTY, properyList); 86 addProperty(BODY_PROPERTY, properyList); 87 PROPERTY_DESCRIPTORS = reapPropertyList(properyList); 88 } 89 90 101 public static List propertyDescriptors(int apiLevel) { 102 return PROPERTY_DESCRIPTORS; 103 } 104 105 109 private ASTNode.NodeList initializers = 110 new ASTNode.NodeList(INITIALIZERS_PROPERTY); 111 112 115 private Expression optionalConditionExpression = null; 116 117 121 private ASTNode.NodeList updaters = 122 new ASTNode.NodeList(UPDATERS_PROPERTY); 123 124 128 private Statement body = null; 129 130 137 ForStatement(AST ast) { 138 super(ast); 139 } 140 141 144 final List internalStructuralPropertiesForType(int apiLevel) { 145 return propertyDescriptors(apiLevel); 146 } 147 148 149 152 final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) { 153 if (property == EXPRESSION_PROPERTY) { 154 if (get) { 155 return getExpression(); 156 } else { 157 setExpression((Expression) child); 158 return null; 159 } 160 } 161 if (property == BODY_PROPERTY) { 162 if (get) { 163 return getBody(); 164 } else { 165 setBody((Statement) child); 166 return null; 167 } 168 } 169 return super.internalGetSetChildProperty(property, get, child); 171 } 172 173 176 final List internalGetChildListProperty(ChildListPropertyDescriptor property) { 177 if (property == INITIALIZERS_PROPERTY) { 178 return initializers(); 179 } 180 if (property == UPDATERS_PROPERTY) { 181 return updaters(); 182 } 183 return super.internalGetChildListProperty(property); 185 } 186 187 190 final int getNodeType0() { 191 return FOR_STATEMENT; 192 } 193 194 197 ASTNode clone0(AST target) { 198 ForStatement result = new ForStatement(target); 199 result.setSourceRange(this.getStartPosition(), this.getLength()); 200 result.copyLeadingComment(this); 201 result.initializers().addAll(ASTNode.copySubtrees(target, initializers())); 202 result.setExpression( 203 (Expression) ASTNode.copySubtree(target, getExpression())); 204 result.updaters().addAll(ASTNode.copySubtrees(target, updaters())); 205 result.setBody( 206 (Statement) ASTNode.copySubtree(target, getBody())); 207 return result; 208 } 209 210 213 final boolean subtreeMatch0(ASTMatcher matcher, Object other) { 214 return matcher.match(this, other); 216 } 217 218 221 void accept0(ASTVisitor visitor) { 222 boolean visitChildren = visitor.visit(this); 223 if (visitChildren) { 224 acceptChildren(visitor, this.initializers); 226 acceptChild(visitor, getExpression()); 227 acceptChildren(visitor, this.updaters); 228 acceptChild(visitor, getBody()); 229 } 230 visitor.endVisit(this); 231 } 232 233 245 public List initializers() { 246 return this.initializers; 247 } 248 249 256 public Expression getExpression() { 257 return this.optionalConditionExpression; 258 } 259 260 272 public void setExpression(Expression expression) { 273 ASTNode oldChild = this.optionalConditionExpression; 274 preReplaceChild(oldChild, expression, EXPRESSION_PROPERTY); 275 this.optionalConditionExpression = expression; 276 postReplaceChild(oldChild, expression, EXPRESSION_PROPERTY); 277 } 278 279 290 public List updaters() { 291 return this.updaters; 292 } 293 294 299 public Statement getBody() { 300 if (this.body == null) { 301 synchronized (this) { 303 if (this.body == null) { 304 preLazyInit(); 305 this.body = new Block(this.ast); 306 postLazyInit(this.body, BODY_PROPERTY); 307 } 308 } 309 } 310 return this.body; 311 } 312 313 332 public void setBody(Statement statement) { 333 if (statement == null) { 334 throw new IllegalArgumentException (); 335 } 336 ASTNode oldChild = this.body; 337 preReplaceChild(oldChild, statement, BODY_PROPERTY); 338 this.body = statement; 339 postReplaceChild(oldChild, statement, BODY_PROPERTY); 340 } 341 342 345 int memSize() { 346 return super.memSize() + 4 * 4; 347 } 348 349 352 int treeSize() { 353 return 354 memSize() 355 + this.initializers.listSize() 356 + this.updaters.listSize() 357 + (this.optionalConditionExpression == null ? 0 : getExpression().treeSize()) 358 + (this.body == null ? 0 : getBody().treeSize()); 359 } 360 } 361 | Popular Tags |