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 44 public class VariableDeclarationExpression extends Expression { 45 46 50 public static final SimplePropertyDescriptor MODIFIERS_PROPERTY = 51 new SimplePropertyDescriptor(VariableDeclarationExpression.class, "modifiers", int.class, MANDATORY); 53 57 public static final ChildListPropertyDescriptor MODIFIERS2_PROPERTY = 58 new ChildListPropertyDescriptor(VariableDeclarationExpression.class, "modifiers", IExtendedModifier.class, CYCLE_RISK); 60 64 public static final ChildPropertyDescriptor TYPE_PROPERTY = 65 new ChildPropertyDescriptor(VariableDeclarationExpression.class, "type", Type.class, MANDATORY, NO_CYCLE_RISK); 67 71 public static final ChildListPropertyDescriptor FRAGMENTS_PROPERTY = 72 new ChildListPropertyDescriptor(VariableDeclarationExpression.class, "fragments", VariableDeclarationFragment.class, CYCLE_RISK); 74 80 private static final List PROPERTY_DESCRIPTORS_2_0; 81 82 88 private static final List PROPERTY_DESCRIPTORS_3_0; 89 90 static { 91 List propertyList = new ArrayList (4); 92 createPropertyList(VariableDeclarationExpression.class, propertyList); 93 addProperty(MODIFIERS_PROPERTY, propertyList); 94 addProperty(TYPE_PROPERTY, propertyList); 95 addProperty(FRAGMENTS_PROPERTY, propertyList); 96 PROPERTY_DESCRIPTORS_2_0 = reapPropertyList(propertyList); 97 98 propertyList = new ArrayList (4); 99 createPropertyList(VariableDeclarationExpression.class, propertyList); 100 addProperty(MODIFIERS2_PROPERTY, propertyList); 101 addProperty(TYPE_PROPERTY, propertyList); 102 addProperty(FRAGMENTS_PROPERTY, propertyList); 103 PROPERTY_DESCRIPTORS_3_0 = reapPropertyList(propertyList); 104 } 105 106 117 public static List propertyDescriptors(int apiLevel) { 118 if (apiLevel == AST.JLS2_INTERNAL) { 119 return PROPERTY_DESCRIPTORS_2_0; 120 } else { 121 return PROPERTY_DESCRIPTORS_3_0; 122 } 123 } 124 125 131 private ASTNode.NodeList modifiers = null; 132 133 137 private int modifierFlags = Modifier.NONE; 138 139 143 private Type baseType = null; 144 145 149 private ASTNode.NodeList variableDeclarationFragments = 150 new ASTNode.NodeList(FRAGMENTS_PROPERTY); 151 152 163 VariableDeclarationExpression(AST ast) { 164 super(ast); 165 if (ast.apiLevel >= AST.JLS3) { 166 this.modifiers = new ASTNode.NodeList(MODIFIERS2_PROPERTY); 167 } 168 } 169 170 173 final List internalStructuralPropertiesForType(int apiLevel) { 174 return propertyDescriptors(apiLevel); 175 } 176 177 180 final int internalGetSetIntProperty(SimplePropertyDescriptor property, boolean get, int value) { 181 if (property == MODIFIERS_PROPERTY) { 182 if (get) { 183 return getModifiers(); 184 } else { 185 setModifiers(value); 186 return 0; 187 } 188 } 189 return super.internalGetSetIntProperty(property, get, value); 191 } 192 193 196 final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) { 197 if (property == TYPE_PROPERTY) { 198 if (get) { 199 return getType(); 200 } else { 201 setType((Type) child); 202 return null; 203 } 204 } 205 return super.internalGetSetChildProperty(property, get, child); 207 } 208 209 212 final List internalGetChildListProperty(ChildListPropertyDescriptor property) { 213 if (property == MODIFIERS2_PROPERTY) { 214 return modifiers(); 215 } 216 if (property == FRAGMENTS_PROPERTY) { 217 return fragments(); 218 } 219 return super.internalGetChildListProperty(property); 221 } 222 223 226 final int getNodeType0() { 227 return VARIABLE_DECLARATION_EXPRESSION; 228 } 229 230 233 ASTNode clone0(AST target) { 234 VariableDeclarationExpression result = 235 new VariableDeclarationExpression(target); 236 result.setSourceRange(this.getStartPosition(), this.getLength()); 237 if (this.ast.apiLevel == AST.JLS2_INTERNAL) { 238 result.setModifiers(getModifiers()); 239 } 240 if (this.ast.apiLevel >= AST.JLS3) { 241 result.modifiers().addAll(ASTNode.copySubtrees(target, modifiers())); 242 } 243 result.setType((Type) getType().clone(target)); 244 result.fragments().addAll( 245 ASTNode.copySubtrees(target, fragments())); 246 return result; 247 248 } 249 250 253 final boolean subtreeMatch0(ASTMatcher matcher, Object other) { 254 return matcher.match(this, other); 256 } 257 258 261 void accept0(ASTVisitor visitor) { 262 boolean visitChildren = visitor.visit(this); 263 if (visitChildren) { 264 if (this.ast.apiLevel >= AST.JLS3) { 266 acceptChildren(visitor, this.modifiers); 267 } 268 acceptChild(visitor, getType()); 269 acceptChildren(visitor, variableDeclarationFragments); 270 } 271 visitor.endVisit(this); 272 } 273 274 288 public List modifiers() { 289 if (this.modifiers == null) { 291 unsupportedIn2(); 292 } 293 return this.modifiers; 294 } 295 296 306 public int getModifiers() { 307 if (this.modifiers == null) { 309 return this.modifierFlags; 311 } else { 312 int computedModifierFlags = Modifier.NONE; 316 for (Iterator it = modifiers().iterator(); it.hasNext(); ) { 317 Object x = it.next(); 318 if (x instanceof Modifier) { 319 computedModifierFlags |= ((Modifier) x).getKeyword().toFlagValue(); 320 } 321 } 322 return computedModifierFlags; 323 } 324 } 325 326 340 public void setModifiers(int modifiers) { 341 internalSetModifiers(modifiers); 342 } 343 344 349 final void internalSetModifiers(int pmodifiers) { 350 supportedOnlyIn2(); 351 preValueChange(MODIFIERS_PROPERTY); 352 this.modifierFlags = pmodifiers; 353 postValueChange(MODIFIERS_PROPERTY); 354 } 355 356 366 public Type getType() { 367 if (this.baseType == null) { 368 synchronized (this) { 370 if (this.baseType == null) { 371 preLazyInit(); 372 this.baseType = this.ast.newPrimitiveType(PrimitiveType.INT); 373 postLazyInit(this.baseType, TYPE_PROPERTY); 374 } 375 } 376 } 377 return this.baseType; 378 } 379 380 391 public void setType(Type type) { 392 if (type == null) { 393 throw new IllegalArgumentException (); 394 } 395 ASTNode oldChild = this.baseType; 396 preReplaceChild(oldChild, type, TYPE_PROPERTY); 397 this.baseType = type; 398 postReplaceChild(oldChild, type, TYPE_PROPERTY); 399 } 400 401 411 public List fragments() { 412 return this.variableDeclarationFragments; 413 } 414 415 418 int memSize() { 419 return BASE_NODE_SIZE + 4 * 4; 421 } 422 423 426 int treeSize() { 427 return 428 memSize() 429 + (this.modifiers == null ? 0 : this.modifiers.listSize()) 430 + (this.baseType == null ? 0 : getType().treeSize()) 431 + this.variableDeclarationFragments.listSize(); 432 } 433 } 434 435 | Popular Tags |