KickJava   Java API By Example, From Geeks To Geeks.

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


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  * Simple or qualified "super" method invocation expression AST node type.
19  * For JLS2:
20  * <pre>
21  * SuperMethodInvocation:
22  * [ ClassName <b>.</b> ] <b>super</b> <b>.</b> Identifier
23  * <b>(</b> [ Expression { <b>,</b> Expression } ] <b>)</b>
24  * </pre>
25  * For JLS3, type arguments are added:
26  * <pre>
27  * SuperMethodInvocation:
28  * [ ClassName <b>.</b> ] <b>super</b> <b>.</b>
29  * [ <b>&lt;</b> Type { <b>,</b> Type } <b>&gt;</b> ]
30  * Identifier <b>(</b> [ Expression { <b>,</b> Expression } ] <b>)</b>
31  * </pre>
32  *
33  * @since 2.0
34  */

35 public class SuperMethodInvocation extends Expression {
36     
37     /**
38      * The "qualifier" structural property of this node type.
39      * @since 3.0
40      */

41     public static final ChildPropertyDescriptor QUALIFIER_PROPERTY =
42         new ChildPropertyDescriptor(SuperMethodInvocation.class, "qualifier", Name.class, OPTIONAL, NO_CYCLE_RISK); //$NON-NLS-1$
43

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

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

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

55     public static final ChildPropertyDescriptor NAME_PROPERTY =
56         new ChildPropertyDescriptor(SuperMethodInvocation.class, "name", SimpleName.class, MANDATORY, NO_CYCLE_RISK); //$NON-NLS-1$
57

58     /**
59      * The "arguments" structural property of this node type.
60      * @since 3.0
61      */

62     public static final ChildListPropertyDescriptor ARGUMENTS_PROPERTY =
63         new ChildListPropertyDescriptor(SuperMethodInvocation.class, "arguments", Expression.class, CYCLE_RISK); //$NON-NLS-1$
64

65     /**
66      * A list of property descriptors (element type:
67      * {@link StructuralPropertyDescriptor}),
68      * or null if uninitialized.
69      * @since 3.0
70      */

71     private static final List JavaDoc PROPERTY_DESCRIPTORS_2_0;
72     
73     /**
74      * A list of property descriptors (element type:
75      * {@link StructuralPropertyDescriptor}),
76      * or null if uninitialized.
77      * @since 3.1
78      */

79     private static final List JavaDoc PROPERTY_DESCRIPTORS_3_0;
80     
81     static {
82         List JavaDoc propertyList = new ArrayList JavaDoc(4);
83         createPropertyList(SuperMethodInvocation.class, propertyList);
84         addProperty(QUALIFIER_PROPERTY, propertyList);
85         addProperty(NAME_PROPERTY, propertyList);
86         addProperty(ARGUMENTS_PROPERTY, propertyList);
87         PROPERTY_DESCRIPTORS_2_0 = reapPropertyList(propertyList);
88         
89         propertyList = new ArrayList JavaDoc(5);
90         createPropertyList(SuperMethodInvocation.class, propertyList);
91         addProperty(QUALIFIER_PROPERTY, propertyList);
92         addProperty(TYPE_ARGUMENTS_PROPERTY, propertyList);
93         addProperty(NAME_PROPERTY, propertyList);
94         addProperty(ARGUMENTS_PROPERTY, propertyList);
95         PROPERTY_DESCRIPTORS_3_0 = reapPropertyList(propertyList);
96     }
97
98     /**
99      * Returns a list of structural property descriptors for this node type.
100      * Clients must not modify the result.
101      *
102      * @param apiLevel the API level; one of the
103      * <code>AST.JLS&ast;</code> constants
104
105      * @return a list of property descriptors (element type:
106      * {@link StructuralPropertyDescriptor})
107      * @since 3.0
108      */

109     public static List JavaDoc propertyDescriptors(int apiLevel) {
110         if (apiLevel == AST.JLS2_INTERNAL) {
111             return PROPERTY_DESCRIPTORS_2_0;
112         } else {
113             return PROPERTY_DESCRIPTORS_3_0;
114         }
115     }
116             
117     /**
118      * The optional qualifier; <code>null</code> for none; defaults to none.
119      */

120     private Name optionalQualifier = null;
121
122     /**
123      * The type arguments (element type: <code>Type</code>).
124      * Null in JLS2. Added in JLS3; defaults to an empty list
125      * (see constructor).
126      * @since 3.1
127      */

128     private ASTNode.NodeList typeArguments = null;
129
130     /**
131      * The method name; lazily initialized; defaults to a unspecified,
132      * legal Java method name.
133      */

134     private SimpleName methodName = null;
135     
136     /**
137      * The list of argument expressions (element type:
138      * <code>Expression</code>). Defaults to an empty list.
139      */

140     private ASTNode.NodeList arguments =
141         new ASTNode.NodeList(ARGUMENTS_PROPERTY);
142
143     /**
144      * Creates a new AST node for a "super" method invocation expression owned
145      * by the given AST. By default, no qualifier, no type arguments,
146      * an unspecified, but legal, method name, and an empty list of arguments.
147      *
148      * @param ast the AST that is to own this node
149      */

150     SuperMethodInvocation(AST ast) {
151         super(ast);
152         if (ast.apiLevel >= AST.JLS3) {
153             this.typeArguments = new ASTNode.NodeList(TYPE_ARGUMENTS_PROPERTY);
154         }
155     }
156
157     /* (omit javadoc for this method)
158      * Method declared on ASTNode.
159      */

160     final List JavaDoc internalStructuralPropertiesForType(int apiLevel) {
161         return propertyDescriptors(apiLevel);
162     }
163     
164     /* (omit javadoc for this method)
165      * Method declared on ASTNode.
166      */

167     final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) {
168         if (property == QUALIFIER_PROPERTY) {
169             if (get) {
170                 return getQualifier();
171             } else {
172                 setQualifier((Name) child);
173                 return null;
174             }
175         }
176         if (property == NAME_PROPERTY) {
177             if (get) {
178                 return getName();
179             } else {
180                 setName((SimpleName) child);
181                 return null;
182             }
183         }
184         // allow default implementation to flag the error
185
return super.internalGetSetChildProperty(property, get, child);
186     }
187     
188     /* (omit javadoc for this method)
189      * Method declared on ASTNode.
190      */

