EclipseJDT Source Viewer

Home|eclipse_jdt/src/org/eclipse/jdt/core/dom/ConstructorInvocation.java
1/*******************************************************************************
2 * Copyright (c) 2000, 2013 IBM Corporation and others.
3 *
4 * This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License 2.0
6 * which accompanies this distribution, and is available at
7 * https://www.eclipse.org/legal/epl-2.0/
8 *
9 * SPDX-License-Identifier: EPL-2.0
10 *
11 * Contributors:
12 *     IBM Corporation - initial API and implementation
13 *******************************************************************************/
14
15package org.eclipse.jdt.core.dom;
16
17import java.util.ArrayList;
18import java.util.List;
19
20/**
21 * Alternate constructor invocation statement AST node type.
22 * <pre>
23 * ConstructorInvocation:
24 *    [ <b>&lt;</b> Type { <b>,</b> Type } <b>&gt;</b> ]
25 *            <b>this</b> <b>(</b> [ Expression { <b>,</b> Expression } ] <b>)</b> <b>;</b>
26 * </pre>
27 *
28 * @since 2.0
29 * @noinstantiate This class is not intended to be instantiated by clients.
30 */
31@SuppressWarnings({"rawtypes""unchecked"})
32public class ConstructorInvocation extends Statement {
33
34    /**
35     * The "typeArguments" structural property of this node type (element type: {@link Type}) (added in JLS3 API).
36     * @since 3.1
37     */
38    public static final ChildListPropertyDescriptor TYPE_ARGUMENTS_PROPERTY =
39        new ChildListPropertyDescriptor(ConstructorInvocation.class"typeArguments"Type.classNO_CYCLE_RISK); //$NON-NLS-1$
40
41    /**
42     * The "arguments" structural property of this node type (element type: {@link Expression}).
43     * @since 3.0
44     */
45    public static final ChildListPropertyDescriptor ARGUMENTS_PROPERTY =
46        new ChildListPropertyDescriptor(ConstructorInvocation.class"arguments"Expression.classCYCLE_RISK); //$NON-NLS-1$
47
48    /**
49     * A list of property descriptors (element type:
50     * {@link StructuralPropertyDescriptor}),
51     * or null if uninitialized.
52     * @since 3.0
53     */
54    private static final List PROPERTY_DESCRIPTORS_2_0;
55
56    /**
57     * A list of property descriptors (element type:
58     * {@link StructuralPropertyDescriptor}),
59     * or null if uninitialized.
60     * @since 3.1
61     */
62    private static final List PROPERTY_DESCRIPTORS_3_0;
63
64    static {
65        List properyList = new ArrayList(2);
66        createPropertyList(ConstructorInvocation.classproperyList);
67        addProperty(ARGUMENTS_PROPERTYproperyList);
68        PROPERTY_DESCRIPTORS_2_0 = reapPropertyList(properyList);
69
70        properyList = new ArrayList(3);
71        createPropertyList(ConstructorInvocation.classproperyList);
72        addProperty(TYPE_ARGUMENTS_PROPERTYproperyList);
73        addProperty(ARGUMENTS_PROPERTYproperyList);
74        PROPERTY_DESCRIPTORS_3_0 = reapPropertyList(properyList);
75    }
76
77    /**
78     * Returns a list of structural property descriptors for this node type.
79     * Clients must not modify the result.
80     *
81     * @param apiLevel the API level; one of the
82     * <code>AST.JLS*</code> constants
83
84     * @return a list of property descriptors (element type:
85     * {@link StructuralPropertyDescriptor})
86     * @since 3.0
87     */
88    public static List propertyDescriptors(int apiLevel) {
89        if (apiLevel == AST.JLS2_INTERNAL) {
90            return PROPERTY_DESCRIPTORS_2_0;
91        } else {
92            return PROPERTY_DESCRIPTORS_3_0;
93        }
94    }
95
96    /**
97     * The type arguments (element type: {@link Type}).
98     * Null in JLS2. Added in JLS3; defaults to an empty list
99     * (see constructor).
100     * @since 3.1
101     */
102    private ASTNode.NodeList typeArguments = null;
103
104    /**
105     * The list of argument expressions (element type:
106     * {@link Expression}). Defaults to an empty list.
107     */
108    private ASTNode.NodeList arguments =
109        new ASTNode.NodeList(ARGUMENTS_PROPERTY);
110
111    /**
112     * Creates a new AST node for an alternate constructor invocation statement
113     * owned by the given AST. By default, an empty list of arguments.
114     *
115     * @param ast the AST that is to own this node
116     */
117    ConstructorInvocation(AST ast) {
118        super(ast);
119        if (ast.apiLevel >= AST.JLS3_INTERNAL) {
120            this.typeArguments = new ASTNode.NodeList(TYPE_ARGUMENTS_PROPERTY);
121        }
122    }
123
124    @Override
125    final List internalStructuralPropertiesForType(int apiLevel) {
126        return propertyDescriptors(apiLevel);
127    }
128
129    @Override
130    final List internalGetChildListProperty(ChildListPropertyDescriptor property) {
131        if (property == ARGUMENTS_PROPERTY) {
132            return arguments();
133        }
134        if (property == TYPE_ARGUMENTS_PROPERTY) {
135            return typeArguments();
136        }
137        // allow default implementation to flag the error
138        return super.internalGetChildListProperty(property);
139    }
140
141    @Override
142    final int getNodeType0() {
143        return CONSTRUCTOR_INVOCATION;
144    }
145
146    @Override
147    ASTNode clone0(AST target) {
148        ConstructorInvocation result = new ConstructorInvocation(target);
149        result.setSourceRange(getStartPosition(), getLength());
150        result.copyLeadingComment(this);
151        if (this.ast.apiLevel >= AST.JLS3_INTERNAL) {
152            result.typeArguments().addAll(ASTNode.copySubtrees(targettypeArguments()));
153        }
154        result.arguments().addAll(ASTNode.copySubtrees(targetarguments()));
155        return result;
156    }
157
158    @Override
159    final boolean subtreeMatch0(ASTMatcher matcherObject other) {
160        // dispatch to correct overloaded match method
161        return matcher.match(this, other);
162    }
163
164    @Override
165    void accept0(ASTVisitor visitor) {
166        boolean visitChildren = visitor.visit(this);
167        if (visitChildren) {
168            if (this.ast.apiLevel >= AST.JLS3_INTERNAL) {
169                acceptChildren(visitor, this.typeArguments);
170            }
171            acceptChildren(visitor, this.arguments);
172        }
173        visitor.endVisit(this);
174    }
175
176    /**
177     * Returns the live ordered list of type arguments of this constructor
178     * invocation (added in JLS3 API).
179     *
180     * @return the live list of type arguments
181     *    (element type: {@link Type})
182     * @exception UnsupportedOperationException if this operation is used in
183     * a JLS2 AST
184     * @since 3.1
185     */
186    public List typeArguments() {
187        // more efficient than just calling unsupportedIn2() to check
188        if (this.typeArguments == null) {
189            unsupportedIn2();
190        }
191        return this.typeArguments;
192    }
193
194    /**
195     * Returns the live ordered list of argument expressions in this alternate
196     * constructor invocation statement.
197     *
198     * @return the live list of argument expressions
199     *    (element type: {@link Expression})
200     */
201    public List arguments() {
202        return this.arguments;
203    }
204
205    /**
206     * Resolves and returns the binding for the constructor invoked by this
207     * expression.
208     * <p>
209     * Note that bindings are generally unavailable unless requested when the
210     * AST is being built.
211     * </p>
212     *
213     * @return the constructor binding, or <code>null</code> if the binding
214     *    cannot be resolved
215     */
216    public IMethodBinding resolveConstructorBinding() {
217        return this.ast.getBindingResolver().resolveConstructor(this);
218    }
219
220    @Override
221    int memSize() {
222        // treat Code as free
223        return BASE_NODE_SIZE + 2 * 4;
224    }
225
226    @Override
227    int treeSize() {
228        return
229            memSize()
230            + (this.typeArguments == null ? 0 : this.typeArguments.listSize())
231            + (this.arguments == null ? 0 : this.arguments.listSize());
232    }
233}
234
235
MembersX
ConstructorInvocation:ARGUMENTS_PROPERTY
ConstructorInvocation:accept0
ConstructorInvocation:typeArguments
ConstructorInvocation:internalGetChildListProperty
ConstructorInvocation:memSize
ConstructorInvocation:clone0:Block:result
ConstructorInvocation:ConstructorInvocation
ConstructorInvocation:getNodeType0
ConstructorInvocation:arguments
ConstructorInvocation:subtreeMatch0
ConstructorInvocation:resolveConstructorBinding
ConstructorInvocation:treeSize
ConstructorInvocation:internalStructuralPropertiesForType
ConstructorInvocation:PROPERTY_DESCRIPTORS_2_0
ConstructorInvocation:PROPERTY_DESCRIPTORS_3_0
ConstructorInvocation:propertyDescriptors
ConstructorInvocation:accept0:Block:visitChildren
ConstructorInvocation:clone0
ConstructorInvocation:TYPE_ARGUMENTS_PROPERTY
ConstructorInvocation:Block:properyList
Members
X