KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > core > dom > SuperConstructorInvocation


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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 org.eclipse.jdt.core.dom;
13
14 import java.util.ArrayList JavaDoc;
15 import java.util.List JavaDoc;
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  */

34 public class SuperConstructorInvocation extends Statement {
35     
36     /**
37      * The "expression" structural property of this node type.
38      * @since 3.0
39      */

40     public static final ChildPropertyDescriptor EXPRESSION_PROPERTY =
41         new ChildPropertyDescriptor(SuperConstructorInvocation.class, "expression", Expression.class, OPTIONAL, CYCLE_RISK); //$NON-NLS-1$
42

43     /**
44      * The "typeArguments" structural property of this node type (added in JLS3 API).
45      * @since 3.1
46      */

47     public static final ChildListPropertyDescriptor TYPE_ARGUMENTS_PROPERTY =
48         new ChildListPropertyDescriptor(SuperConstructorInvocation.class, "typeArguments", Type.class, NO_CYCLE_RISK); //$NON-NLS-1$
49

50     /**
51      * The "arguments" structural property of this node type.
52      * @since 3.0
53      */

54     public static final ChildListPropertyDescriptor ARGUMENTS_PROPERTY =
55         new ChildListPropertyDescriptor(SuperConstructorInvocation.class, "arguments", Expression.class, CYCLE_RISK); //$NON-NLS-1$
56

57     /**
58      * A list of property descriptors (element type:
59      * {@link StructuralPropertyDescriptor}),
60      * or null if uninitialized.
61      * @since 3.0
62      */

63     private static final List JavaDoc PROPERTY_DESCRIPTORS_2_0;
64     
65     /**
66      * A list of property descriptors (element type:
67      * {@link StructuralPropertyDescriptor}),
68      * or null if uninitialized.
69      * @since 3.1
70      */

71     private static final List JavaDoc PROPERTY_DESCRIPTORS_3_0;
72     
73     static {
74         List JavaDoc propertyList = new ArrayList JavaDoc(3);
75         createPropertyList(SuperConstructorInvocation.class, propertyList);
76         addProperty(EXPRESSION_PROPERTY, propertyList);
77         addProperty(ARGUMENTS_PROPERTY, propertyList);
78         PROPERTY_DESCRIPTORS_2_0 = reapPropertyList(propertyList);
79         
80         propertyList = new ArrayList JavaDoc(4);
81         createPropertyList(SuperConstructorInvocation.class, propertyList);
82         addProperty(EXPRESSION_PROPERTY, propertyList);
83         addProperty(TYPE_ARGUMENTS_PROPERTY, propertyList);
84         addProperty(ARGUMENTS_PROPERTY, propertyList);
85         PROPERTY_DESCRIPTORS_3_0 = reapPropertyList(propertyList);
86     }
87
88     /**
89      * Returns a list of structural property descriptors for this node type.
90      * Clients must not modify the result.
91      *
92      * @param apiLevel the API level; one of the
93      * <code>AST.JLS*</code> constants
94
95      * @return a list of property descriptors (element type:
96      * {@link StructuralPropertyDescriptor})
97      * @since 3.0
98      */

99     public static List JavaDoc propertyDescriptors(int apiLevel) {
100         if (apiLevel == AST.JLS2_INTERNAL) {
101             return PROPERTY_DESCRIPTORS_2_0;
102         } else {
103             return PROPERTY_DESCRIPTORS_3_0;
104         }
105     }
106             
107     /**
108      * The expression; <code>null</code> for none; defaults to none.
109      */

110     private Expression optionalExpression = null;
111     
112     /**
113      * The type arguments (element type: <code>Type</code>).
114      * Null in JLS2. Added in JLS3; defaults to an empty list
115      * (see constructor).
116      * @since 3.1
117      */

118     private ASTNode.NodeList typeArguments = null;
119
120     /**
121      * The list of argument expressions (element type:
122      * <code>Expression</code>). Defaults to an empty list.
123      */

124     private ASTNode.NodeList arguments =
125         new ASTNode.NodeList(ARGUMENTS_PROPERTY);
126
127     /**
128      * Creates a new AST node for an super constructor invocation statement
129      * owned by the given AST. By default, no type arguments, and an empty list
130      * of arguments.
131      *
132      * @param ast the AST that is to own this node
133      */

134     SuperConstructorInvocation(AST ast) {
135         super(ast);
136         if (ast.apiLevel >= AST.JLS3) {
137             this.typeArguments = new ASTNode.NodeList(TYPE_ARGUMENTS_PROPERTY);
138         }
139     }
140
141     /* (omit javadoc for this method)
142      * Method declared on ASTNode.
143      */

144     final List JavaDoc internalStructuralPropertiesForType(int apiLevel) {
145         return propertyDescriptors(apiLevel);
146     }
147     
148     /* (omit javadoc for this method)
149      * Method declared on ASTNode.
150      */

151     final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) {
152         if (property == EXPRESSION_PROPERTY) {
153             if (get) {
154                 return getExpression();
155             } else {
156                 setExpression((Expression) child);
157                 return null;
158             }
159         }
160         // allow default implementation to flag the error
161
return super.internalGetSetChildProperty(property, get, child);
162     }
163     
164     /* (omit javadoc for this method)
165      * Method declared on ASTNode.
166      */

