1 /*******************************************************************************
2 * Copyright (c) 2000, 2008 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
12 package net.sourceforge.phpdt.core.dom;
14 import java.util.ArrayList;
15 import java.util.List;
18 * Simple or qualified "super" method invocation expression AST node type.
21 * SuperMethodInvocation:
22 * [ ClassName <b>.</b> ] <b>super</b> <b>.</b> Identifier
23 * <b>(</b> [ Expression { <b>,</b> Expression } ] <b>)</b>
25 * For JLS3, type arguments are added:
27 * SuperMethodInvocation:
28 * [ ClassName <b>.</b> ] <b>super</b> <b>.</b>
29 * [ <b><</b> Type { <b>,</b> Type } <b>></b> ]
30 * Identifier <b>(</b> [ Expression { <b>,</b> Expression } ] <b>)</b>
34 * @noinstantiate This class is not intended to be instantiated by clients.
36 public class SuperMethodInvocation extends Expression {
39 * The "qualifier" structural property of this node type.
42 public static final ChildPropertyDescriptor QUALIFIER_PROPERTY =
43 new ChildPropertyDescriptor(SuperMethodInvocation.class, "qualifier", Name.class, OPTIONAL, NO_CYCLE_RISK); //$NON-NLS-1$
46 * The "typeArguments" structural property of this node type (added in JLS3 API).
49 public static final ChildListPropertyDescriptor TYPE_ARGUMENTS_PROPERTY =
50 new ChildListPropertyDescriptor(SuperMethodInvocation.class, "typeArguments", Type.class, NO_CYCLE_RISK); //$NON-NLS-1$
53 * The "name" structural property of this node type.
56 public static final ChildPropertyDescriptor NAME_PROPERTY =
57 new ChildPropertyDescriptor(SuperMethodInvocation.class, "name", SimpleName.class, MANDATORY, NO_CYCLE_RISK); //$NON-NLS-1$
60 * The "arguments" structural property of this node type.
63 public static final ChildListPropertyDescriptor ARGUMENTS_PROPERTY =
64 new ChildListPropertyDescriptor(SuperMethodInvocation.class, "arguments", Expression.class, CYCLE_RISK); //$NON-NLS-1$
67 * A list of property descriptors (element type:
68 * {@link StructuralPropertyDescriptor}),
69 * or null if uninitialized.
72 private static final List PROPERTY_DESCRIPTORS_2_0;
75 * A list of property descriptors (element type:
76 * {@link StructuralPropertyDescriptor}),
77 * or null if uninitialized.
80 private static final List PROPERTY_DESCRIPTORS_3_0;
83 List propertyList = new ArrayList(4);
84 createPropertyList(SuperMethodInvocation.class, propertyList);
85 addProperty(QUALIFIER_PROPERTY, propertyList);
86 addProperty(NAME_PROPERTY, propertyList);
87 addProperty(ARGUMENTS_PROPERTY, propertyList);
88 PROPERTY_DESCRIPTORS_2_0 = reapPropertyList(propertyList);
90 propertyList = new ArrayList(5);
91 createPropertyList(SuperMethodInvocation.class, propertyList);
92 addProperty(QUALIFIER_PROPERTY, propertyList);
93 addProperty(TYPE_ARGUMENTS_PROPERTY, propertyList);
94 addProperty(NAME_PROPERTY, propertyList);
95 addProperty(ARGUMENTS_PROPERTY, propertyList);
96 PROPERTY_DESCRIPTORS_3_0 = reapPropertyList(propertyList);
100 * Returns a list of structural property descriptors for this node type.
101 * Clients must not modify the result.
103 * @param apiLevel the API level; one of the
104 * <code>AST.JLS*</code> constants
106 * @return a list of property descriptors (element type:
107 * {@link StructuralPropertyDescriptor})
110 public static List propertyDescriptors(int apiLevel) {
111 if (apiLevel == AST.JLS2_INTERNAL) {
112 return PROPERTY_DESCRIPTORS_2_0;
114 return PROPERTY_DESCRIPTORS_3_0;
119 * The optional qualifier; <code>null</code> for none; defaults to none.
121 private Name optionalQualifier = null;
124 * The type arguments (element type: <code>Type</code>).
125 * Null in JLS2. Added in JLS3; defaults to an empty list
129 private ASTNode.NodeList typeArguments = null;
132 * The method name; lazily initialized; defaults to a unspecified,
133 * legal Java method name.
135 private SimpleName methodName = null;
138 * The list of argument expressions (element type:
139 * <code>Expression</code>). Defaults to an empty list.
141 private ASTNode.NodeList arguments =
142 new ASTNode.NodeList(ARGUMENTS_PROPERTY);
145 * Creates a new AST node for a "super" method invocation expression owned
146 * by the given AST. By default, no qualifier, no type arguments,
147 * an unspecified, but legal, method name, and an empty list of arguments.
149 * @param ast the AST that is to own this node
151 SuperMethodInvocation(AST ast) {
153 if (ast.apiLevel >= AST.JLS3) {
154 this.typeArguments = new ASTNode.NodeList(TYPE_ARGUMENTS_PROPERTY);
158 /* (omit javadoc for this method)
159 * Method declared on ASTNode.
161 final List internalStructuralPropertiesForType(int apiLevel) {
162 return propertyDescriptors(apiLevel);
165 /* (omit javadoc for this method)
166 * Method declared on ASTNode.
168 final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) {
169 if (property == QUALIFIER_PROPERTY) {
171 return getQualifier();
173 setQualifier((Name) child);
177 if (property == NAME_PROPERTY) {
181 setName((SimpleName) child);
185 // allow default implementation to flag the error
186 return super.internalGetSetChildProperty(property, get, child);
189 /* (omit javadoc for this method)
190 * Method declared on ASTNode.
192 final List internalGetChildListProperty(ChildListPropertyDescriptor property) {
193 if (property == ARGUMENTS_PROPERTY) {
196 if (property == TYPE_ARGUMENTS_PROPERTY) {
197 return typeArguments();
199 // allow default implementation to flag the error
200 return super.internalGetChildListProperty(property);
203 /* (omit javadoc for this method)
204 * Method declared on ASTNode.
206 final int getNodeType0() {
207 return SUPER_METHOD_INVOCATION;
210 /* (omit javadoc for this method)
211 * Method declared on ASTNode.
213 ASTNode clone0(AST target) {
214 SuperMethodInvocation result = new SuperMethodInvocation(target);
215 result.setSourceRange(this.getStartPosition(), this.getLength());
216 result.setName((SimpleName) getName().clone(target));
217 result.setQualifier((Name) ASTNode.copySubtree(target, getQualifier()));
218 if (this.ast.apiLevel >= AST.JLS3) {
219 result.typeArguments().addAll(ASTNode.copySubtrees(target, typeArguments()));
221 result.arguments().addAll(ASTNode.copySubtrees(target, arguments()));
225 /* (omit javadoc for this method)
226 * Method declared on ASTNode.
228 final boolean subtreeMatch0(ASTMatcher matcher, Object other) {
229 // dispatch to correct overloaded match method
230 return matcher.match(this, other);
233 /* (omit javadoc for this method)
234 * Method declared on ASTNode.
236 void accept0(ASTVisitor visitor) {
237 boolean visitChildren = visitor.visit(this);
239 // visit children in normal left to right reading order
240 acceptChild(visitor, getQualifier());
241 if (this.ast.apiLevel >= AST.JLS3) {
242 acceptChildren(visitor, this.typeArguments);
244 acceptChild(visitor, getName());
245 acceptChildren(visitor, this.arguments);
247 visitor.endVisit(this);
251 * Returns the qualifier of this "super" method invocation expression, or
252 * <code>null</code> if there is none.
254 * @return the qualifier name node, or <code>null</code> if there is none
256 public Name getQualifier() {
257 return this.optionalQualifier;
261 * Returns true if the resolved return type has been inferred from the assignment context (JLS3 15.12.2.8), false otherwise.
263 * This information is available only when bindings are requested when the AST is being built
266 * @return true if the resolved return type has been inferred from the assignment context (JLS3 15.12.2.8), false otherwise
269 public boolean isResolvedTypeInferredFromExpectedType() {
270 return this.ast.getBindingResolver().isResolvedTypeInferredFromExpectedType(this);
275 * Sets or clears the qualifier of this "super" method invocation expression.
277 * @param name the qualifier name node, or <code>null</code> if
279 * @exception IllegalArgumentException if:
281 * <li>the node belongs to a different AST</li>
282 * <li>the node already has a parent</li>
285 public void setQualifier(Name name) {
286 ASTNode oldChild = this.optionalQualifier;
287 preReplaceChild(oldChild, name, QUALIFIER_PROPERTY);
288 this.optionalQualifier = name;
289 postReplaceChild(oldChild, name, QUALIFIER_PROPERTY);
293 * Returns the live ordered list of type arguments of this method
294 * invocation (added in JLS3 API).
296 * @return the live list of type arguments
297 * (element type: <code>Type</code>)
298 * @exception UnsupportedOperationException if this operation is used in
302 public List typeArguments() {
303 // more efficient than just calling unsupportedIn2() to check
304 if (this.typeArguments == null) {
307 return this.typeArguments;
311 * Returns the name of the method invoked in this expression.
313 * @return the method name node
315 public SimpleName getName() {
316 if (this.methodName == null) {
317 // lazy init must be thread-safe for readers
318 synchronized (this) {
319 if (this.methodName == null) {
321 this.methodName = new SimpleName(this.ast);
322 postLazyInit(this.methodName, NAME_PROPERTY);
326 return this.methodName;
330 * Sets the name of the method invoked in this expression to the
333 * @param name the new method name
334 * @exception IllegalArgumentException if:
336 * <li>the node belongs to a different AST</li>
337 * <li>the node already has a parent</li>
340 public void setName(SimpleName name) {
342 throw new IllegalArgumentException();
344 ASTNode oldChild = this.methodName;
345 preReplaceChild(oldChild, name, NAME_PROPERTY);
346 this.methodName = name;
347 postReplaceChild(oldChild, name, NAME_PROPERTY);
351 * Returns the live ordered list of argument expressions in this
352 * "super" method invocation expression.
354 * @return the live list of argument expressions
355 * (element type: <code>Expression</code>)
357 public List arguments() {
358 return this.arguments;
362 * Resolves and returns the binding for the method invoked by this
365 * Note that bindings are generally unavailable unless requested when the
366 * AST is being built.
369 * @return the method binding, or <code>null</code> if the binding cannot
373 public IMethodBinding resolveMethodBinding() {
374 return this.ast.getBindingResolver().resolveMethod(this);
377 /* (omit javadoc for this method)
378 * Method declared on ASTNode.
381 // treat Code as free
382 return BASE_NODE_SIZE + 4 * 4;
385 /* (omit javadoc for this method)
386 * Method declared on ASTNode.
391 + (this.optionalQualifier == null ? 0 : getQualifier().treeSize())
392 + (this.typeArguments == null ? 0 : this.typeArguments.listSize())
393 + (this.methodName == null ? 0 : getName().treeSize())
394 + (this.arguments == null ? 0 : this.arguments.listSize());