removed unused private methods.
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / core / dom / SuperConstructorInvocation.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  * Super constructor invocation statement AST node type.
19  * For JLS2: * <pre>
20  * SuperConstructorInvocation:
21  *     [ Expression <b>.</b> ] <b>super</b>
22  *         <b>(</b> [ Expression { <b>,</b> Expression } ] <b>)</b> <b>;</b>
23  * </pre>
24  * For JLS3, type arguments are added:
25  * <pre>
26  * SuperConstructorInvocation:
27  *     [ Expression <b>.</b> ]
28  *         [ <b>&lt;</b> Type { <b>,</b> Type } <b>&gt;</b> ]
29  *         <b>super</b> <b>(</b> [ Expression { <b>,</b> Expression } ] <b>)</b> <b>;</b>
30  * </pre>
31  * 
32  * @since 2.0
33  * @noinstantiate This class is not intended to be instantiated by clients.
34  */
35 public class SuperConstructorInvocation extends Statement {
36         
37         /**
38          * The "expression" structural property of this node type.
39          * @since 3.0
40          */
41         public static final ChildPropertyDescriptor EXPRESSION_PROPERTY = 
42                 new ChildPropertyDescriptor(SuperConstructorInvocation.class, "expression", Expression.class, OPTIONAL, CYCLE_RISK); //$NON-NLS-1$
43
44         /**
45          * The "typeArguments" structural property of this node type (added in JLS3 API).
46          * @since 3.1
47          */
48         public static final ChildListPropertyDescriptor TYPE_ARGUMENTS_PROPERTY = 
49                 new ChildListPropertyDescriptor(SuperConstructorInvocation.class, "typeArguments", Type.class, NO_CYCLE_RISK); //$NON-NLS-1$
50         
51         /**
52          * The "arguments" structural property of this node type.
53          * @since 3.0
54          */
55         public static final ChildListPropertyDescriptor ARGUMENTS_PROPERTY = 
56                 new ChildListPropertyDescriptor(SuperConstructorInvocation.class, "arguments", Expression.class, CYCLE_RISK); //$NON-NLS-1$
57         
58         /**
59          * A list of property descriptors (element type: 
60          * {@link StructuralPropertyDescriptor}),
61          * or null if uninitialized.
62          * @since 3.0
63          */
64         private static final List PROPERTY_DESCRIPTORS_2_0;
65         
66         /**
67          * A list of property descriptors (element type: 
68          * {@link StructuralPropertyDescriptor}),
69          * or null if uninitialized.
70          * @since 3.1
71          */
72         private static final List PROPERTY_DESCRIPTORS_3_0;
73         
74         static {
75                 List propertyList = new ArrayList(3);
76                 createPropertyList(SuperConstructorInvocation.class, propertyList);
77                 addProperty(EXPRESSION_PROPERTY, propertyList);
78                 addProperty(ARGUMENTS_PROPERTY, propertyList);
79                 PROPERTY_DESCRIPTORS_2_0 = reapPropertyList(propertyList);
80                 
81                 propertyList = new ArrayList(4);
82                 createPropertyList(SuperConstructorInvocation.class, propertyList);
83                 addProperty(EXPRESSION_PROPERTY, propertyList);
84                 addProperty(TYPE_ARGUMENTS_PROPERTY, propertyList);
85                 addProperty(ARGUMENTS_PROPERTY, propertyList);
86                 PROPERTY_DESCRIPTORS_3_0 = reapPropertyList(propertyList);
87         }
88
89         /**
90          * Returns a list of structural property descriptors for this node type.
91          * Clients must not modify the result.
92          * 
93          * @param apiLevel the API level; one of the
94          * <code>AST.JLS*</code> constants
95
96          * @return a list of property descriptors (element type: 
97          * {@link StructuralPropertyDescriptor})
98          * @since 3.0
99          */
100         public static List propertyDescriptors(int apiLevel) {
101                 if (apiLevel == AST.JLS2_INTERNAL) {
102                         return PROPERTY_DESCRIPTORS_2_0;
103                 } else {
104                         return PROPERTY_DESCRIPTORS_3_0;
105                 }
106         }
107                         
108         /**
109          * The expression; <code>null</code> for none; defaults to none.
110          */
111         private Expression optionalExpression = null;
112         
113         /**
114          * The type arguments (element type: <code>Type</code>). 
115          * Null in JLS2. Added in JLS3; defaults to an empty list
116          * (see constructor).
117          * @since 3.1
118          */
119         private ASTNode.NodeList typeArguments = null;
120
121         /**
122          * The list of argument expressions (element type: 
123          * <code>Expression</code>). Defaults to an empty list.
124          */
125         private ASTNode.NodeList arguments =
126                 new ASTNode.NodeList(ARGUMENTS_PROPERTY);
127
128         /**
129          * Creates a new AST node for an super constructor invocation statement
130          * owned by the given AST. By default, no type arguments, and an empty list
131          * of arguments.
132          * 
133          * @param ast the AST that is to own this node
134          */
135         SuperConstructorInvocation(AST ast) {
136                 super(ast);     
137                 if (ast.apiLevel >= AST.JLS3) {
138                         this.typeArguments = new ASTNode.NodeList(TYPE_ARGUMENTS_PROPERTY);
139                 }
140         }
141
142         /* (omit javadoc for this method)
143          * Method declared on ASTNode.
144          */
145         final List internalStructuralPropertiesForType(int apiLevel) {
146                 return propertyDescriptors(apiLevel);
147         }
148         
149         /* (omit javadoc for this method)
150          * Method declared on ASTNode.
151          */
152         final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) {
153                 if (property == EXPRESSION_PROPERTY) {
154                         if (get) {
155                                 return getExpression();
156                         } else {
157                                 setExpression((Expression) child);
158                                 return null;
159                         }
160                 }
161                 // allow default implementation to flag the error
162                 return super.internalGetSetChildProperty(property, get, child);
163         }
164         
165         /* (omit javadoc for this method)
166          * Method declared on ASTNode.
167          */
168         final List internalGetChildListProperty(ChildListPropertyDescriptor property) {
169                 if (property == ARGUMENTS_PROPERTY) {
170                         return arguments();
171                 }
172                 if (property == TYPE_ARGUMENTS_PROPERTY) {
173                         return typeArguments();
174                 }
175                 // allow default implementation to flag the error
176                 return super.internalGetChildListProperty(property);
177         }
178
179         /* (omit javadoc for this method)
180          * Method declared on ASTNode.
181          */
182         final int getNodeType0() {
183                 return SUPER_CONSTRUCTOR_INVOCATION;
184         }
185
186         /* (omit javadoc for this method)
187          * Method declared on ASTNode.
188          */
189         ASTNode clone0(AST target) {
190                 SuperConstructorInvocation result = new SuperConstructorInvocation(target);
191                 result.setSourceRange(this.getStartPosition(), this.getLength());
192                 result.copyLeadingComment(this);
193                 result.setExpression(
194                         (Expression) ASTNode.copySubtree(target, getExpression()));
195                 if (this.ast.apiLevel >= AST.JLS3) {
196                         result.typeArguments().addAll(ASTNode.copySubtrees(target, typeArguments()));
197                 }
198                 result.arguments().addAll(ASTNode.copySubtrees(target, arguments()));
199                 return result;
200         }
201
202         /* (omit javadoc for this method)
203          * Method declared on ASTNode.
204          */
205         final boolean subtreeMatch0(ASTMatcher matcher, Object other) {
206                 // dispatch to correct overloaded match method
207                 return matcher.match(this, other);
208         }
209
210         /* (omit javadoc for this method)
211          * Method declared on ASTNode.
212          */
213         void accept0(ASTVisitor visitor) {
214                 boolean visitChildren = visitor.visit(this);
215                 if (visitChildren) {
216                         // visit children in normal left to right reading order
217                         acceptChild(visitor, getExpression());
218                         if (this.ast.apiLevel >= AST.JLS3) {
219                                 acceptChildren(visitor, this.typeArguments);
220                         }
221                         acceptChildren(visitor, this.arguments);
222                 }
223                 visitor.endVisit(this);
224         }
225         
226         /**
227          * Returns the expression of this super constructor invocation statement,
228          * or <code>null</code> if there is none.
229          * 
230          * @return the expression node, or <code>null</code> if there is none
231          */ 
232         public Expression getExpression() {
233                 return this.optionalExpression;
234         }
235         
236         /**
237          * Sets or clears the expression of this super constructor invocation
238          * statement.
239          * 
240          * @param expression the expression node, or <code>null</code> if 
241          *    there is none
242          * @exception IllegalArgumentException if:
243          * <ul>
244          * <li>the node belongs to a different AST</li>
245          * <li>the node already has a parent</li>
246          * <li>a cycle in would be created</li>
247          * </ul>
248          */ 
249         public void setExpression(Expression expression) {
250                 ASTNode oldChild = this.optionalExpression;
251                 preReplaceChild(oldChild, expression, EXPRESSION_PROPERTY);
252                 this.optionalExpression = expression;
253                 postReplaceChild(oldChild, expression, EXPRESSION_PROPERTY);
254         }
255
256         /**
257          * Returns the live ordered list of type arguments of this constructor
258          * invocation (added in JLS3 API).
259          * 
260          * @return the live list of type arguments
261          *    (element type: <code>Type</code>)
262          * @exception UnsupportedOperationException if this operation is used in
263          * a JLS2 AST
264          * @since 3.1
265          */ 
266         public List typeArguments() {
267                 // more efficient than just calling unsupportedIn2() to check
268                 if (this.typeArguments == null) {
269                         unsupportedIn2();
270                 }
271                 return this.typeArguments;
272         }
273         
274         /**
275          * Returns the live ordered list of argument expressions in this super
276          * constructor invocation statement.
277          * 
278          * @return the live list of argument expressions 
279          *    (element type: <code>Expression</code>)
280          */ 
281         public List arguments() {
282                 return this.arguments;
283         }
284
285         /**
286          * Resolves and returns the binding for the constructor invoked by this
287          * expression.
288          * <p>
289          * Note that bindings are generally unavailable unless requested when the
290          * AST is being built.
291          * </p>
292          * 
293          * @return the constructor binding, or <code>null</code> if the binding
294          *    cannot be resolved
295          */     
296         public IMethodBinding resolveConstructorBinding() {
297                 return this.ast.getBindingResolver().resolveConstructor(this);
298         }
299
300         /* (omit javadoc for this method)
301          * Method declared on ASTNode.
302          */
303         int memSize() {
304                 // treat Code as free
305                 return BASE_NODE_SIZE + 3 * 4;
306         }
307         
308         /* (omit javadoc for this method)
309          * Method declared on ASTNode.
310          */
311         int treeSize() {
312                 return memSize()
313                 + (this.optionalExpression == null ? 0 : getExpression().treeSize())
314                 + (this.typeArguments == null ? 0 : this.typeArguments.listSize())
315                 + (this.arguments == null ? 0 : this.arguments.listSize());
316         }
317 }