EclipseJDT Source Viewer

Home|eclipse_jdt/src/org/eclipse/jdt/core/dom/ArrayInitializer.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 * Array initializer AST node type.
22 *
23 * <pre>
24 * ArrayInitializer:
25 *         <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 ArrayInitializer extends Expression {
33
34    /**
35     * The "expressions" structural property of this node type (element type: {@link Expression}).
36     * @since 3.0
37     */
38    public static final ChildListPropertyDescriptor EXPRESSIONS_PROPERTY =
39        new ChildListPropertyDescriptor(ArrayInitializer.class"expressions"Expression.classCYCLE_RISK); //$NON-NLS-1$
40
41    /**
42     * A list of property descriptors (element type:
43     * {@link StructuralPropertyDescriptor}),
44     * or null if uninitialized.
45     */
46    private static final List PROPERTY_DESCRIPTORS;
47
48    static {
49        List properyList = new ArrayList(2);
50        createPropertyList(ArrayInitializer.classproperyList);
51        addProperty(EXPRESSIONS_PROPERTYproperyList);
52        PROPERTY_DESCRIPTORS = reapPropertyList(properyList);
53    }
54
55    /**
56     * Returns a list of structural property descriptors for this node type.
57     * Clients must not modify the result.
58     *
59     * @param apiLevel the API level; one of the
60     * <code>AST.JLS*</code> constants
61
62     * @return a list of property descriptors (element type:
63     * {@link StructuralPropertyDescriptor})
64     * @since 3.0
65     */
66    public static List propertyDescriptors(int apiLevel) {
67        return PROPERTY_DESCRIPTORS;
68    }
69
70    /**
71     * The list of expressions (element type:
72     * {@link Expression}). Defaults to an empty list.
73     */
74    private ASTNode.NodeList expressions =
75        new ASTNode.NodeList(EXPRESSIONS_PROPERTY);
76
77    /**
78     * Creates a new AST node for an array initializer owned by the
79     * given AST. By default, the list of expressions is empty.
80     *
81     * @param ast the AST that is to own this node
82     */
83    ArrayInitializer(AST ast) {
84        super(ast);
85    }
86
87    @Override
88    final List internalStructuralPropertiesForType(int apiLevel) {
89        return propertyDescriptors(apiLevel);
90    }
91
92    @Override
93    final List internalGetChildListProperty(ChildListPropertyDescriptor property) {
94        if (property == EXPRESSIONS_PROPERTY) {
95            return expressions();
96        }
97        // allow default implementation to flag the error
98        return super.internalGetChildListProperty(property);
99    }
100
101    @Override
102    final int getNodeType0() {
103        return ARRAY_INITIALIZER;
104    }
105
106    @Override
107    ASTNode clone0(AST target) {
108        ArrayInitializer result = new ArrayInitializer(target);
109        result.setSourceRange(getStartPosition(), getLength());
110        result.expressions().addAll(ASTNode.copySubtrees(targetexpressions()));
111        return result;
112    }
113
114    @Override
115    final boolean subtreeMatch0(ASTMatcher matcherObject other) {
116        // dispatch to correct overloaded match method
117        return matcher.match(this, other);
118    }
119
120    @Override
121    void accept0(ASTVisitor visitor) {
122        boolean visitChildren = visitor.visit(this);
123        if (visitChildren) {
124            acceptChildren(visitor, this.expressions);
125        }
126        visitor.endVisit(this);
127    }
128
129    /**
130     * Returns the live ordered list of expressions in this array initializer.
131     *
132     * @return the live list of expressions
133     *    (element type: {@link Expression})
134     */
135    public List expressions() {
136        return this.expressions;
137    }
138
139    @Override
140    int memSize() {
141        return BASE_NODE_SIZE + 1 * 4;
142    }
143
144    @Override
145    int treeSize() {
146        return memSize() + this.expressions.listSize();
147    }
148}
149
150
MembersX
ArrayInitializer:EXPRESSIONS_PROPERTY
ArrayInitializer:internalStructuralPropertiesForType
ArrayInitializer:memSize
ArrayInitializer:ArrayInitializer
ArrayInitializer:subtreeMatch0
ArrayInitializer:Block:properyList
ArrayInitializer:accept0
ArrayInitializer:treeSize
ArrayInitializer:internalGetChildListProperty
ArrayInitializer:PROPERTY_DESCRIPTORS
ArrayInitializer:expressions
ArrayInitializer:propertyDescriptors
ArrayInitializer:clone0:Block:result
ArrayInitializer:accept0:Block:visitChildren
ArrayInitializer:getNodeType0
ArrayInitializer:clone0
Members
X