removed unused private methods.
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / core / dom / SuperMethodInvocation.java
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
7  *
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11
12 package net.sourceforge.phpdt.core.dom;
13
14 import java.util.ArrayList;
15 import java.util.List;
16
17 /**
18  * Simple or qualified "super" method invocation expression AST node type.
19  * For JLS2:
20  * <pre>
21  * SuperMethodInvocation:
22  *     [ ClassName <b>.</b> ] <b>super</b> <b>.</b> Identifier
23  *         <b>(</b> [ Expression { <b>,</b> Expression } ] <b>)</b>
24  * </pre>
25  * For JLS3, type arguments are added:
26  * <pre>
27  * SuperMethodInvocation:
28  *     [ ClassName <b>.</b> ] <b>super</b> <b>.</b>
29  *         [ <b>&lt;</b> Type { <b>,</b> Type } <b>&gt;</b> ]
30  *         Identifier <b>(</b> [ Expression { <b>,</b> Expression } ] <b>)</b>
31  * </pre>
32  *
33  * @since 2.0
34  * @noinstantiate This class is not intended to be instantiated by clients.
35  */
36 public class SuperMethodInvocation extends Expression {
37
38         /**
39          * The "qualifier" structural property of this node type.
40          * @since 3.0
41          */
42         public static final ChildPropertyDescriptor QUALIFIER_PROPERTY =
43                 new ChildPropertyDescriptor(SuperMethodInvocation.class, "qualifier", Name.class, OPTIONAL, NO_CYCLE_RISK); //$NON-NLS-1$
44
45         /**
46          * The "typeArguments" structural property of this node type (added in JLS3 API).
47          * @since 3.1
48          */
49         public static final ChildListPropertyDescriptor TYPE_ARGUMENTS_PROPERTY =
50                 new ChildListPropertyDescriptor(SuperMethodInvocation.class, "typeArguments", Type.class, NO_CYCLE_RISK); //$NON-NLS-1$
51
52         /**
53          * The "name" structural property of this node type.
54          * @since 3.0
55          */
56         public static final ChildPropertyDescriptor NAME_PROPERTY =
57                 new ChildPropertyDescriptor(SuperMethodInvocation.class, "name", SimpleName.class, MANDATORY, NO_CYCLE_RISK); //$NON-NLS-1$
58
59         /**
60          * The "arguments" structural property of this node type.
61          * @since 3.0
62          */
63         public static final ChildListPropertyDescriptor ARGUMENTS_PROPERTY =
64                 new ChildListPropertyDescriptor(SuperMethodInvocation.class, "arguments", Expression.class, CYCLE_RISK); //$NON-NLS-1$
65
66         /**
67          * A list of property descriptors (element type:
68          * {@link StructuralPropertyDescriptor}),
69          * or null if uninitialized.
70          * @since 3.0
71          */
72         private static final List PROPERTY_DESCRIPTORS_2_0;
73
74         /**
75          * A list of property descriptors (element type:
76          * {@link StructuralPropertyDescriptor}),
77          * or null if uninitialized.
78          * @since 3.1
79          */
80         private static final List PROPERTY_DESCRIPTORS_3_0;
81
82         static {
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);
89
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);
97         }
98
99         /**
100          * Returns a list of structural property descriptors for this node type.
101          * Clients must not modify the result.
102          *
103          * @param apiLevel the API level; one of the
104          * <code>AST.JLS*</code> constants
105
106          * @return a list of property descriptors (element type:
107          * {@link StructuralPropertyDescriptor})
108          * @since 3.0
109          */
110         public static List propertyDescriptors(int apiLevel) {
111                 if (apiLevel == AST.JLS2_INTERNAL) {
112                         return PROPERTY_DESCRIPTORS_2_0;
113                 } else {
114                         return PROPERTY_DESCRIPTORS_3_0;
115                 }
116         }
117
118         /**
119          * The optional qualifier; <code>null</code> for none; defaults to none.
120          */
121         private Name optionalQualifier = null;
122
123         /**
124          * The type arguments (element type: <code>Type</code>).
125          * Null in JLS2. Added in JLS3; defaults to an empty list
126          * (see constructor).
127          * @since 3.1
128          */
129         private ASTNode.NodeList typeArguments = null;
130
131         /**
132          * The method name; lazily initialized; defaults to a unspecified,
133          * legal Java method name.
134          */
135         private SimpleName methodName = null;
136
137         /**
138          * The list of argument expressions (element type:
139          * <code>Expression</code>). Defaults to an empty list.
140          */
141         private ASTNode.NodeList arguments =
142                 new ASTNode.NodeList(ARGUMENTS_PROPERTY);
143
144         /**
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.
148          *
149          * @param ast the AST that is to own this node
150          */
151         SuperMethodInvocation(AST ast) {
152                 super(ast);
153                 if (ast.apiLevel >= AST.JLS3) {
154                         this.typeArguments = new ASTNode.NodeList(TYPE_ARGUMENTS_PROPERTY);
155                 }
156         }
157
158         /* (omit javadoc for this method)
159          * Method declared on ASTNode.
160          */
161         final List internalStructuralPropertiesForType(int apiLevel) {
162                 return propertyDescriptors(apiLevel);
163         }
164
165         /* (omit javadoc for this method)
166          * Method declared on ASTNode.
167          */
168         final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) {
169                 if (property == QUALIFIER_PROPERTY) {
170                         if (get) {
171                                 return getQualifier();
172                         } else {
173                                 setQualifier((Name) child);
174                                 return null;
175                         }
176                 }
177                 if (property == NAME_PROPERTY) {
178                         if (get) {
179                                 return getName();
180                         } else {
181                                 setName((SimpleName) child);
182                                 return null;
183                         }
184                 }
185                 // allow default implementation to flag the error
186                 return super.internalGetSetChildProperty(property, get, child);
187         }
188
189         /* (omit javadoc for this method)
190          * Method declared on ASTNode.
191          */
192         final List internalGetChildListProperty(ChildListPropertyDescriptor property) {
193                 if (property == ARGUMENTS_PROPERTY) {
194                         return arguments();
195                 }
196                 if (property == TYPE_ARGUMENTS_PROPERTY) {
197                         return typeArguments();
198                 }
199                 // allow default implementation to flag the error
200                 return super.internalGetChildListProperty(property);
201         }
202
203         /* (omit javadoc for this method)
204          * Method declared on ASTNode.
205          */
206         final int getNodeType0() {
207                 return SUPER_METHOD_INVOCATION;
208         }
209
210         /* (omit javadoc for this method)
211          * Method declared on ASTNode.
212          */
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()));
220                 }
221                 result.arguments().addAll(ASTNode.copySubtrees(target, arguments()));
222                 return result;
223         }
224
225         /* (omit javadoc for this method)
226          * Method declared on ASTNode.
227          */
228         final boolean subtreeMatch0(ASTMatcher matcher, Object other) {
229                 // dispatch to correct overloaded match method
230                 return matcher.match(this, other);
231         }
232
233         /* (omit javadoc for this method)
234          * Method declared on ASTNode.
235          */
236         void accept0(ASTVisitor visitor) {
237                 boolean visitChildren = visitor.visit(this);
238                 if (visitChildren) {
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);
243                         }
244                         acceptChild(visitor, getName());
245                         acceptChildren(visitor, this.arguments);
246                 }
247                 visitor.endVisit(this);
248         }
249
250         /**
251          * Returns the qualifier of this "super" method invocation expression, or
252          * <code>null</code> if there is none.
253          *
254          * @return the qualifier name node, or <code>null</code> if there is none
255          */
256         public Name getQualifier() {
257                 return this.optionalQualifier;
258         }
259
260         /**
261          * Returns true if the resolved return type has been inferred from the assignment context (JLS3 15.12.2.8), false otherwise.
262          * <p>
263          * This information is available only when bindings are requested when the AST is being built
264          * </p>.
265          *
266          * @return true if the resolved return type has been inferred from the assignment context (JLS3 15.12.2.8), false otherwise
267          * @since 3.3
268          */
269         public boolean isResolvedTypeInferredFromExpectedType() {
270                 return this.ast.getBindingResolver().isResolvedTypeInferredFromExpectedType(this);
271         }
272
273
274         /**
275          * Sets or clears the qualifier of this "super" method invocation expression.
276          *
277          * @param name the qualifier name node, or <code>null</code> if
278          *    there is none
279          * @exception IllegalArgumentException if:
280          * <ul>
281          * <li>the node belongs to a different AST</li>
282          * <li>the node already has a parent</li>
283          * </ul>
284          */
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);
290         }
291
292         /**
293          * Returns the live ordered list of type arguments of this method
294          * invocation (added in JLS3 API).
295          *
296          * @return the live list of type arguments
297          *    (element type: <code>Type</code>)
298          * @exception UnsupportedOperationException if this operation is used in
299          * a JLS2 AST
300          * @since 3.1
301          */
302         public List typeArguments() {
303                 // more efficient than just calling unsupportedIn2() to check
304                 if (this.typeArguments == null) {
305                         unsupportedIn2();
306                 }
307                 return this.typeArguments;
308         }
309
310         /**
311          * Returns the name of the method invoked in this expression.
312          *
313          * @return the method name node
314          */
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) {
320                                         preLazyInit();
321                                         this.methodName = new SimpleName(this.ast);
322                                         postLazyInit(this.methodName, NAME_PROPERTY);
323                                 }
324                         }
325                 }
326                 return this.methodName;
327         }
328
329         /**
330          * Sets the name of the method invoked in this expression to the
331          * given name.
332          *
333          * @param name the new method name
334          * @exception IllegalArgumentException if:
335          * <ul>
336          * <li>the node belongs to a different AST</li>
337          * <li>the node already has a parent</li>
338          * </ul>
339          */
340         public void setName(SimpleName name) {
341                 if (name == null) {
342                         throw new IllegalArgumentException();
343                 }
344                 ASTNode oldChild = this.methodName;
345                 preReplaceChild(oldChild, name, NAME_PROPERTY);
346                 this.methodName = name;
347                 postReplaceChild(oldChild, name, NAME_PROPERTY);
348         }
349
350         /**
351          * Returns the live ordered list of argument expressions in this
352          * "super" method invocation expression.
353          *
354          * @return the live list of argument expressions
355          *    (element type: <code>Expression</code>)
356          */
357         public List arguments() {
358                 return this.arguments;
359         }
360
361         /**
362          * Resolves and returns the binding for the method invoked by this
363          * expression.
364          * <p>
365          * Note that bindings are generally unavailable unless requested when the
366          * AST is being built.
367          * </p>
368          *
369          * @return the method binding, or <code>null</code> if the binding cannot
370          * be resolved
371          * @since 2.1
372          */
373         public IMethodBinding resolveMethodBinding() {
374                 return this.ast.getBindingResolver().resolveMethod(this);
375         }
376
377         /* (omit javadoc for this method)
378          * Method declared on ASTNode.
379          */
380         int memSize() {
381                 // treat Code as free
382                 return BASE_NODE_SIZE + 4 * 4;
383         }
384
385         /* (omit javadoc for this method)
386          * Method declared on ASTNode.
387          */
388         int treeSize() {
389                 return
390                         memSize()
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());
395         }
396 }
397