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