191     final List JavaDoc internalGetChildListProperty(ChildListPropertyDescriptor property) {
192         if (property == ARGUMENTS_PROPERTY) {
193             return arguments();
194         }
195         if (property == TYPE_ARGUMENTS_PROPERTY) {
196             return typeArguments();
197         }
198         // allow default implementation to flag the error
199
return super.internalGetChildListProperty(property);
200     }
201
202     /* (omit javadoc for this method)
203      * Method declared on ASTNode.
204      */

205     final int getNodeType0() {
206         return SUPER_METHOD_INVOCATION;
207     }
208
209     /* (omit javadoc for this method)
210      * Method declared on ASTNode.
211      */

212     ASTNode clone0(AST target) {
213         SuperMethodInvocation result = new SuperMethodInvocation(target);
214         result.setSourceRange(this.getStartPosition(), this.getLength());
215         result.setName((SimpleName) getName().clone(target));
216         result.setQualifier((Name) ASTNode.copySubtree(target, getQualifier()));
217         if (this.ast.apiLevel >= AST.JLS3) {
218             result.typeArguments().addAll(ASTNode.copySubtrees(target, typeArguments()));
219         }
220         result.arguments().addAll(ASTNode.copySubtrees(target, arguments()));
221         return result;
222     }
223
224     /* (omit javadoc for this method)
225      * Method declared on ASTNode.
226      */

227     final boolean subtreeMatch0(ASTMatcher matcher, Object JavaDoc other) {
228         // dispatch to correct overloaded match method
229
return matcher.match(this, other);
230     }
231
232     /* (omit javadoc for this method)
233      * Method declared on ASTNode.
234      */

235     void accept0(ASTVisitor visitor) {
236         boolean visitChildren = visitor.visit(this);
237         if (visitChildren) {
238             // visit children in normal left to right reading order
239
acceptChild(visitor, getQualifier());
240             if (this.ast.apiLevel >= AST.JLS3) {
241                 acceptChildren(visitor, this.typeArguments);
242             }
243             acceptChild(visitor, getName());
244             acceptChildren(visitor, this.arguments);
245         }
246         visitor.endVisit(this);
247     }
248     
249     /**
250      * Returns the qualifier of this "super" method invocation expression, or
251      * <code>null</code> if there is none.
252      *
253      * @return the qualifier name node, or <code>null</code> if there is none
254      */

