EclipseJDT Source Viewer

Home|eclipse_jdt/src/org/eclipse/jdt/core/dom/CreationReference.java
1/*******************************************************************************
2 * Copyright (c) 2013, 2014 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 *******************************************************************************/
14package org.eclipse.jdt.core.dom;
15
16import java.util.ArrayList;
17import java.util.List;
18
19/**
20 * Creation reference expression AST node type (added in JLS8 API).
21 *
22 * <pre>
23 * CreationReference:
24 *     Type <b>::</b>
25 *         [ <b>&lt;</b> Type { <b>,</b> Type } <b>&gt;</b> ]
26 *         <b>new</b>
27 * </pre>
28 *
29 * @since 3.10
30 * @noinstantiate This class is not intended to be instantiated by clients.
31 */
32@SuppressWarnings({"rawtypes""unchecked"})
33public class CreationReference extends MethodReference {
34
35    /**
36     * The "type" structural property of this node type (child type: {@link Type}).
37     */
38    public static final ChildPropertyDescriptor TYPE_PROPERTY =
39        new ChildPropertyDescriptor(CreationReference.class"type"Type.classMANDATORYNO_CYCLE_RISK); //$NON-NLS-1$
40
41    /**
42     * The "typeArguments" structural property of this node type (element type: {@link Type}).
43     */
44    public static final ChildListPropertyDescriptor TYPE_ARGUMENTS_PROPERTY =
45        internalTypeArgumentsFactory(CreationReference.class);
46
47    /**
48     * A list of property descriptors (element type:
49     * {@link StructuralPropertyDescriptor}),
50     * or null if uninitialized.
51     */
52    private static final List PROPERTY_DESCRIPTORS_8_0;
53
54    static {
55        List propertyList = new ArrayList(3);
56        createPropertyList(CreationReference.classpropertyList);
57        addProperty(TYPE_PROPERTYpropertyList);
58        addProperty(TYPE_ARGUMENTS_PROPERTYpropertyList);
59        PROPERTY_DESCRIPTORS_8_0 = reapPropertyList(propertyList);
60    }
61
62    /**
63     * Returns a list of structural property descriptors for this node type.
64     * Clients must not modify the result.
65     *
66     * @param apiLevel the API level; one of the AST.JLS* constants
67     * @return a list of property descriptors (element type:
68     * {@link StructuralPropertyDescriptor})
69     */
70    public static List propertyDescriptors(int apiLevel) {
71        return PROPERTY_DESCRIPTORS_8_0;
72    }
73
74    /**
75     * The type; lazily initialized; defaults to an unspecified type.
76     */
77    private Type type = null;
78
79    /**
80     * Creates a new AST node for an CreationReference declaration owned
81     * by the given AST.
82     * <p>
83     * N.B. This constructor is package-private; all subclasses must be
84     * declared in the same package; clients are unable to declare
85     * additional subclasses.
86     * </p>
87     *
88     * @param ast the AST that is to own this node
89     */
90    CreationReference(AST ast) {
91        super(ast);
92        unsupportedIn2_3_4();
93    }
94
95    @Override
96    final ChildListPropertyDescriptor internalTypeArgumentsProperty() {
97        return TYPE_ARGUMENTS_PROPERTY;
98    }
99
100    @Override
101    final List internalStructuralPropertiesForType(int apiLevel) {
102        return propertyDescriptors(apiLevel);
103    }
104
105    @Override
106    final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor propertyboolean getASTNode child) {
107        if (property == TYPE_PROPERTY) {
108            if (get) {
109                return getType();
110            } else {
111                setType((Typechild);
112                return null;
113            }
114        }
115        // allow default implementation to flag the error
116        return super.internalGetSetChildProperty(propertygetchild);
117    }
118
119    @Override
120    final List internalGetChildListProperty(ChildListPropertyDescriptor property) {
121        if (property == TYPE_ARGUMENTS_PROPERTY) {
122            return typeArguments();
123        }
124        // allow default implementation to flag the error
125        return super.internalGetChildListProperty(property);
126    }
127
128    @Override
129    final int getNodeType0() {
130        return CREATION_REFERENCE;
131    }
132
133    @Override
134    ASTNode clone0(AST target) {
135        CreationReference result = new CreationReference(target);
136        result.setSourceRange(getStartPosition(), getLength());
137        result.setType((TypeASTNode.copySubtree(targetgetType()));
138        result.typeArguments().addAll(ASTNode.copySubtrees(targettypeArguments()));
139        return result;
140    }
141
142    @Override
143    final boolean subtreeMatch0(ASTMatcher matcherObject other) {
144        // dispatch to correct overloaded match method
145        return matcher.match(this, other);
146    }
147
148    @Override
149    void accept0(ASTVisitor visitor) {
150        boolean visitChildren = visitor.visit(this);
151        if (visitChildren) {
152            // visit children in normal left to right reading order
153            acceptChild(visitorgetType());
154            acceptChildren(visitor, this.typeArguments);
155        }
156        visitor.endVisit(this);
157    }
158
159    /**
160     * Returns the type of this creation reference expression.
161     *
162     * @return the type node
163     */
164    public Type getType() {
165        if (this.type == null) {
166            // lazy init must be thread-safe for readers
167            synchronized (this) {
168                if (this.type == null) {
169                    preLazyInit();
170                    this.type = new SimpleType(this.ast);
171                    postLazyInit(this.typeTYPE_PROPERTY);
172                }
173            }
174        }
175        return this.type;
176    }
177
178    /**
179     * Sets the type of this creation reference expression.
180     *
181     * @param type the new type node
182     * @exception IllegalArgumentException if:
183     * <ul>
184     * <li>the node belongs to a different AST</li>
185     * <li>the node already has a parent</li>
186     * </ul>
187     */
188    public void setType(Type type) {
189        if (type == null) {
190            throw new IllegalArgumentException();
191        }
192        ASTNode oldChild = this.type;
193        preReplaceChild(oldChildtypeTYPE_PROPERTY);
194        this.type = type;
195        postReplaceChild(oldChildtypeTYPE_PROPERTY);
196    }
197
198    /**
199     * Returns the live ordered list of type arguments of this creation reference expression.
200     *
201     * @return the live list of type arguments
202     *    (element type: {@link Type})
203     */
204    @Override
205    public List typeArguments() {
206        return this.typeArguments;
207    }
208
209    @Override
210    int memSize() {
211        // treat Code as free
212        return BASE_NODE_SIZE + 2 * 4;
213    }
214
215    @Override
216    int treeSize() {
217        return
218            memSize()
219            + (this.type == null ? 0 : getType().treeSize())
220            + (this.typeArguments == null ? 0 : this.typeArguments.listSize());
221    }
222}
223
MembersX
CreationReference:TYPE_ARGUMENTS_PROPERTY
CreationReference:CreationReference
CreationReference:internalGetChildListProperty
CreationReference:subtreeMatch0
CreationReference:clone0:Block:result
CreationReference:Block:propertyList
CreationReference:setType
CreationReference:getType
CreationReference:accept0
CreationReference:getNodeType0
CreationReference:propertyDescriptors
CreationReference:treeSize
CreationReference:type
CreationReference:internalStructuralPropertiesForType
CreationReference:clone0
CreationReference:typeArguments
CreationReference:memSize
CreationReference:accept0:Block:visitChildren
CreationReference:internalTypeArgumentsProperty
CreationReference:setType:Block:oldChild
CreationReference:TYPE_PROPERTY
CreationReference:PROPERTY_DESCRIPTORS_8_0
CreationReference:internalGetSetChildProperty
Members
X