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 * Alternate constructor invocation statement AST node type.
21 * ConstructorInvocation:
22 * <b>this</b> <b>(</b> [ Expression { <b>,</b> Expression } ] <b>)</b> <b>;</b>
24 * For JLS3, type arguments are added:
26 * ConstructorInvocation:
27 * [ <b><</b> Type { <b>,</b> Type } <b>></b> ]
28 * <b>this</b> <b>(</b> [ Expression { <b>,</b> Expression } ] <b>)</b> <b>;</b>
32 * @noinstantiate This class is not intended to be instantiated by clients.
34 public class ConstructorInvocation extends Statement {
37 * The "typeArguments" structural property of this node type (added in JLS3 API).
40 public static final ChildListPropertyDescriptor TYPE_ARGUMENTS_PROPERTY =
41 new ChildListPropertyDescriptor(ConstructorInvocation.class, "typeArguments", Type.class, NO_CYCLE_RISK); //$NON-NLS-1$
44 * The "arguments" structural property of this node type.
47 public static final ChildListPropertyDescriptor ARGUMENTS_PROPERTY =
48 new ChildListPropertyDescriptor(ConstructorInvocation.class, "arguments", Expression.class, CYCLE_RISK); //$NON-NLS-1$
51 * A list of property descriptors (element type:
52 * {@link StructuralPropertyDescriptor}),
53 * or null if uninitialized.
56 private static final List PROPERTY_DESCRIPTORS_2_0;
59 * A list of property descriptors (element type:
60 * {@link StructuralPropertyDescriptor}),
61 * or null if uninitialized.
64 private static final List PROPERTY_DESCRIPTORS_3_0;
67 List properyList = new ArrayList(2);
68 createPropertyList(ConstructorInvocation.class, properyList);
69 addProperty(ARGUMENTS_PROPERTY, properyList);
70 PROPERTY_DESCRIPTORS_2_0 = reapPropertyList(properyList);
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);
80 * Returns a list of structural property descriptors for this node type.
81 * Clients must not modify the result.
83 * @param apiLevel the API level; one of the
84 * <code>AST.JLS*</code> constants
86 * @return a list of property descriptors (element type:
87 * {@link StructuralPropertyDescriptor})
90 public static List propertyDescriptors(int apiLevel) {
91 if (apiLevel == AST.JLS2_INTERNAL) {
92 return PROPERTY_DESCRIPTORS_2_0;
94 return PROPERTY_DESCRIPTORS_3_0;
99 * The type arguments (element type: <code>Type</code>).
100 * Null in JLS2. Added in JLS3; defaults to an empty list
104 private ASTNode.NodeList typeArguments = null;
107 * The list of argument expressions (element type:
108 * <code>Expression</code>). Defaults to an empty list.
110 private ASTNode.NodeList arguments =
111 new ASTNode.NodeList(ARGUMENTS_PROPERTY);
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.
117 * @param ast the AST that is to own this node
119 ConstructorInvocation(AST ast) {
121 if (ast.apiLevel >= AST.JLS3) {
122 this.typeArguments = new ASTNode.NodeList(TYPE_ARGUMENTS_PROPERTY);
126 /* (omit javadoc for this method)
127 * Method declared on ASTNode.
129 final List internalStructuralPropertiesForType(int apiLevel) {
130 return propertyDescriptors(apiLevel);
133 /* (omit javadoc for this method)
134 * Method declared on ASTNode.
136 final List internalGetChildListProperty(ChildListPropertyDescriptor property) {
137 if (property == ARGUMENTS_PROPERTY) {
140 if (property == TYPE_ARGUMENTS_PROPERTY) {
141 return typeArguments();
143 // allow default implementation to flag the error
144 return super.internalGetChildListProperty(property);
147 /* (omit javadoc for this method)
148 * Method declared on ASTNode.
150 final int getNodeType0() {
151 return CONSTRUCTOR_INVOCATION;
154 /* (omit javadoc for this method)
155 * Method declared on ASTNode.
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()));
164 result.arguments().addAll(ASTNode.copySubtrees(target, arguments()));
168 /* (omit javadoc for this method)
169 * Method declared on ASTNode.
171 final boolean subtreeMatch0(ASTMatcher matcher, Object other) {
172 // dispatch to correct overloaded match method
173 return matcher.match(this, other);
176 /* (omit javadoc for this method)
177 * Method declared on ASTNode.
179 void accept0(ASTVisitor visitor) {
180 boolean visitChildren = visitor.visit(this);
182 if (this.ast.apiLevel >= AST.JLS3) {
183 acceptChildren(visitor, this.typeArguments);
185 acceptChildren(visitor, this.arguments);
187 visitor.endVisit(this);
191 * Returns the live ordered list of type arguments of this constructor
192 * invocation (added in JLS3 API).
194 * @return the live list of type arguments
195 * (element type: <code>Type</code>)
196 * @exception UnsupportedOperationException if this operation is used in
200 public List typeArguments() {
201 // more efficient than just calling unsupportedIn2() to check
202 if (this.typeArguments == null) {
205 return this.typeArguments;
209 * Returns the live ordered list of argument expressions in this alternate
210 * constructor invocation statement.
212 * @return the live list of argument expressions
213 * (element type: <code>Expression</code>)
215 public List arguments() {
216 return this.arguments;
220 * Resolves and returns the binding for the constructor invoked by this
223 * Note that bindings are generally unavailable unless requested when the
224 * AST is being built.
227 * @return the constructor binding, or <code>null</code> if the binding
230 public IMethodBinding resolveConstructorBinding() {
231 return this.ast.getBindingResolver().resolveConstructor(this);
234 /* (omit javadoc for this method)
235 * Method declared on ASTNode.
238 // treat Code as free
239 return BASE_NODE_SIZE + 2 * 4;
242 /* (omit javadoc for this method)
243 * Method declared on ASTNode.
248 + (this.typeArguments == null ? 0 : this.typeArguments.listSize())
249 + (this.arguments == null ? 0 : this.arguments.listSize());