255     public Name getQualifier() {
256         return this.optionalQualifier;
257     }
258     
259     /**
260      * Sets or clears the qualifier of this "super" method invocation expression.
261      *
262      * @param name the qualifier name node, or <code>null</code> if
263      * there is none
264      * @exception IllegalArgumentException if:
265      * <ul>
266      * <li>the node belongs to a different AST</li>
267      * <li>the node already has a parent</li>
268      * </ul>
269      */

270     public void setQualifier(Name name) {
271         ASTNode oldChild = this.optionalQualifier;
272         preReplaceChild(oldChild, name, QUALIFIER_PROPERTY);
273         this.optionalQualifier = name;
274         postReplaceChild(oldChild, name, QUALIFIER_PROPERTY);
275     }
276     
277     /**
278      * Returns the live ordered list of type arguments of this method
279      * invocation (added in JLS3 API).
280      *
281      * @return the live list of type arguments
282      * (element type: <code>Type</code>)
283      * @exception UnsupportedOperationException if this operation is used in
284      * a JLS2 AST
285      * @since 3.1
286      */

287     public List JavaDoc typeArguments() {
288         // more efficient than just calling unsupportedIn2() to check
289
if (this.typeArguments == null) {
290             unsupportedIn2();
291         }
292         return this.typeArguments;
293     }
294     
295     /**
296      * Returns the name of the method invoked in this expression.
297      *
298      * @return the method name node
299      */

300     public SimpleName getName() {
301         if (this.methodName == null) {
302             // lazy init must be thread-safe for readers
303
synchronized (this) {
304                 if (this.methodName == null) {
305                     preLazyInit();
306                     this.methodName = new SimpleName(this.ast);
307                     postLazyInit(this.methodName, NAME_PROPERTY);
308                 }
309             }
310         }
311         return this.methodName;
312     }
313     
314     /**
315      * Sets the name of the method invoked in this expression to the
316      * given name.
317      *
318      * @param name the new method name
319      * @exception IllegalArgumentException if:
320      * <ul>
321      * <li>the node belongs to a different AST</li>
322      * <li>the node already has a parent</li>
323      * </ul>
324      */

325     public void setName(SimpleName name) {
326         if (name == null) {
327             throw new IllegalArgumentException JavaDoc();
328         }
329         ASTNode oldChild = this.methodName;
330         preReplaceChild(oldChild, name, NAME_PROPERTY);
331         this.methodName = name;
332         postReplaceChild(oldChild, name, NAME_PROPERTY);
333     }
334
335     /**
336      * Returns the live ordered list of argument expressions in this
337      * "super" method invocation expression.
338      *
339      * @return the live list of argument expressions
340      * (element type: <code>Expression</code>)
341      */

342     public List JavaDoc arguments() {
343         return this.arguments;
344     }
345
346     /**
347      * Resolves and returns the binding for the method invoked by this
348      * expression.
349      * <p>
350      * Note that bindings are generally unavailable unless requested when the
351      * AST is being built.
352      * </p>
353      *
354      * @return the method binding, or <code>null</code> if the binding cannot
355      * be resolved
356      * @since 2.1
357      */

358     public IMethodBinding resolveMethodBinding() {
359         return this.ast.getBindingResolver().resolveMethod(this);
360     }
361
362     /* (omit javadoc for this method)
363      * Method declared on ASTNode.
364      */

365     int memSize() {
366         // treat Code as free
367
return BASE_NODE_SIZE + 4 * 4;
368     }
369     
370     /* (omit javadoc for this method)
371      * Method declared on ASTNode.
372      */

373     int treeSize() {
374         return
375             memSize()
376             + (this.optionalQualifier == null ? 0 : getQualifier().treeSize())
377             + (this.typeArguments == null ? 0 : this.typeArguments.listSize())
378             + (this.methodName == null ? 0 : getName().treeSize())
379             + (this.arguments == null ? 0 : this.arguments.listSize());
380     }
381 }
382
383
Popular Tags