1 11 12 package org.eclipse.jdt.core.dom; 13 14 import java.util.ArrayList ; 15 import java.util.List ; 16 17 34 public class SwitchStatement extends Statement { 35 36 40 public static final ChildPropertyDescriptor EXPRESSION_PROPERTY = 41 new ChildPropertyDescriptor(SwitchStatement.class, "expression", Expression.class, MANDATORY, CYCLE_RISK); 43 47 public static final ChildListPropertyDescriptor STATEMENTS_PROPERTY = 48 new ChildListPropertyDescriptor(SwitchStatement.class, "statements", Statement.class, CYCLE_RISK); 50 55 private static final List PROPERTY_DESCRIPTORS; 56 57 static { 58 List propertyList = new ArrayList (3); 59 createPropertyList(SwitchStatement.class, propertyList); 60 addProperty(EXPRESSION_PROPERTY, propertyList); 61 addProperty(STATEMENTS_PROPERTY, propertyList); 62 PROPERTY_DESCRIPTORS = reapPropertyList(propertyList); 63 } 64 65 75 public static List propertyDescriptors(int apiLevel) { 76 return PROPERTY_DESCRIPTORS; 77 } 78 79 83 private Expression expression = null; 84 85 90 private ASTNode.NodeList statements = 91 new ASTNode.NodeList(STATEMENTS_PROPERTY); 92 93 103 SwitchStatement(AST ast) { 104 super(ast); 105 } 106 107 110 final List internalStructuralPropertiesForType(int apiLevel) { 111 return propertyDescriptors(apiLevel); 112 } 113 114 117 final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) { 118 if (property == EXPRESSION_PROPERTY) { 119 if (get) { 120 return getExpression(); 121 } else { 122 setExpression((Expression) child); 123 return null; 124 } 125 } 126 return super.internalGetSetChildProperty(property, get, child); 128 } 129 130 133 final List internalGetChildListProperty(ChildListPropertyDescriptor property) { 134 if (property == STATEMENTS_PROPERTY) { 135 return statements(); 136 } 137 return super.internalGetChildListProperty(property); 139 } 140 141 144 final int getNodeType0() { 145 return SWITCH_STATEMENT; 146 } 147 148 151 ASTNode clone0(AST target) { 152 SwitchStatement result = new SwitchStatement(target); 153 result.setSourceRange(this.getStartPosition(), this.getLength()); 154 result.copyLeadingComment(this); 155 result.setExpression((Expression) getExpression().clone(target)); 156 result.statements().addAll(ASTNode.copySubtrees(target, statements())); 157 return result; 158 } 159 160 163 final boolean subtreeMatch0(ASTMatcher matcher, Object other) { 164 return matcher.match(this, other); 166 } 167 168 171 void accept0(ASTVisitor visitor) { 172 boolean visitChildren = visitor.visit(this); 173 if (visitChildren) { 174 acceptChild(visitor, getExpression()); 176 acceptChildren(visitor, this.statements); 177 } 178 visitor.endVisit(this); 179 } 180 181 186 public Expression getExpression() { 187 if (this.expression == null) { 188 synchronized (this) { 190 if (this.expression == null) { 191 preLazyInit(); 192 this.expression = new SimpleName(this.ast); 193 postLazyInit(this.expression, EXPRESSION_PROPERTY); 194 } 195 } 196 } 197 return this.expression; 198 } 199 200 211 public void setExpression(Expression expression) { 212 if (expression == null) { 213 throw new IllegalArgumentException (); 214 } 215 ASTNode oldChild = this.expression; 216 preReplaceChild(oldChild, expression, EXPRESSION_PROPERTY); 217 this.expression = expression; 218 postReplaceChild(oldChild, expression, EXPRESSION_PROPERTY); 219 } 220 221 229 public List statements() { 230 return this.statements; 231 } 232 233 236 int memSize() { 237 return super.memSize() + 2 * 4; 238 } 239 240 243 int treeSize() { 244 return 245 memSize() 246 + (this.expression == null ? 0 : getExpression().treeSize()) 247 + this.statements.listSize(); 248 } 249 } 250 | Popular Tags |