1 11 package org.eclipse.jdt.core.dom; 12 13 import java.util.ArrayList ; 14 import java.util.List ; 15 16 34 public class MethodInvocation extends Expression { 35 36 40 public static final ChildPropertyDescriptor EXPRESSION_PROPERTY = 41 new ChildPropertyDescriptor(MethodInvocation.class, "expression", Expression.class, OPTIONAL, CYCLE_RISK); 43 47 public static final ChildListPropertyDescriptor TYPE_ARGUMENTS_PROPERTY = 48 new ChildListPropertyDescriptor(MethodInvocation.class, "typeArguments", Type.class, NO_CYCLE_RISK); 50 54 public static final ChildPropertyDescriptor NAME_PROPERTY = 55 new ChildPropertyDescriptor(MethodInvocation.class, "name", SimpleName.class, MANDATORY, NO_CYCLE_RISK); 57 61 public static final ChildListPropertyDescriptor ARGUMENTS_PROPERTY = 62 new ChildListPropertyDescriptor(MethodInvocation.class, "arguments", Expression.class, CYCLE_RISK); 64 70 private static final List PROPERTY_DESCRIPTORS_2_0; 71 72 78 private static final List PROPERTY_DESCRIPTORS_3_0; 79 80 static { 81 List properyList = new ArrayList (4); 82 createPropertyList(MethodInvocation.class, properyList); 83 addProperty(EXPRESSION_PROPERTY, properyList); 84 addProperty(NAME_PROPERTY, properyList); 85 addProperty(ARGUMENTS_PROPERTY, properyList); 86 PROPERTY_DESCRIPTORS_2_0 = reapPropertyList(properyList); 87 88 properyList = new ArrayList (5); 89 createPropertyList(MethodInvocation.class, properyList); 90 addProperty(EXPRESSION_PROPERTY, properyList); 91 addProperty(TYPE_ARGUMENTS_PROPERTY, properyList); 92 addProperty(NAME_PROPERTY, properyList); 93 addProperty(ARGUMENTS_PROPERTY, properyList); 94 PROPERTY_DESCRIPTORS_3_0 = reapPropertyList(properyList); 95 } 96 97 108 public static List propertyDescriptors(int apiLevel) { 109 if (apiLevel == AST.JLS2_INTERNAL) { 110 return PROPERTY_DESCRIPTORS_2_0; 111 } else { 112 return PROPERTY_DESCRIPTORS_3_0; 113 } 114 } 115 116 119 private Expression optionalExpression = null; 120 121 127 private ASTNode.NodeList typeArguments = null; 128 129 133 private SimpleName methodName = null; 134 135 139 private ASTNode.NodeList arguments = 140 new ASTNode.NodeList(ARGUMENTS_PROPERTY); 141 142 149 MethodInvocation(AST ast) { 150 super(ast); 151 if (ast.apiLevel >= AST.JLS3) { 152 this.typeArguments = new ASTNode.NodeList(TYPE_ARGUMENTS_PROPERTY); 153 } 154 } 155 156 159 final List internalStructuralPropertiesForType(int apiLevel) { 160 return propertyDescriptors(apiLevel); 161 } 162 163 166 final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) { 167 if (property == NAME_PROPERTY) { 168 if (get) { 169 return getName(); 170 } else { 171 setName((SimpleName) child); 172 return null; 173 } 174 } 175 if (property == EXPRESSION_PROPERTY) { 176 if (get) { 177 return getExpression(); 178 } else { 179 setExpression((Expression) child); 180 return null; 181 } 182 } 183 return super.internalGetSetChildProperty(property, get, child); 185 } 186 187 190 final List internalGetChildListProperty(ChildListPropertyDescriptor property) { 191 if (property == ARGUMENTS_PROPERTY) { 192 return arguments(); 193 } 194 if (property == TYPE_ARGUMENTS_PROPERTY) { 195 return typeArguments(); 196 } 197 return super.internalGetChildListProperty(property); 199 } 200 201 204 final int getNodeType0() { 205 return METHOD_INVOCATION; 206 } 207 208 211 ASTNode clone0(AST target) { 212 MethodInvocation result = new MethodInvocation(target); 213 result.setSourceRange(this.getStartPosition(), this.getLength()); 214 result.setName((SimpleName) getName().clone(target)); 215 result.setExpression( 216 (Expression) ASTNode.copySubtree(target, getExpression())); 217 if (this.ast.apiLevel >= AST.JLS3) { 218 result.typeArguments().addAll(ASTNode.copySubtrees(target, typeArguments())); 219 } 220 result.arguments().addAll(ASTNode.copySubtrees(target, arguments())); 221 return result; 222 } 223 224 227 final boolean subtreeMatch0(ASTMatcher matcher, Object other) { 228 return matcher.match(this, other); 230 } 231 232 235 void accept0(ASTVisitor visitor) { 236 boolean visitChildren = visitor.visit(this); 237 if (visitChildren) { 238 acceptChild(visitor, getExpression()); 240 if (this.ast.apiLevel >= AST.JLS3) { 241 acceptChildren(visitor, this.typeArguments); 242 } 243 acceptChild(visitor, getName()); 244 acceptChildren(visitor, this.arguments); 245 } 246 visitor.endVisit(this); 247 } 248 249 255 public Expression getExpression() { 256 return this.optionalExpression; 257 } 258 259 271 public void setExpression(Expression expression) { 272 ASTNode oldChild = this.optionalExpression; 273 preReplaceChild(oldChild, expression, EXPRESSION_PROPERTY); 274 this.optionalExpression = expression; 275 postReplaceChild(oldChild, expression, EXPRESSION_PROPERTY); 276 } 277 278 288 public List typeArguments() { 289 if (this.typeArguments == null) { 291 unsupportedIn2(); 292 } 293 return this.typeArguments; 294 } 295 296 301 public SimpleName getName() { 302 if (this.methodName == null) { 303 synchronized (this) { 305 if (this.methodName == null) { 306 preLazyInit(); 307 this.methodName = new SimpleName(this.ast); 308 postLazyInit(this.methodName, NAME_PROPERTY); 309 } 310 } 311 } 312 return this.methodName; 313 } 314 315 326 public void setName(SimpleName name) { 327 if (name == null) { 328 throw new IllegalArgumentException (); 329 } 330 ASTNode oldChild = this.methodName; 331 preReplaceChild(oldChild, name, NAME_PROPERTY); 332 this.methodName = name; 333 postReplaceChild(oldChild, name, NAME_PROPERTY); 334 } 335 336 343 public List arguments() { 344 return this.arguments; 345 } 346 347 359 public IMethodBinding resolveMethodBinding() { 360 return this.ast.getBindingResolver().resolveMethod(this); 361 } 362 363 366 int memSize() { 367 return BASE_NODE_SIZE + 4 * 4; 369 } 370 371 374 int treeSize() { 375 return 376 memSize() 377 + (this.optionalExpression == null ? 0 : getExpression().treeSize()) 378 + (this.typeArguments == null ? 0 : this.typeArguments.listSize()) 379 + (this.methodName == null ? 0 : getName().treeSize()) 380 + (this.arguments == null ? 0 : this.arguments.listSize()); 381 } 382 } 383 384 | Popular Tags |