1 11 12 package org.eclipse.jdt.core.dom; 13 14 import java.util.ArrayList ; 15 import java.util.List ; 16 17 30 public class EnhancedForStatement extends Statement { 31 32 35 public static final ChildPropertyDescriptor PARAMETER_PROPERTY = 36 new ChildPropertyDescriptor(EnhancedForStatement.class, "parameter", SingleVariableDeclaration.class, MANDATORY, CYCLE_RISK); 38 41 public static final ChildPropertyDescriptor EXPRESSION_PROPERTY = 42 new ChildPropertyDescriptor(EnhancedForStatement.class, "expression", Expression.class, MANDATORY, CYCLE_RISK); 44 47 public static final ChildPropertyDescriptor BODY_PROPERTY = 48 new ChildPropertyDescriptor(EnhancedForStatement.class, "body", Statement.class, MANDATORY, CYCLE_RISK); 50 55 private static final List PROPERTY_DESCRIPTORS; 56 57 static { 58 List properyList = new ArrayList (4); 59 createPropertyList(EnhancedForStatement.class, properyList); 60 addProperty(PARAMETER_PROPERTY, properyList); 61 addProperty(EXPRESSION_PROPERTY, properyList); 62 addProperty(BODY_PROPERTY, properyList); 63 PROPERTY_DESCRIPTORS = reapPropertyList(properyList); 64 } 65 66 76 public static List propertyDescriptors(int apiLevel) { 77 return PROPERTY_DESCRIPTORS; 78 } 79 80 84 private SingleVariableDeclaration parameter = null; 85 86 90 private Expression expression = null; 91 92 96 private Statement body = null; 97 98 105 EnhancedForStatement(AST ast) { 106 super(ast); 107 unsupportedIn2(); 108 } 109 110 113 final List internalStructuralPropertiesForType(int apiLevel) { 114 return propertyDescriptors(apiLevel); 115 } 116 117 120 final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) { 121 if (property == PARAMETER_PROPERTY) { 122 if (get) { 123 return getParameter(); 124 } else { 125 setParameter((SingleVariableDeclaration) child); 126 return null; 127 } 128 } 129 if (property == EXPRESSION_PROPERTY) { 130 if (get) { 131 return getExpression(); 132 } else { 133 setExpression((Expression) child); 134 return null; 135 } 136 } 137 if (property == BODY_PROPERTY) { 138 if (get) { 139 return getBody(); 140 } else { 141 setBody((Statement) child); 142 return null; 143 } 144 } 145 return super.internalGetSetChildProperty(property, get, child); 147 } 148 149 152 final int getNodeType0() { 153 return ENHANCED_FOR_STATEMENT; 154 } 155 156 159 ASTNode clone0(AST target) { 160 EnhancedForStatement result = new EnhancedForStatement(target); 161 result.setSourceRange(this.getStartPosition(), this.getLength()); 162 result.copyLeadingComment(this); 163 result.setParameter((SingleVariableDeclaration) getParameter().clone(target)); 164 result.setExpression((Expression) getExpression().clone(target)); 165 result.setBody( 166 (Statement) ASTNode.copySubtree(target, getBody())); 167 return result; 168 } 169 170 173 final boolean subtreeMatch0(ASTMatcher matcher, Object other) { 174 return matcher.match(this, other); 176 } 177 178 181 void accept0(ASTVisitor visitor) { 182 boolean visitChildren = visitor.visit(this); 183 if (visitChildren) { 184 acceptChild(visitor, getParameter()); 186 acceptChild(visitor, getExpression()); 187 acceptChild(visitor, getBody()); 188 } 189 visitor.endVisit(this); 190 } 191 192 197 public SingleVariableDeclaration getParameter() { 198 if (this.parameter == null) { 199 synchronized (this) { 201 if (this.parameter == null) { 202 preLazyInit(); 203 this.parameter = this.ast.newSingleVariableDeclaration(); 204 postLazyInit(this.parameter, PARAMETER_PROPERTY); 205 } 206 } 207 } 208 return this.parameter; 209 } 210 211 221 public void setParameter(SingleVariableDeclaration parameter) { 222 if (parameter == null) { 223 throw new IllegalArgumentException (); 224 } 225 ASTNode oldChild = this.parameter; 226 preReplaceChild(oldChild, parameter, PARAMETER_PROPERTY); 227 this.parameter = parameter; 228 postReplaceChild(oldChild, parameter, PARAMETER_PROPERTY); 229 } 230 231 236 public Expression getExpression() { 237 if (this.expression == null) { 238 synchronized (this) { 240 if (this.expression == null) { 241 preLazyInit(); 242 this.expression = new SimpleName(this.ast); 243 postLazyInit(this.expression, EXPRESSION_PROPERTY); 244 } 245 } 246 } 247 return this.expression; 248 } 249 250 261 public void setExpression(Expression expression) { 262 if (expression == null) { 263 throw new IllegalArgumentException (); 264 } 265 ASTNode oldChild = this.expression; 266 preReplaceChild(oldChild, expression, EXPRESSION_PROPERTY); 267 this.expression = expression; 268 postReplaceChild(oldChild, expression, EXPRESSION_PROPERTY); 269 } 270 271 276 public Statement getBody() { 277 if (this.body == null) { 278 synchronized (this) { 280 if (this.body == null) { 281 preLazyInit(); 282 this.body = new Block(this.ast); 283 postLazyInit(this.body, BODY_PROPERTY); 284 } 285 } 286 } 287 return this.body; 288 } 289 290 301 public void setBody(Statement statement) { 302 if (statement == null) { 303 throw new IllegalArgumentException (); 304 } 305 ASTNode oldChild = this.body; 306 preReplaceChild(oldChild, statement, BODY_PROPERTY); 307 this.body = statement; 308 postReplaceChild(oldChild, statement, BODY_PROPERTY); 309 } 310 311 314 int memSize() { 315 return super.memSize() + 3 * 4; 316 } 317 318 321 int treeSize() { 322 return 323 memSize() 324 + (this.parameter == null ? 0 : getParameter().treeSize()) 325 + (this.expression == null ? 0 : getExpression().treeSize()) 326 + (this.body == null ? 0 : getBody().treeSize()); 327 } 328 } 329 | Popular Tags |