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 * Super constructor invocation statement AST node type.
20 * SuperConstructorInvocation:
21 * [ Expression <b>.</b> ] <b>super</b>
22 * <b>(</b> [ Expression { <b>,</b> Expression } ] <b>)</b> <b>;</b>
24 * For JLS3, type arguments are added:
26 * SuperConstructorInvocation:
27 * [ Expression <b>.</b> ]
28 * [ <b><</b> Type { <b>,</b> Type } <b>></b> ]
29 * <b>super</b> <b>(</b> [ Expression { <b>,</b> Expression } ] <b>)</b> <b>;</b>
33 * @noinstantiate This class is not intended to be instantiated by clients.
35 public class SuperConstructorInvocation extends Statement {
38 * The "expression" structural property of this node type.
41 public static final ChildPropertyDescriptor EXPRESSION_PROPERTY =
42 new ChildPropertyDescriptor(SuperConstructorInvocation.class, "expression", Expression.class, OPTIONAL, CYCLE_RISK); //$NON-NLS-1$
45 * The "typeArguments" structural property of this node type (added in JLS3 API).
48 public static final ChildListPropertyDescriptor TYPE_ARGUMENTS_PROPERTY =
49 new ChildListPropertyDescriptor(SuperConstructorInvocation.class, "typeArguments", Type.class, NO_CYCLE_RISK); //$NON-NLS-1$
52 * The "arguments" structural property of this node type.
55 public static final ChildListPropertyDescriptor ARGUMENTS_PROPERTY =
56 new ChildListPropertyDescriptor(SuperConstructorInvocation.class, "arguments", Expression.class, CYCLE_RISK); //$NON-NLS-1$
59 * A list of property descriptors (element type:
60 * {@link StructuralPropertyDescriptor}),
61 * or null if uninitialized.
64 private static final List PROPERTY_DESCRIPTORS_2_0;
67 * A list of property descriptors (element type:
68 * {@link StructuralPropertyDescriptor}),
69 * or null if uninitialized.
72 private static final List PROPERTY_DESCRIPTORS_3_0;
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);
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);
90 * Returns a list of structural property descriptors for this node type.
91 * Clients must not modify the result.
93 * @param apiLevel the API level; one of the
94 * <code>AST.JLS*</code> constants
96 * @return a list of property descriptors (element type:
97 * {@link StructuralPropertyDescriptor})
100 public static List propertyDescriptors(int apiLevel) {
101 if (apiLevel == AST.JLS2_INTERNAL) {
102 return PROPERTY_DESCRIPTORS_2_0;
104 return PROPERTY_DESCRIPTORS_3_0;
109 * The expression; <code>null</code> for none; defaults to none.
111 private Expression optionalExpression = null;
114 * The type arguments (element type: <code>Type</code>).
115 * Null in JLS2. Added in JLS3; defaults to an empty list
119 private ASTNode.NodeList typeArguments = null;
122 * The list of argument expressions (element type:
123 * <code>Expression</code>). Defaults to an empty list.
125 private ASTNode.NodeList arguments =
126 new ASTNode.NodeList(ARGUMENTS_PROPERTY);
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
133 * @param ast the AST that is to own this node
135 SuperConstructorInvocation(AST ast) {
137 if (ast.apiLevel >= AST.JLS3) {
138 this.typeArguments = new ASTNode.NodeList(TYPE_ARGUMENTS_PROPERTY);
142 /* (omit javadoc for this method)
143 * Method declared on ASTNode.
145 final List internalStructuralPropertiesForType(int apiLevel) {
146 return propertyDescriptors(apiLevel);
149 /* (omit javadoc for this method)
150 * Method declared on ASTNode.
152 final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) {
153 if (property == EXPRESSION_PROPERTY) {
155 return getExpression();
157 setExpression((Expression) child);
161 // allow default implementation to flag the error
162 return super.internalGetSetChildProperty(property, get, child);
165 /* (omit javadoc for this method)
166 * Method declared on ASTNode.
168 final List internalGetChildListProperty(ChildListPropertyDescriptor property) {
169 if (property == ARGUMENTS_PROPERTY) {
172 if (property == TYPE_ARGUMENTS_PROPERTY) {
173 return typeArguments();
175 // allow default implementation to flag the error
176 return super.internalGetChildListProperty(property);
179 /* (omit javadoc for this method)
180 * Method declared on ASTNode.
182 final int getNodeType0() {
183 return SUPER_CONSTRUCTOR_INVOCATION;
186 /* (omit javadoc for this method)
187 * Method declared on ASTNode.
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()));
198 result.arguments().addAll(ASTNode.copySubtrees(target, arguments()));
202 /* (omit javadoc for this method)
203 * Method declared on ASTNode.
205 final boolean subtreeMatch0(ASTMatcher matcher, Object other) {
206 // dispatch to correct overloaded match method
207 return matcher.match(this, other);
210 /* (omit javadoc for this method)
211 * Method declared on ASTNode.
213 void accept0(ASTVisitor visitor) {
214 boolean visitChildren = visitor.visit(this);
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);
221 acceptChildren(visitor, this.arguments);
223 visitor.endVisit(this);
227 * Returns the expression of this super constructor invocation statement,
228 * or <code>null</code> if there is none.
230 * @return the expression node, or <code>null</code> if there is none
232 public Expression getExpression() {
233 return this.optionalExpression;
237 * Sets or clears the expression of this super constructor invocation
240 * @param expression the expression node, or <code>null</code> if
242 * @exception IllegalArgumentException if:
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>
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);
257 * Returns the live ordered list of type arguments of this constructor
258 * invocation (added in JLS3 API).
260 * @return the live list of type arguments
261 * (element type: <code>Type</code>)
262 * @exception UnsupportedOperationException if this operation is used in
266 public List typeArguments() {
267 // more efficient than just calling unsupportedIn2() to check
268 if (this.typeArguments == null) {
271 return this.typeArguments;
275 * Returns the live ordered list of argument expressions in this super
276 * constructor invocation statement.
278 * @return the live list of argument expressions
279 * (element type: <code>Expression</code>)
281 public List arguments() {
282 return this.arguments;
286 * Resolves and returns the binding for the constructor invoked by this
289 * Note that bindings are generally unavailable unless requested when the
290 * AST is being built.
293 * @return the constructor binding, or <code>null</code> if the binding
296 public IMethodBinding resolveConstructorBinding() {
297 return this.ast.getBindingResolver().resolveConstructor(this);
300 /* (omit javadoc for this method)
301 * Method declared on ASTNode.
304 // treat Code as free
305 return BASE_NODE_SIZE + 3 * 4;
308 /* (omit javadoc for this method)
309 * Method declared on ASTNode.
313 + (this.optionalExpression == null ? 0 : getExpression().treeSize())
314 + (this.typeArguments == null ? 0 : this.typeArguments.listSize())
315 + (this.arguments == null ? 0 : this.arguments.listSize());