1 11 12 package org.eclipse.jdt.core.dom; 13 14 import java.util.ArrayList ; 15 import java.util.Iterator ; 16 import java.util.List ; 17 18 47 public class VariableDeclarationStatement extends Statement { 48 49 53 public static final SimplePropertyDescriptor MODIFIERS_PROPERTY = 54 new SimplePropertyDescriptor(VariableDeclarationStatement.class, "modifiers", int.class, MANDATORY); 56 60 public static final ChildListPropertyDescriptor MODIFIERS2_PROPERTY = 61 new ChildListPropertyDescriptor(VariableDeclarationStatement.class, "modifiers", IExtendedModifier.class, CYCLE_RISK); 63 67 public static final ChildPropertyDescriptor TYPE_PROPERTY = 68 new ChildPropertyDescriptor(VariableDeclarationStatement.class, "type", Type.class, MANDATORY, NO_CYCLE_RISK); 70 74 public static final ChildListPropertyDescriptor FRAGMENTS_PROPERTY = 75 new ChildListPropertyDescriptor(VariableDeclarationStatement.class, "fragments", VariableDeclarationFragment.class, CYCLE_RISK); 77 83 private static final List PROPERTY_DESCRIPTORS_2_0; 84 85 91 private static final List PROPERTY_DESCRIPTORS_3_0; 92 93 static { 94 List propertyList = new ArrayList (4); 95 createPropertyList(VariableDeclarationStatement.class, propertyList); 96 addProperty(MODIFIERS_PROPERTY, propertyList); 97 addProperty(TYPE_PROPERTY, propertyList); 98 addProperty(FRAGMENTS_PROPERTY, propertyList); 99 PROPERTY_DESCRIPTORS_2_0 = reapPropertyList(propertyList); 100 101 propertyList = new ArrayList (4); 102 createPropertyList(VariableDeclarationStatement.class, propertyList); 103 addProperty(MODIFIERS2_PROPERTY, propertyList); 104 addProperty(TYPE_PROPERTY, propertyList); 105 addProperty(FRAGMENTS_PROPERTY, propertyList); 106 PROPERTY_DESCRIPTORS_3_0 = reapPropertyList(propertyList); 107 } 108 109 120 public static List propertyDescriptors(int apiLevel) { 121 if (apiLevel == AST.JLS2_INTERNAL) { 122 return PROPERTY_DESCRIPTORS_2_0; 123 } else { 124 return PROPERTY_DESCRIPTORS_3_0; 125 } 126 } 127 128 134 private ASTNode.NodeList modifiers = null; 135 136 140 private int modifierFlags = Modifier.NONE; 141 142 146 private Type baseType = null; 147 148 152 private ASTNode.NodeList variableDeclarationFragments = 153 new ASTNode.NodeList(FRAGMENTS_PROPERTY); 154 155 166 VariableDeclarationStatement(AST ast) { 167 super(ast); 168 if (ast.apiLevel >= AST.JLS3) { 169 this.modifiers = new ASTNode.NodeList(MODIFIERS2_PROPERTY); 170 } 171 } 172 173 176 final List internalStructuralPropertiesForType(int apiLevel) { 177 return propertyDescriptors(apiLevel); 178 } 179 180 183 final int internalGetSetIntProperty(SimplePropertyDescriptor property, boolean get, int value) { 184 if (property == MODIFIERS_PROPERTY) { 185 if (get) { 186 return getModifiers(); 187 } else { 188 setModifiers(value); 189 return 0; 190 } 191 } 192 return super.internalGetSetIntProperty(property, get, value); 194 } 195 196 199 final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) { 200 if (property == TYPE_PROPERTY) { 201 if (get) { 202 return getType(); 203 } else { 204 setType((Type) child); 205 return null; 206 } 207 } 208 return super.internalGetSetChildProperty(property, get, child); 210 } 211 212 215 final List internalGetChildListProperty(ChildListPropertyDescriptor property) { 216 if (property == MODIFIERS2_PROPERTY) { 217 return modifiers(); 218 } 219 if (property == FRAGMENTS_PROPERTY) { 220 return fragments(); 221 } 222 return super.internalGetChildListProperty(property); 224 } 225 226 229 final int getNodeType0() { 230 return VARIABLE_DECLARATION_STATEMENT; 231 } 232 233 236 ASTNode clone0(AST target) { 237 VariableDeclarationStatement result = 238 new VariableDeclarationStatement(target); 239 result.setSourceRange(this.getStartPosition(), this.getLength()); 240 result.copyLeadingComment(this); 241 if (this.ast.apiLevel == AST.JLS2_INTERNAL) { 242 result.setModifiers(getModifiers()); 243 } 244 if (this.ast.apiLevel >= AST.JLS3) { 245 result.modifiers().addAll(ASTNode.copySubtrees(target, modifiers())); 246 } 247 result.setType((Type) getType().clone(target)); 248 result.fragments().addAll( 249 ASTNode.copySubtrees(target, fragments())); 250 return result; 251 } 252 253 256 final boolean subtreeMatch0(ASTMatcher matcher, Object other) { 257 return matcher.match(this, other); 259 } 260 261 264 void accept0(ASTVisitor visitor) { 265 boolean visitChildren = visitor.visit(this); 266 if (visitChildren) { 267 if (this.ast.apiLevel >= AST.JLS3) { 269 acceptChildren(visitor, this.modifiers); 270 } 271 acceptChild(visitor, getType()); 272 acceptChildren(visitor, this.variableDeclarationFragments); 273 } 274 visitor.endVisit(this); 275 } 276 277 291 public List modifiers() { 292 if (this.modifiers == null) { 294 unsupportedIn2(); 295 } 296 return this.modifiers; 297 } 298 299 309 public int getModifiers() { 310 if (this.modifiers == null) { 312 return this.modifierFlags; 314 } else { 315 int computedModifierFlags = Modifier.NONE; 319 for (Iterator it = modifiers().iterator(); it.hasNext(); ) { 320 Object x = it.next(); 321 if (x instanceof Modifier) { 322 computedModifierFlags |= ((Modifier) x).getKeyword().toFlagValue(); 323 } 324 } 325 return computedModifierFlags; 326 } 327 } 328 329 343 public void setModifiers(int modifiers) { 344 internalSetModifiers(modifiers); 345 } 346 347 352 final void internalSetModifiers(int pmodifiers) { 353 supportedOnlyIn2(); 354 preValueChange(MODIFIERS_PROPERTY); 355 this.modifierFlags = pmodifiers; 356 postValueChange(MODIFIERS_PROPERTY); 357 } 358 359 369 public Type getType() { 370 if (this.baseType == null) { 371 synchronized (this) { 373 if (this.baseType == null) { 374 preLazyInit(); 375 this.baseType = this.ast.newPrimitiveType(PrimitiveType.INT); 376 postLazyInit(this.baseType, TYPE_PROPERTY); 377 } 378 } 379 } 380 return this.baseType; 381 } 382 383 394 public void setType(Type type) { 395 if (type == null) { 396 throw new IllegalArgumentException (); 397 } 398 ASTNode oldChild = this.baseType; 399 preReplaceChild(oldChild, type, TYPE_PROPERTY); 400 this.baseType = type; 401 postReplaceChild(oldChild, type, TYPE_PROPERTY); 402 } 403 404 414 public List fragments() { 415 return this.variableDeclarationFragments; 416 } 417 418 421 int memSize() { 422 return super.memSize() + 4 * 4; 423 } 424 425 428 int treeSize() { 429 return 430 memSize() 431 + (this.modifiers == null ? 0 : this.modifiers.listSize()) 432 + (this.baseType == null ? 0 : getType().treeSize()) 433 + this.variableDeclarationFragments.listSize(); 434 } 435 } 436 437 | Popular Tags |