1 11 12 package org.eclipse.jdt.core.dom; 13 14 import java.util.ArrayList ; 15 import java.util.List ; 16 17 27 public class ConditionalExpression extends Expression { 28 29 33 public static final ChildPropertyDescriptor EXPRESSION_PROPERTY = 34 new ChildPropertyDescriptor(ConditionalExpression.class, "expression", Expression.class, MANDATORY, CYCLE_RISK); 36 40 public static final ChildPropertyDescriptor THEN_EXPRESSION_PROPERTY = 41 new ChildPropertyDescriptor(ConditionalExpression.class, "thenExpression", Expression.class, MANDATORY, CYCLE_RISK); 43 47 public static final ChildPropertyDescriptor ELSE_EXPRESSION_PROPERTY = 48 new ChildPropertyDescriptor(ConditionalExpression.class, "elseExpression", Expression.class, MANDATORY, CYCLE_RISK); 50 55 private static final List PROPERTY_DESCRIPTORS; 56 57 static { 58 List properyList = new ArrayList (4); 59 createPropertyList(ConditionalExpression.class, properyList); 60 addProperty(EXPRESSION_PROPERTY, properyList); 61 addProperty(THEN_EXPRESSION_PROPERTY, properyList); 62 addProperty(ELSE_EXPRESSION_PROPERTY, properyList); 63 PROPERTY_DESCRIPTORS = reapPropertyList(properyList); 64 } 65 66 77 public static List propertyDescriptors(int apiLevel) { 78 return PROPERTY_DESCRIPTORS; 79 } 80 81 85 private Expression conditionExpression = null; 86 87 91 private Expression thenExpression = null; 92 93 97 private Expression elseExpression = null; 98 99 109 ConditionalExpression(AST ast) { 110 super(ast); 111 } 112 113 116 final List internalStructuralPropertiesForType(int apiLevel) { 117 return propertyDescriptors(apiLevel); 118 } 119 120 123 final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) { 124 if (property == EXPRESSION_PROPERTY) { 125 if (get) { 126 return getExpression(); 127 } else { 128 setExpression((Expression) child); 129 return null; 130 } 131 } 132 if (property == THEN_EXPRESSION_PROPERTY) { 133 if (get) { 134 return getThenExpression(); 135 } else { 136 setThenExpression((Expression) child); 137 return null; 138 } 139 } 140 if (property == ELSE_EXPRESSION_PROPERTY) { 141 if (get) { 142 return getElseExpression(); 143 } else { 144 setElseExpression((Expression) child); 145 return null; 146 } 147 } 148 return super.internalGetSetChildProperty(property, get, child); 150 } 151 152 155 final int getNodeType0() { 156 return CONDITIONAL_EXPRESSION; 157 } 158 159 162 ASTNode clone0(AST target) { 163 ConditionalExpression result = new ConditionalExpression(target); 164 result.setSourceRange(this.getStartPosition(), this.getLength()); 165 result.setExpression((Expression) getExpression().clone(target)); 166 result.setThenExpression( 167 (Expression) getThenExpression().clone(target)); 168 result.setElseExpression( 169 (Expression) getElseExpression().clone(target)); 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, getThenExpression()); 190 acceptChild(visitor, getElseExpression()); 191 } 192 visitor.endVisit(this); 193 } 194 195 200 public Expression getExpression() { 201 if (this.conditionExpression == null) { 202 synchronized (this) { 204 if (this.conditionExpression == null) { 205 preLazyInit(); 206 this.conditionExpression = new SimpleName(this.ast); 207 postLazyInit(this.conditionExpression, EXPRESSION_PROPERTY); 208 } 209 } 210 } 211 return this.conditionExpression; 212 } 213 214 225 public void setExpression(Expression expression) { 226 if (expression == null) { 227 throw new IllegalArgumentException (); 228 } 229 ASTNode oldChild = this.conditionExpression; 230 preReplaceChild(oldChild, expression, EXPRESSION_PROPERTY); 231 this.conditionExpression = expression; 232 postReplaceChild(oldChild, expression, EXPRESSION_PROPERTY); 233 } 234 235 240 public Expression getThenExpression() { 241 if (this.thenExpression == null) { 242 synchronized (this) { 244 if (this.thenExpression == null) { 245 preLazyInit(); 246 this.thenExpression = new SimpleName(this.ast); 247 postLazyInit(this.thenExpression, THEN_EXPRESSION_PROPERTY); 248 } 249 } 250 } 251 return this.thenExpression; 252 } 253 254 265 public void setThenExpression(Expression expression) { 266 if (expression == null) { 267 throw new IllegalArgumentException (); 268 } 269 ASTNode oldChild = this.thenExpression; 270 preReplaceChild(oldChild, expression, THEN_EXPRESSION_PROPERTY); 271 this.thenExpression = expression; 272 postReplaceChild(oldChild, expression, THEN_EXPRESSION_PROPERTY); 273 } 274 275 280 public Expression getElseExpression() { 281 if (this.elseExpression == null) { 282 synchronized (this) { 284 if (this.elseExpression == null) { 285 preLazyInit(); 286 this.elseExpression = new SimpleName(this.ast); 287 postLazyInit(this.elseExpression, ELSE_EXPRESSION_PROPERTY); 288 } 289 } 290 } 291 return this.elseExpression; 292 } 293 294 305 public void setElseExpression(Expression expression) { 306 if (expression == null) { 307 throw new IllegalArgumentException (); 308 } 309 ASTNode oldChild = this.elseExpression; 310 preReplaceChild(oldChild, expression, ELSE_EXPRESSION_PROPERTY); 311 this.elseExpression = expression; 312 postReplaceChild(oldChild, expression, ELSE_EXPRESSION_PROPERTY); 313 } 314 315 318 int memSize() { 319 return BASE_NODE_SIZE + 3 * 4; 321 } 322 323 326 int treeSize() { 327 return 328 memSize() 329 + (this.conditionExpression == null ? 0 : getExpression().treeSize()) 330 + (this.thenExpression == null ? 0 : getThenExpression().treeSize()) 331 + (this.elseExpression == null ? 0 : getElseExpression().treeSize()); 332 } 333 } 334 | Popular Tags |