1 11 12 package org.eclipse.jdt.core.dom; 13 14 import java.util.ArrayList ; 15 import java.util.List ; 16 17 62 public class ClassInstanceCreation extends Expression { 63 64 68 public static final ChildListPropertyDescriptor TYPE_ARGUMENTS_PROPERTY = 69 new ChildListPropertyDescriptor(ClassInstanceCreation.class, "typeArguments", Type.class, NO_CYCLE_RISK); 71 75 public static final ChildPropertyDescriptor EXPRESSION_PROPERTY = 76 new ChildPropertyDescriptor(ClassInstanceCreation.class, "expression", Expression.class, OPTIONAL, CYCLE_RISK); 78 82 public static final ChildPropertyDescriptor NAME_PROPERTY = 83 new ChildPropertyDescriptor(ClassInstanceCreation.class, "name", Name.class, MANDATORY, NO_CYCLE_RISK); 85 89 public static final ChildPropertyDescriptor TYPE_PROPERTY = 90 new ChildPropertyDescriptor(ClassInstanceCreation.class, "type", Type.class, MANDATORY, NO_CYCLE_RISK); 92 96 public static final ChildListPropertyDescriptor ARGUMENTS_PROPERTY = 97 new ChildListPropertyDescriptor(ClassInstanceCreation.class, "arguments", Expression.class, CYCLE_RISK); 99 103 public static final ChildPropertyDescriptor ANONYMOUS_CLASS_DECLARATION_PROPERTY = 104 new ChildPropertyDescriptor(ClassInstanceCreation.class, "anonymousClassDeclaration", AnonymousClassDeclaration.class, OPTIONAL, CYCLE_RISK); 106 112 private static final List PROPERTY_DESCRIPTORS_2_0; 113 114 120 private static final List PROPERTY_DESCRIPTORS_3_0; 121 122 static { 123 List properyList = new ArrayList (5); 124 createPropertyList(ClassInstanceCreation.class, properyList); 125 addProperty(EXPRESSION_PROPERTY, properyList); 126 addProperty(NAME_PROPERTY, properyList); 127 addProperty(ARGUMENTS_PROPERTY, properyList); 128 addProperty(ANONYMOUS_CLASS_DECLARATION_PROPERTY, properyList); 129 PROPERTY_DESCRIPTORS_2_0 = reapPropertyList(properyList); 130 131 properyList = new ArrayList (6); 132 createPropertyList(ClassInstanceCreation.class, properyList); 133 addProperty(EXPRESSION_PROPERTY, properyList); 134 addProperty(TYPE_ARGUMENTS_PROPERTY, properyList); 135 addProperty(TYPE_PROPERTY, properyList); 136 addProperty(ARGUMENTS_PROPERTY, properyList); 137 addProperty(ANONYMOUS_CLASS_DECLARATION_PROPERTY, properyList); 138 PROPERTY_DESCRIPTORS_3_0 = reapPropertyList(properyList); 139 } 140 141 152 public static List propertyDescriptors(int apiLevel) { 153 if (apiLevel == AST.JLS2_INTERNAL) { 154 return PROPERTY_DESCRIPTORS_2_0; 155 } else { 156 return PROPERTY_DESCRIPTORS_3_0; 157 } 158 } 159 160 163 private Expression optionalExpression = null; 164 165 171 private ASTNode.NodeList typeArguments = null; 172 173 177 private Name typeName = null; 178 179 183 private Type type = null; 184 185 189 private ASTNode.NodeList arguments = 190 new ASTNode.NodeList(ARGUMENTS_PROPERTY); 191 192 196 private AnonymousClassDeclaration optionalAnonymousClassDeclaration = null; 197 198 211 ClassInstanceCreation (AST ast) { 212 super(ast); 213 if (ast.apiLevel >= AST.JLS3) { 214 this.typeArguments = new ASTNode.NodeList(TYPE_ARGUMENTS_PROPERTY); 215 } 216 } 217 218 222 final List internalStructuralPropertiesForType(int apiLevel) { 223 return propertyDescriptors(apiLevel); 224 } 225 226 227 230 final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) { 231 if (property == EXPRESSION_PROPERTY) { 232 if (get) { 233 return getExpression(); 234 } else { 235 setExpression((Expression) child); 236 return null; 237 } 238 } 239 if (property == NAME_PROPERTY) { 240 if (get) { 241 return getName(); 242 } else { 243 setName((Name) child); 244 return null; 245 } 246 } 247 if (property == TYPE_PROPERTY) { 248 if (get) { 249 return getType(); 250 } else { 251 setType((Type) child); 252 return null; 253 } 254 } 255 if (property == ANONYMOUS_CLASS_DECLARATION_PROPERTY) { 256 if (get) { 257 return getAnonymousClassDeclaration(); 258 } else { 259 setAnonymousClassDeclaration((AnonymousClassDeclaration) child); 260 return null; 261 } 262 } 263 return super.internalGetSetChildProperty(property, get, child); 265 } 266 267 270 final List internalGetChildListProperty(ChildListPropertyDescriptor property) { 271 if (property == ARGUMENTS_PROPERTY) { 272 return arguments(); 273 } 274 if (property == TYPE_ARGUMENTS_PROPERTY) { 275 return typeArguments(); 276 } 277 return super.internalGetChildListProperty(property); 279 } 280 281 284 final int getNodeType0() { 285 return CLASS_INSTANCE_CREATION; 286 } 287 288 291 ASTNode clone0(AST target) { 292 ClassInstanceCreation result = new ClassInstanceCreation(target); 293 result.setSourceRange(this.getStartPosition(), this.getLength()); 294 result.setExpression( 295 (Expression) ASTNode.copySubtree(target, getExpression())); 296 if (this.ast.apiLevel == AST.JLS2_INTERNAL) { 297 result.setName((Name) getName().clone(target)); 298 } 299 if (this.ast.apiLevel >= AST.JLS3) { 300 result.typeArguments().addAll(ASTNode.copySubtrees(target, typeArguments())); 301 result.setType((Type) getType().clone(target)); 302 } 303 result.arguments().addAll(ASTNode.copySubtrees(target, arguments())); 304 result.setAnonymousClassDeclaration( 305 (AnonymousClassDeclaration) 306 ASTNode.copySubtree(target, getAnonymousClassDeclaration())); 307 return result; 308 } 309 310 313 final boolean subtreeMatch0(ASTMatcher matcher, Object other) { 314 return matcher.match(this, other); 316 } 317 318 321 void accept0(ASTVisitor visitor) { 322 boolean visitChildren = visitor.visit(this); 323 if (visitChildren) { 324 acceptChild(visitor, getExpression()); 326 if (this.ast.apiLevel == AST.JLS2_INTERNAL) { 327 acceptChild(visitor, getName()); 328 } 329 if (this.ast.apiLevel >= AST.JLS3) { 330 acceptChildren(visitor, this.typeArguments); 331 acceptChild(visitor, getType()); 332 } 333 acceptChildren(visitor, this.arguments); 334 acceptChild(visitor, getAnonymousClassDeclaration()); 335 } 336 visitor.endVisit(this); 337 } 338 339 345 public Expression getExpression() { 346 return this.optionalExpression; 347 } 348 349 361 public void setExpression(Expression expression) { 362 ASTNode oldChild = this.optionalExpression; 365 preReplaceChild(oldChild, expression, EXPRESSION_PROPERTY); 366 this.optionalExpression = expression; 367 postReplaceChild(oldChild, expression, EXPRESSION_PROPERTY); 368 } 369 370 380 public List typeArguments() { 381 if (this.typeArguments == null) { 383 unsupportedIn2(); 384 } 385 return this.typeArguments; 386 } 387 388 399 public Name getName() { 400 return internalGetName(); 401 } 402 403 408 Name internalGetName() { 409 supportedOnlyIn2(); 410 if (this.typeName == null) { 411 synchronized (this) { 413 if (this.typeName == null) { 414 preLazyInit(); 415 this.typeName = new SimpleName(this.ast); 416 postLazyInit(this.typeName, NAME_PROPERTY); 417 } 418 } 419 } 420 return typeName; 421 } 422 423 439 public void setName(Name name) { 440 internalSetName(name); 441 } 442 443 448 void internalSetName(Name name) { 449 supportedOnlyIn2(); 450 if (name == null) { 451 throw new IllegalArgumentException (); 452 } 453 ASTNode oldChild = this.typeName; 454 preReplaceChild(oldChild, name, NAME_PROPERTY); 455 this.typeName = name; 456 postReplaceChild(oldChild, name, NAME_PROPERTY); 457 } 458 459 468 public Type getType() { 469 unsupportedIn2(); 470 if (this.type == null) { 471 synchronized (this) { 473 if (this.type == null) { 474 preLazyInit(); 475 this.type = new SimpleType(this.ast); 476 postLazyInit(this.type, TYPE_PROPERTY); 477 } 478 } 479 } 480 return this.type; 481 } 482 483 497 public void setType(Type type) { 498 unsupportedIn2(); 499 if (type == null) { 500 throw new IllegalArgumentException (); 501 } 502 ASTNode oldChild = this.type; 503 preReplaceChild(oldChild, type, TYPE_PROPERTY); 504 this.type = type; 505 postReplaceChild(oldChild, type, TYPE_PROPERTY); 506 } 507 508 515 public List arguments() { 516 return this.arguments; 517 } 518 519 525 public AnonymousClassDeclaration getAnonymousClassDeclaration() { 526 return this.optionalAnonymousClassDeclaration; 527 } 528 529 536 public void setAnonymousClassDeclaration(AnonymousClassDeclaration decl) { 537 ASTNode oldChild = this.optionalAnonymousClassDeclaration; 538 preReplaceChild(oldChild, decl, ANONYMOUS_CLASS_DECLARATION_PROPERTY); 539 this.optionalAnonymousClassDeclaration = decl; 540 postReplaceChild(oldChild, decl, ANONYMOUS_CLASS_DECLARATION_PROPERTY); 541 } 542 543 555 public IMethodBinding resolveConstructorBinding() { 556 return this.ast.getBindingResolver().resolveConstructor(this); 557 } 558 559 562 int memSize() { 563 return BASE_NODE_SIZE + 6 * 4; 565 } 566 567 570 int treeSize() { 571 return 575 memSize() 576 + (this.typeName == null ? 0 : getName().treeSize()) 577 + (this.type == null ? 0 : getType().treeSize()) 578 + (this.optionalExpression == null ? 0 : getExpression().treeSize()) 579 + (this.typeArguments == null ? 0 : this.typeArguments.listSize()) 580 + (this.arguments == null ? 0 : this.arguments.listSize()) 581 + (this.optionalAnonymousClassDeclaration == null ? 0 : getAnonymousClassDeclaration().treeSize()); 582 } 583 } 584 585 | Popular Tags |