167     final List JavaDoc internalGetChildListProperty(ChildListPropertyDescriptor property) {
168         if (property == ARGUMENTS_PROPERTY) {
169             return arguments();
170         }
171         if (property == TYPE_ARGUMENTS_PROPERTY) {
172             return typeArguments();
173         }
174         // allow default implementation to flag the error
175
return super.internalGetChildListProperty(property);
176     }
177
178     /* (omit javadoc for this method)
179      * Method declared on ASTNode.
180      */

181     final int getNodeType0() {
182         return SUPER_CONSTRUCTOR_INVOCATION;
183     }
184
185     /* (omit javadoc for this method)
186      * Method declared on ASTNode.
187      */

188     ASTNode clone0(AST target) {
189         SuperConstructorInvocation result = new SuperConstructorInvocation(target);
190         result.setSourceRange(this.getStartPosition(), this.getLength());
191         result.copyLeadingComment(this);
192         result.setExpression(
193             (Expression) ASTNode.copySubtree(target, getExpression()));
194         if (this.ast.apiLevel >= AST.JLS3) {
195             result.typeArguments().addAll(ASTNode.copySubtrees(target, typeArguments()));
196         }
197         result.arguments().addAll(ASTNode.copySubtrees(target, arguments()));
198         return result;
199     }
200
201     /* (omit javadoc for this method)
202      * Method declared on ASTNode.
203      */

204     final boolean subtreeMatch0(ASTMatcher matcher, Object JavaDoc other) {
205         // dispatch to correct overloaded match method
206
return matcher.match(this, other);
207     }
208
209     /* (omit javadoc for this method)
210      * Method declared on ASTNode.
211      */

212     void accept0(ASTVisitor visitor) {
213         boolean visitChildren = visitor.visit(this);
214         if (visitChildren) {
215             // visit children in normal left to right reading order
216
acceptChild(visitor, getExpression());
217             if (this.ast.apiLevel >= AST.JLS3) {
218                 acceptChildren(visitor, this.typeArguments);
219             }
220             acceptChildren(visitor, this.arguments);
221         }
222         visitor.endVisit(this);
223     }
224     
225     /**
226      * Returns the expression of this super constructor invocation statement,
227      * or <code>null</code> if there is none.
228      *
229      * @return the expression node, or <code>null</code> if there is none
230      */

231     public Expression getExpression() {
232         return this.optionalExpression;
233     }
234     
235     /**
236      * Sets or clears the expression of this super constructor invocation
237      * statement.
238      *
239      * @param expression the expression node, or <code>null</code> if
240      * there is none
241      * @exception IllegalArgumentException if:
242      * <ul>
243      * <li>the node belongs to a different AST</li>
244      * <li>the node already has a parent</li>
245      * <li>a cycle in would be created</li>
246      * </ul>
247      */

248     public void setExpression(Expression expression) {
249         ASTNode oldChild = this.optionalExpression;
250         preReplaceChild(oldChild, expression, EXPRESSION_PROPERTY);
251         this.optionalExpression = expression;
252         postReplaceChild(oldChild, expression, EXPRESSION_PROPERTY);
253     }
254
255     /**
256      * Returns the live ordered list of type arguments of this constructor
257      * invocation (added in JLS3 API).
258      *
259      * @return the live list of type arguments
260      * (element type: <code>Type</code>)
261      * @exception UnsupportedOperationException if this operation is used in
262      * a JLS2 AST
263      * @since 3.1
264      */

265     public List JavaDoc typeArguments() {
266         // more efficient than just calling unsupportedIn2() to check
267
if (this.typeArguments == null) {
268             unsupportedIn2();
269         }
270         return this.typeArguments;
271     }
272     
273     /**
274      * Returns the live ordered list of argument expressions in this super
275      * constructor invocation statement.
276      *
277      * @return the live list of argument expressions
278      * (element type: <code>Expression</code>)
279      */

280     public List JavaDoc arguments() {
281         return this.arguments;
282     }
283
284     /**
285      * Resolves and returns the binding for the constructor invoked by this
286      * expression.
287      * <p>
288      * Note that bindings are generally unavailable unless requested when the
289      * AST is being built.
290      * </p>
291      *
292      * @return the constructor binding, or <code>null</code> if the binding
293      * cannot be resolved
294      */

295     public IMethodBinding resolveConstructorBinding() {
296         return this.ast.getBindingResolver().resolveConstructor(this);
297     }
298
299     /* (omit javadoc for this method)
300      * Method declared on ASTNode.
301      */

302     int memSize() {
303         // treat Code as free
304
return BASE_NODE_SIZE + 3 * 4;
305     }
306     
307     /* (omit javadoc for this method)
308      * Method declared on ASTNode.
309      */

310     int treeSize() {
311         return memSize()
312         + (this.optionalExpression == null ? 0 : getExpression().treeSize())
313         + (this.typeArguments == null ? 0 : this.typeArguments.listSize())
314         + (this.arguments == null ? 0 : this.arguments.listSize());
315     }
316 }
317
Popular Tags