KickJava   Java API By Example, From Geeks To Geeks.

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


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  * 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  */

33 public class ConstructorInvocation extends Statement {
34     
35     /**
36      * The "typeArguments" structural property of this node type (added in JLS3 API).
37      * @since 3.1
38      */

39     public static final ChildListPropertyDescriptor TYPE_ARGUMENTS_PROPERTY =
40         new ChildListPropertyDescriptor(ConstructorInvocation.class, "typeArguments", Type.class, NO_CYCLE_RISK); //$NON-NLS-1$
41

42     /**
43      * The "arguments" structural property of this node type.
44      * @since 3.0
45      */

46     public static final ChildListPropertyDescriptor ARGUMENTS_PROPERTY =
47         new ChildListPropertyDescriptor(ConstructorInvocation.class, "arguments", Expression.class, CYCLE_RISK); //$NON-NLS-1$
48

49     /**
50      * A list of property descriptors (element type:
51      * {@link StructuralPropertyDescriptor}),
52      * or null if uninitialized.
53      * @since 3.0
54      */

55     private static final List JavaDoc PROPERTY_DESCRIPTORS_2_0;
56     
57     /**
58      * A list of property descriptors (element type:
59      * {@link StructuralPropertyDescriptor}),
60      * or null if uninitialized.
61      * @since 3.1
62      */

63     private static final List JavaDoc PROPERTY_DESCRIPTORS_3_0;
64     
65     static {
66         List JavaDoc properyList = new ArrayList JavaDoc(2);
67         createPropertyList(ConstructorInvocation.class, properyList);
68         addProperty(ARGUMENTS_PROPERTY, properyList);
69         PROPERTY_DESCRIPTORS_2_0 = reapPropertyList(properyList);
70         
71         properyList = new ArrayList JavaDoc(3);
72         createPropertyList(ConstructorInvocation.class, properyList);
73         addProperty(TYPE_ARGUMENTS_PROPERTY, properyList);
74         addProperty(ARGUMENTS_PROPERTY, properyList);
75         PROPERTY_DESCRIPTORS_3_0 = reapPropertyList(properyList);
76     }
77
78     /**
79      * Returns a list of structural property descriptors for this node type.
80      * Clients must not modify the result.
81      *
82      * @param apiLevel the API level; one of the
83      * <code>AST.JLS*</code> constants
84
85      * @return a list of property descriptors (element type:
86      * {@link StructuralPropertyDescriptor})
87      * @since 3.0
88      */

89     public static List JavaDoc propertyDescriptors(int apiLevel) {
90         if (apiLevel == AST.JLS2_INTERNAL) {
91             return PROPERTY_DESCRIPTORS_2_0;
92         } else {
93             return PROPERTY_DESCRIPTORS_3_0;
94         }
95     }
96             
97     /**
98      * The type arguments (element type: <code>Type</code>).
99      * Null in JLS2. Added in JLS3; defaults to an empty list
100      * (see constructor).
101      * @since 3.1
102      */

103     private ASTNode.NodeList typeArguments = null;
104
105     /**
106      * The list of argument expressions (element type:
107      * <code>Expression</code>). Defaults to an empty list.
108      */

109     private ASTNode.NodeList arguments =
110         new ASTNode.NodeList(ARGUMENTS_PROPERTY);
111
112     /**
113      * Creates a new AST node for an alternate constructor invocation statement
114      * owned by the given AST. By default, an empty list of arguments.
115      *
116      * @param ast the AST that is to own this node
117      */

118     ConstructorInvocation(AST ast) {
119         super(ast);
120         if (ast.apiLevel >= AST.JLS3) {
121             this.typeArguments = new ASTNode.NodeList(TYPE_ARGUMENTS_PROPERTY);
122         }
123     }
124
125     /* (omit javadoc for this method)
126      * Method declared on ASTNode.
127      */

128     final List JavaDoc internalStructuralPropertiesForType(int apiLevel) {
129         return propertyDescriptors(apiLevel);
130     }
131     
132     /* (omit javadoc for this method)
133      * Method declared on ASTNode.
134      */

135     final List JavaDoc internalGetChildListProperty(ChildListPropertyDescriptor property) {
136         if (property == ARGUMENTS_PROPERTY) {
137             return arguments();
138         }
139         if (property == TYPE_ARGUMENTS_PROPERTY) {
140             return typeArguments();
141         }
142         // allow default implementation to flag the error
143
return super.internalGetChildListProperty(property);
144     }
145
146     /* (omit javadoc for this method)
147      * Method declared on ASTNode.
148      */

149     final int getNodeType0() {
150         return CONSTRUCTOR_INVOCATION;
151     }
152
153     /* (omit javadoc for this method)
154      * Method declared on ASTNode.
155      */

156     ASTNode clone0(AST target) {
157         ConstructorInvocation result = new ConstructorInvocation(target);
158         result.setSourceRange(this.getStartPosition(), this.getLength());
159         result.copyLeadingComment(this);
160         if (this.ast.apiLevel >= AST.JLS3) {
161             result.typeArguments().addAll(ASTNode.copySubtrees(target, typeArguments()));
162         }
163         result.arguments().addAll(ASTNode.copySubtrees(target, arguments()));
164         return result;
165     }
166
167     /* (omit javadoc for this method)
168      * Method declared on ASTNode.
169      */

170     final boolean subtreeMatch0(ASTMatcher matcher, Object JavaDoc other) {
171         // dispatch to correct overloaded match method
172
return matcher.match(this, other);
173     }
174
175     /* (omit javadoc for this method)
176      * Method declared on ASTNode.
177      */

178     void accept0(ASTVisitor visitor) {
179         boolean visitChildren = visitor.visit(this);
180         if (visitChildren) {
181             if (this.ast.apiLevel >= AST.JLS3) {
182                 acceptChildren(visitor, this.typeArguments);
183             }
184             acceptChildren(visitor, this.arguments);
185         }
186         visitor.endVisit(this);
187     }
188     
189     /**
190      * Returns the live ordered list of type arguments of this constructor
191      * invocation (added in JLS3 API).
192      *
193      * @return the live list of type arguments
194      * (element type: <code>Type</code>)
195      * @exception UnsupportedOperationException if this operation is used in
196      * a JLS2 AST
197      * @since 3.1
198      */

199     public List JavaDoc typeArguments() {
200         // more efficient than just calling unsupportedIn2() to check
201
if (this.typeArguments == null) {
202             unsupportedIn2();
203         }
204         return this.typeArguments;
205     }
206     
207     /**
208      * Returns the live ordered list of argument expressions in this alternate
209      * constructor invocation statement.
210      *
211      * @return the live list of argument expressions
212      * (element type: <code>Expression</code>)
213      */

214     public List JavaDoc arguments() {
215         return this.arguments;
216     }
217
218     /**
219      * Resolves and returns the binding for the constructor invoked by this
220      * expression.
221      * <p>
222      * Note that bindings are generally unavailable unless requested when the
223      * AST is being built.
224      * </p>
225      *
226      * @return the constructor binding, or <code>null</code> if the binding
227      * cannot be resolved
228      */

229     public IMethodBinding resolveConstructorBinding() {
230         return this.ast.getBindingResolver().resolveConstructor(this);
231     }
232
233     /* (omit javadoc for this method)
234      * Method declared on ASTNode.
235      */

236     int memSize() {
237         // treat Code as free
238
return BASE_NODE_SIZE + 2 * 4;
239     }
240     
241     /* (omit javadoc for this method)
242      * Method declared on ASTNode.
243      */

244     int treeSize() {
245         return
246             memSize()
247             + (this.typeArguments == null ? 0 : this.typeArguments.listSize())
248             + (this.arguments == null ? 0 : this.arguments.listSize());
249     }
250 }
251
252
Popular Tags