1 11 12 package org.eclipse.jdt.core.dom; 13 14 import java.util.ArrayList ; 15 import java.util.List ; 16 17 38 public class FieldDeclaration extends BodyDeclaration { 39 40 44 public static final ChildPropertyDescriptor JAVADOC_PROPERTY = 45 internalJavadocPropertyFactory(FieldDeclaration.class); 46 47 51 public static final SimplePropertyDescriptor MODIFIERS_PROPERTY = 52 internalModifiersPropertyFactory(FieldDeclaration.class); 53 54 58 public static final ChildListPropertyDescriptor MODIFIERS2_PROPERTY = 59 internalModifiers2PropertyFactory(FieldDeclaration.class); 60 61 65 public static final ChildPropertyDescriptor TYPE_PROPERTY = 66 new ChildPropertyDescriptor(FieldDeclaration.class, "type", Type.class, MANDATORY, NO_CYCLE_RISK); 68 72 public static final ChildListPropertyDescriptor FRAGMENTS_PROPERTY = 73 new ChildListPropertyDescriptor(FieldDeclaration.class, "fragments", VariableDeclarationFragment.class, CYCLE_RISK); 75 81 private static final List PROPERTY_DESCRIPTORS_2_0; 82 83 89 private static final List PROPERTY_DESCRIPTORS_3_0; 90 91 static { 92 List properyList = new ArrayList (5); 93 createPropertyList(FieldDeclaration.class, properyList); 94 addProperty(JAVADOC_PROPERTY, properyList); 95 addProperty(MODIFIERS_PROPERTY, properyList); 96 addProperty(TYPE_PROPERTY, properyList); 97 addProperty(FRAGMENTS_PROPERTY, properyList); 98 PROPERTY_DESCRIPTORS_2_0 = reapPropertyList(properyList); 99 100 properyList = new ArrayList (5); 101 createPropertyList(FieldDeclaration.class, properyList); 102 addProperty(JAVADOC_PROPERTY, properyList); 103 addProperty(MODIFIERS2_PROPERTY, properyList); 104 addProperty(TYPE_PROPERTY, properyList); 105 addProperty(FRAGMENTS_PROPERTY, properyList); 106 PROPERTY_DESCRIPTORS_3_0 = reapPropertyList(properyList); 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 132 private Type baseType = null; 133 134 138 private ASTNode.NodeList variableDeclarationFragments = 139 new ASTNode.NodeList(FRAGMENTS_PROPERTY); 140 141 152 FieldDeclaration(AST ast) { 153 super(ast); 154 } 155 156 160 final List internalStructuralPropertiesForType(int apiLevel) { 161 return propertyDescriptors(apiLevel); 162 } 163 164 167 final int internalGetSetIntProperty(SimplePropertyDescriptor property, boolean get, int value) { 168 if (property == MODIFIERS_PROPERTY) { 169 if (get) { 170 return getModifiers(); 171 } else { 172 internalSetModifiers(value); 173 return 0; 174 } 175 } 176 return super.internalGetSetIntProperty(property, get, value); 178 } 179 180 183 final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) { 184 if (property == JAVADOC_PROPERTY) { 185 if (get) { 186 return getJavadoc(); 187 } else { 188 setJavadoc((Javadoc) child); 189 return null; 190 } 191 } 192 if (property == TYPE_PROPERTY) { 193 if (get) { 194 return getType(); 195 } else { 196 setType((Type) child); 197 return null; 198 } 199 } 200 return super.internalGetSetChildProperty(property, get, child); 202 } 203 204 207 final List internalGetChildListProperty(ChildListPropertyDescriptor property) { 208 if (property == MODIFIERS2_PROPERTY) { 209 return modifiers(); 210 } 211 if (property == FRAGMENTS_PROPERTY) { 212 return fragments(); 213 } 214 return super.internalGetChildListProperty(property); 216 } 217 218 221 final ChildPropertyDescriptor internalJavadocProperty() { 222 return JAVADOC_PROPERTY; 223 } 224 225 228 final SimplePropertyDescriptor internalModifiersProperty() { 229 return MODIFIERS_PROPERTY; 230 } 231 232 235 final ChildListPropertyDescriptor internalModifiers2Property() { 236 return MODIFIERS2_PROPERTY; 237 } 238 239 242 final int getNodeType0() { 243 return FIELD_DECLARATION; 244 } 245 246 249 ASTNode clone0(AST target) { 250 FieldDeclaration result = new FieldDeclaration(target); 251 result.setSourceRange(this.getStartPosition(), this.getLength()); 252 result.setJavadoc( 253 (Javadoc) ASTNode.copySubtree(target, getJavadoc())); 254 if (this.ast.apiLevel == AST.JLS2_INTERNAL) { 255 result.internalSetModifiers(getModifiers()); 256 } 257 if (this.ast.apiLevel >= AST.JLS3) { 258 result.modifiers().addAll(ASTNode.copySubtrees(target, modifiers())); 259 } 260 result.setType((Type) getType().clone(target)); 261 result.fragments().addAll( 262 ASTNode.copySubtrees(target, fragments())); 263 return result; 264 } 265 266 269 final boolean subtreeMatch0(ASTMatcher matcher, Object other) { 270 return matcher.match(this, other); 272 } 273 274 277 void accept0(ASTVisitor visitor) { 278 boolean visitChildren = visitor.visit(this); 279 if (visitChildren) { 280 acceptChild(visitor, getJavadoc()); 282 if (this.ast.apiLevel >= AST.JLS3) { 283 acceptChildren(visitor, this.modifiers); 284 } 285 acceptChild(visitor, getType()); 286 acceptChildren(visitor, this.variableDeclarationFragments); 287 } 288 visitor.endVisit(this); 289 } 290 291 301 public Type getType() { 302 if (this.baseType == null) { 303 synchronized (this) { 305 if (this.baseType == null) { 306 preLazyInit(); 307 this.baseType = this.ast.newPrimitiveType(PrimitiveType.INT); 308 postLazyInit(this.baseType, TYPE_PROPERTY); 309 } 310 } 311 } 312 return this.baseType; 313 } 314 315 325 public void setType(Type type) { 326 if (type == null) { 327 throw new IllegalArgumentException (); 328 } 329 ASTNode oldChild = this.baseType; 330 preReplaceChild(oldChild, type, TYPE_PROPERTY); 331 this.baseType = type; 332 postReplaceChild(oldChild, type, TYPE_PROPERTY); 333 } 334 335 345 public List fragments() { 346 return this.variableDeclarationFragments; 347 } 348 349 352 int memSize() { 353 return super.memSize() + 2 * 4; 354 } 355 356 359 int treeSize() { 360 return 361 memSize() 362 + (this.optionalDocComment == null ? 0 : getJavadoc().treeSize()) 363 + (this.modifiers == null ? 0 : this.modifiers.listSize()) 364 + (this.baseType == null ? 0 : getType().treeSize()) 365 + this.variableDeclarationFragments.listSize(); 366 } 367 } 368 | Popular Tags |