1 11 12 package org.eclipse.jdt.core.dom; 13 14 import java.util.ArrayList ; 15 import java.util.List ; 16 17 26 public class IfStatement extends Statement { 27 28 32 public static final ChildPropertyDescriptor EXPRESSION_PROPERTY = 33 new ChildPropertyDescriptor(IfStatement.class, "expression", Expression.class, MANDATORY, CYCLE_RISK); 35 39 public static final ChildPropertyDescriptor THEN_STATEMENT_PROPERTY = 40 new ChildPropertyDescriptor(IfStatement.class, "thenStatement", Statement.class, MANDATORY, CYCLE_RISK); 42 46 public static final ChildPropertyDescriptor ELSE_STATEMENT_PROPERTY = 47 new ChildPropertyDescriptor(IfStatement.class, "elseStatement", Statement.class, OPTIONAL, CYCLE_RISK); 49 54 private static final List PROPERTY_DESCRIPTORS; 55 56 static { 57 List properyList = new ArrayList (4); 58 createPropertyList(IfStatement.class, properyList); 59 addProperty(EXPRESSION_PROPERTY, properyList); 60 addProperty(THEN_STATEMENT_PROPERTY, properyList); 61 addProperty(ELSE_STATEMENT_PROPERTY, properyList); 62 PROPERTY_DESCRIPTORS = reapPropertyList(properyList); 63 } 64 65 76 public static List propertyDescriptors(int apiLevel) { 77 return PROPERTY_DESCRIPTORS; 78 } 79 80 84 private Expression expression = null; 85 86 90 private Statement thenStatement = null; 91 92 95 private Statement optionalElseStatement = null; 96 97 108 IfStatement(AST ast) { 109 super(ast); 110 } 111 112 115 final List internalStructuralPropertiesForType(int apiLevel) { 116 return propertyDescriptors(apiLevel); 117 } 118 119 122 final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) { 123 if (property == EXPRESSION_PROPERTY) { 124 if (get) { 125 return getExpression(); 126 } else { 127 setExpression((Expression) child); 128 return null; 129 } 130 } 131 if (property == THEN_STATEMENT_PROPERTY) { 132 if (get) { 133 return getThenStatement(); 134 } else { 135 setThenStatement((Statement) child); 136 return null; 137 } 138 } 139 if (property == ELSE_STATEMENT_PROPERTY) { 140 if (get) { 141 return getElseStatement(); 142 } else { 143 setElseStatement((Statement) child); 144 return null; 145 } 146 } 147 return super.internalGetSetChildProperty(property, get, child); 149 } 150 151 154 final int getNodeType0() { 155 return IF_STATEMENT; 156 } 157 158 161 ASTNode clone0(AST target) { 162 IfStatement result = new IfStatement(target); 163 result.setSourceRange(this.getStartPosition(), this.getLength()); 164 result.copyLeadingComment(this); 165 result.setExpression((Expression) getExpression().clone(target)); 166 result.setThenStatement( 167 (Statement) getThenStatement().clone(target)); 168 result.setElseStatement( 169 (Statement) ASTNode.copySubtree(target, getElseStatement())); 170 return result; 171 } 172 173 176 final boolean subtreeMatch0(ASTMatcher matcher, Object other) { 177 return matcher.match(this, other); 179 } 180 181 184 void accept0(ASTVisitor visitor) { 185 boolean visitChildren = visitor.visit(this); 186 if (visitChildren) { 187 acceptChild(visitor, getExpression()); 189 acceptChild(visitor, getThenStatement()); 190 acceptChild(visitor, getElseStatement()); 191 } 192 visitor.endVisit(this); 193 } 194 195 200 public Expression getExpression() { 201 if (this.expression == null) { 202 synchronized (this) { 204 if (this.expression == null) { 205 preLazyInit(); 206 this.expression = new SimpleName(this.ast); 207 postLazyInit(this.expression, EXPRESSION_PROPERTY); 208 } 209 } 210 } 211 return this.expression; 212 } 213 214 225 public void setExpression(Expression expression) { 226 if (expression == null) { 227 throw new IllegalArgumentException (); 228 } 229 ASTNode oldChild = this.expression; 230 preReplaceChild(oldChild, expression, EXPRESSION_PROPERTY); 231 this.expression = expression; 232 postReplaceChild(oldChild, expression, EXPRESSION_PROPERTY); 233 } 234 235 240 public Statement getThenStatement() { 241 if (this.thenStatement == null) { 242 synchronized (this) { 244 if (this.thenStatement == null) { 245 preLazyInit(); 246 this.thenStatement = new Block(this.ast); 247 postLazyInit(this.thenStatement, THEN_STATEMENT_PROPERTY); 248 } 249 } 250 } 251 return this.thenStatement; 252 } 253 254 273 public void setThenStatement(Statement statement) { 274 if (statement == null) { 275 throw new IllegalArgumentException (); 276 } 277 ASTNode oldChild = this.thenStatement; 278 preReplaceChild(oldChild, statement, THEN_STATEMENT_PROPERTY); 279 this.thenStatement = statement; 280 postReplaceChild(oldChild, statement, THEN_STATEMENT_PROPERTY); 281 } 282 283 293 public Statement getElseStatement() { 294 return this.optionalElseStatement; 295 } 296 297 322 public void setElseStatement(Statement statement) { 323 ASTNode oldChild = this.optionalElseStatement; 324 preReplaceChild(oldChild, statement, ELSE_STATEMENT_PROPERTY); 325 this.optionalElseStatement = statement; 326 postReplaceChild(oldChild, statement, ELSE_STATEMENT_PROPERTY); 327 } 328 329 332 int memSize() { 333 return super.memSize() + 3 * 4; 334 } 335 336 339 int treeSize() { 340 return 341 memSize() 342 + (this.expression == null ? 0 : getExpression().treeSize()) 343 + (this.thenStatement == null ? 0 : getThenStatement().treeSize()) 344 + (this.optionalElseStatement == null ? 0 : getElseStatement().treeSize()); 345 } 346 } 347 348 | Popular Tags |