1 11 12 package org.eclipse.jdt.core.dom; 13 14 import java.util.ArrayList ; 15 import java.util.List ; 16 17 31 public class VariableDeclarationFragment extends VariableDeclaration { 32 33 37 public static final ChildPropertyDescriptor NAME_PROPERTY = 38 new ChildPropertyDescriptor(VariableDeclarationFragment.class, "name", SimpleName.class, MANDATORY, NO_CYCLE_RISK); 40 44 public static final SimplePropertyDescriptor EXTRA_DIMENSIONS_PROPERTY = 45 new SimplePropertyDescriptor(VariableDeclarationFragment.class, "extraDimensions", int.class, MANDATORY); 47 51 public static final ChildPropertyDescriptor INITIALIZER_PROPERTY = 52 new ChildPropertyDescriptor(VariableDeclarationFragment.class, "initializer", Expression.class, OPTIONAL, CYCLE_RISK); 54 60 private static final List PROPERTY_DESCRIPTORS; 61 62 static { 63 List propertyList = new ArrayList (4); 64 createPropertyList(VariableDeclarationFragment.class, propertyList); 65 addProperty(NAME_PROPERTY, propertyList); 66 addProperty(EXTRA_DIMENSIONS_PROPERTY, propertyList); 67 addProperty(INITIALIZER_PROPERTY, propertyList); 68 PROPERTY_DESCRIPTORS = reapPropertyList(propertyList); 69 } 70 71 81 public static List propertyDescriptors(int apiLevel) { 82 return PROPERTY_DESCRIPTORS; 83 } 84 85 89 private SimpleName variableName = null; 90 91 95 private int extraArrayDimensions = 0; 96 97 101 private Expression optionalInitializer = null; 102 103 113 VariableDeclarationFragment(AST ast) { 114 super(ast); 115 } 116 117 121 final SimplePropertyDescriptor internalExtraDimensionsProperty() { 122 return EXTRA_DIMENSIONS_PROPERTY; 123 } 124 125 129 final ChildPropertyDescriptor internalInitializerProperty() { 130 return INITIALIZER_PROPERTY; 131 } 132 133 137 final ChildPropertyDescriptor internalNameProperty() { 138 return NAME_PROPERTY; 139 } 140 141 144 final List internalStructuralPropertiesForType(int apiLevel) { 145 return propertyDescriptors(apiLevel); 146 } 147 148 151 final int internalGetSetIntProperty(SimplePropertyDescriptor property, boolean get, int value) { 152 if (property == EXTRA_DIMENSIONS_PROPERTY) { 153 if (get) { 154 return getExtraDimensions(); 155 } else { 156 setExtraDimensions(value); 157 return 0; 158 } 159 } 160 return super.internalGetSetIntProperty(property, get, value); 162 } 163 164 167 final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) { 168 if (property == NAME_PROPERTY) { 169 if (get) { 170 return getName(); 171 } else { 172 setName((SimpleName) child); 173 return null; 174 } 175 } 176 if (property == INITIALIZER_PROPERTY) { 177 if (get) { 178 return getInitializer(); 179 } else { 180 setInitializer((Expression) child); 181 return null; 182 } 183 } 184 return super.internalGetSetChildProperty(property, get, child); 186 } 187 188 191 final int getNodeType0() { 192 return VARIABLE_DECLARATION_FRAGMENT; 193 } 194 195 198 ASTNode clone0(AST target) { 199 VariableDeclarationFragment result = new VariableDeclarationFragment(target); 200 result.setSourceRange(this.getStartPosition(), this.getLength()); 201 result.setName((SimpleName) getName().clone(target)); 202 result.setExtraDimensions(getExtraDimensions()); 203 result.setInitializer( 204 (Expression) ASTNode.copySubtree(target, getInitializer())); 205 return result; 206 } 207 208 211 final boolean subtreeMatch0(ASTMatcher matcher, Object other) { 212 return matcher.match(this, other); 214 } 215 216 219 void accept0(ASTVisitor visitor) { 220 boolean visitChildren = visitor.visit(this); 221 if (visitChildren) { 222 acceptChild(visitor, getName()); 224 acceptChild(visitor, getInitializer()); 225 } 226 visitor.endVisit(this); 227 } 228 229 232 public SimpleName getName() { 233 if (this.variableName == null) { 234 synchronized (this) { 236 if (this.variableName == null) { 237 preLazyInit(); 238 this.variableName = new SimpleName(this.ast); 239 postLazyInit(this.variableName, NAME_PROPERTY); 240 } 241 } 242 } 243 return this.variableName; 244 } 245 246 249 public void setName(SimpleName variableName) { 250 if (variableName == null) { 251 throw new IllegalArgumentException (); 252 } 253 ASTNode oldChild = this.variableName; 254 preReplaceChild(oldChild, variableName, NAME_PROPERTY); 255 this.variableName = variableName; 256 postReplaceChild(oldChild, variableName, NAME_PROPERTY); 257 } 258 259 273 public int getExtraDimensions() { 274 return this.extraArrayDimensions; 275 } 276 277 290 public void setExtraDimensions(int dimensions) { 291 if (dimensions < 0) { 292 throw new IllegalArgumentException (); 293 } 294 preValueChange(EXTRA_DIMENSIONS_PROPERTY); 295 this.extraArrayDimensions = dimensions; 296 postValueChange(EXTRA_DIMENSIONS_PROPERTY); 297 } 298 299 302 public Expression getInitializer() { 303 return this.optionalInitializer; 304 } 305 306 309 public void setInitializer(Expression initializer) { 310 ASTNode oldChild = this.optionalInitializer; 311 preReplaceChild(oldChild, initializer, INITIALIZER_PROPERTY); 312 this.optionalInitializer = initializer; 313 postReplaceChild(oldChild, initializer, INITIALIZER_PROPERTY); 314 } 315 316 319 int memSize() { 320 return BASE_NODE_SIZE + 3 * 4; 322 } 323 324 327 int treeSize() { 328 return 329 memSize() 330 + (this.variableName == null ? 0 : getName().treeSize()) 331 + (this.optionalInitializer == null ? 0 : getInitializer().treeSize()); 332 } 333 } 334 | Popular Tags |