1 11 package org.eclipse.jdt.core.dom; 12 13 import java.util.ArrayList ; 14 import java.util.List ; 15 16 48 public class ArrayCreation extends Expression { 49 50 54 public static final ChildPropertyDescriptor TYPE_PROPERTY = 55 new ChildPropertyDescriptor(ArrayCreation.class, "type", ArrayType.class, MANDATORY, NO_CYCLE_RISK); 57 61 public static final ChildListPropertyDescriptor DIMENSIONS_PROPERTY = 62 new ChildListPropertyDescriptor(ArrayCreation.class, "dimensions", Expression.class, CYCLE_RISK); 64 68 public static final ChildPropertyDescriptor INITIALIZER_PROPERTY = 69 new ChildPropertyDescriptor(ArrayCreation.class, "initializer", ArrayInitializer.class, OPTIONAL, CYCLE_RISK); 71 76 private static final List PROPERTY_DESCRIPTORS; 77 78 static { 79 List properyList = new ArrayList (4); 80 createPropertyList(ArrayCreation.class, properyList); 81 addProperty(TYPE_PROPERTY, properyList); 82 addProperty(DIMENSIONS_PROPERTY, properyList); 83 addProperty(INITIALIZER_PROPERTY, properyList); 84 PROPERTY_DESCRIPTORS = reapPropertyList(properyList); 85 } 86 87 98 public static List propertyDescriptors(int apiLevel) { 99 return PROPERTY_DESCRIPTORS; 100 } 101 102 106 private ArrayType arrayType = null; 107 108 112 private ASTNode.NodeList dimensions = 113 new ASTNode.NodeList(DIMENSIONS_PROPERTY); 114 115 119 private ArrayInitializer optionalInitializer = null; 120 121 129 ArrayCreation(AST ast) { 130 super(ast); 131 } 132 133 136 final List internalStructuralPropertiesForType(int apiLevel) { 137 return propertyDescriptors(apiLevel); 138 } 139 140 143 final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) { 144 if (property == INITIALIZER_PROPERTY) { 145 if (get) { 146 return getInitializer(); 147 } else { 148 setInitializer((ArrayInitializer) child); 149 return null; 150 } 151 } 152 if (property == TYPE_PROPERTY) { 153 if (get) { 154 return getType(); 155 } else { 156 setType((ArrayType) child); 157 return null; 158 } 159 } 160 return super.internalGetSetChildProperty(property, get, child); 162 } 163 164 167 final List internalGetChildListProperty(ChildListPropertyDescriptor property) { 168 if (property == DIMENSIONS_PROPERTY) { 169 return dimensions(); 170 } 171 return super.internalGetChildListProperty(property); 173 } 174 175 178 final int getNodeType0() { 179 return ARRAY_CREATION; 180 } 181 182 185 ASTNode clone0(AST target) { 186 ArrayCreation result = new ArrayCreation(target); 187 result.setSourceRange(this.getStartPosition(), this.getLength()); 188 result.setType((ArrayType) getType().clone(target)); 189 result.dimensions().addAll(ASTNode.copySubtrees(target, dimensions())); 190 result.setInitializer( 191 (ArrayInitializer) ASTNode.copySubtree(target, getInitializer())); 192 return result; 193 } 194 195 198 final boolean subtreeMatch0(ASTMatcher matcher, Object other) { 199 return matcher.match(this, other); 201 } 202 203 206 void accept0(ASTVisitor visitor) { 207 boolean visitChildren = visitor.visit(this); 208 if (visitChildren) { 209 acceptChild(visitor, getType()); 211 acceptChildren(visitor, this.dimensions); 212 acceptChild(visitor, getInitializer()); 213 } 214 visitor.endVisit(this); 215 } 216 217 222 public ArrayType getType() { 223 if (this.arrayType == null) { 224 synchronized (this) { 226 if (this.arrayType == null) { 227 preLazyInit(); 228 this.arrayType = this.ast.newArrayType( 229 this.ast.newPrimitiveType(PrimitiveType.INT)); 230 postLazyInit(this.arrayType, TYPE_PROPERTY); 231 } 232 } 233 } 234 return this.arrayType; 235 } 236 237 247 public void setType(ArrayType type) { 248 if (type == null) { 249 throw new IllegalArgumentException (); 250 } 251 ASTNode oldChild = this.arrayType; 253 preReplaceChild(oldChild, type, TYPE_PROPERTY); 254 this.arrayType = type; 255 postReplaceChild(oldChild, type, TYPE_PROPERTY); 256 } 257 258 265 public List dimensions() { 266 return this.dimensions; 267 } 268 269 276 public ArrayInitializer getInitializer() { 277 return optionalInitializer; 278 } 279 280 292 public void setInitializer(ArrayInitializer initializer) { 293 ASTNode oldChild = this.optionalInitializer; 296 preReplaceChild(oldChild, initializer, INITIALIZER_PROPERTY); 297 this.optionalInitializer = initializer; 298 postReplaceChild(oldChild, initializer, INITIALIZER_PROPERTY); 299 } 300 301 304 int memSize() { 305 return BASE_NODE_SIZE + 3 * 4; 306 } 307 308 311 int treeSize() { 312 int size = memSize() 313 + (this.arrayType == null ? 0 : getType().treeSize()) 314 + (this.optionalInitializer == null ? 0 : getInitializer().treeSize()) 315 + this.dimensions.listSize(); 316 return size; 317 } 318 } 319 320 | Popular Tags |