blob: f2c115d28b700672a015fd0369e9f1b46770ed0b [file] [log] [blame]
Stephan Herrmann7b7062f2010-04-01 19:56:59 +00001/*******************************************************************************
Stephan Herrmann66cc2b62010-09-26 15:38:59 +00002 * Copyright (c) 2000, 2010 IBM Corporation and others.
Stephan Herrmann7b7062f2010-04-01 19:56:59 +00003 * 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
12package org.eclipse.jdt.core.dom;
13
14import java.util.ArrayList;
15import java.util.List;
16
17/**
18 * Array initializer AST node type.
19 *
20 * <pre>
21 * ArrayInitializer:
22 * <b>{</b> [ Expression { <b>,</b> Expression} [ <b>,</b> ]] <b>}</b>
23 * </pre>
Stephan Herrmannab1b9762010-09-26 14:31:00 +000024 *
Stephan Herrmann7b7062f2010-04-01 19:56:59 +000025 * @since 2.0
26 * @noinstantiate This class is not intended to be instantiated by clients.
27 */
28public class ArrayInitializer extends Expression {
Stephan Herrmannab1b9762010-09-26 14:31:00 +000029
Stephan Herrmann7b7062f2010-04-01 19:56:59 +000030 /**
Stephan Herrmann66cc2b62010-09-26 15:38:59 +000031 * The "expressions" structural property of this node type (element type: {@link Expression}).
Stephan Herrmann7b7062f2010-04-01 19:56:59 +000032 * @since 3.0
33 */
Stephan Herrmannab1b9762010-09-26 14:31:00 +000034 public static final ChildListPropertyDescriptor EXPRESSIONS_PROPERTY =
Stephan Herrmann7b7062f2010-04-01 19:56:59 +000035 new ChildListPropertyDescriptor(ArrayInitializer.class, "expressions", Expression.class, CYCLE_RISK); //$NON-NLS-1$
36
37 /**
Stephan Herrmannab1b9762010-09-26 14:31:00 +000038 * A list of property descriptors (element type:
Stephan Herrmann7b7062f2010-04-01 19:56:59 +000039 * {@link StructuralPropertyDescriptor}),
40 * or null if uninitialized.
41 */
42 private static final List PROPERTY_DESCRIPTORS;
Stephan Herrmannab1b9762010-09-26 14:31:00 +000043
Stephan Herrmann7b7062f2010-04-01 19:56:59 +000044 static {
45 List properyList = new ArrayList(2);
46 createPropertyList(ArrayInitializer.class, properyList);
47 addProperty(EXPRESSIONS_PROPERTY, properyList);
48 PROPERTY_DESCRIPTORS = reapPropertyList(properyList);
49 }
50
51 /**
52 * Returns a list of structural property descriptors for this node type.
53 * Clients must not modify the result.
Stephan Herrmannab1b9762010-09-26 14:31:00 +000054 *
Stephan Herrmann7b7062f2010-04-01 19:56:59 +000055 * @param apiLevel the API level; one of the
56 * <code>AST.JLS*</code> constants
57
Stephan Herrmannab1b9762010-09-26 14:31:00 +000058 * @return a list of property descriptors (element type:
Stephan Herrmann7b7062f2010-04-01 19:56:59 +000059 * {@link StructuralPropertyDescriptor})
60 * @since 3.0
61 */
62 public static List propertyDescriptors(int apiLevel) {
63 return PROPERTY_DESCRIPTORS;
64 }
Stephan Herrmannab1b9762010-09-26 14:31:00 +000065
Stephan Herrmann7b7062f2010-04-01 19:56:59 +000066 /**
67 * The list of expressions (element type:
Stephan Herrmann66cc2b62010-09-26 15:38:59 +000068 * {@link Expression}). Defaults to an empty list.
Stephan Herrmann7b7062f2010-04-01 19:56:59 +000069 */
70 private ASTNode.NodeList expressions =
71 new ASTNode.NodeList(EXPRESSIONS_PROPERTY);
72
73 /**
Stephan Herrmannab1b9762010-09-26 14:31:00 +000074 * Creates a new AST node for an array initializer owned by the
Stephan Herrmann7b7062f2010-04-01 19:56:59 +000075 * given AST. By default, the list of expressions is empty.
Stephan Herrmannab1b9762010-09-26 14:31:00 +000076 *
Stephan Herrmann7b7062f2010-04-01 19:56:59 +000077 * @param ast the AST that is to own this node
78 */
79 ArrayInitializer(AST ast) {
Stephan Herrmannab1b9762010-09-26 14:31:00 +000080 super(ast);
Stephan Herrmann7b7062f2010-04-01 19:56:59 +000081 }
82
83 /* (omit javadoc for this method)
84 * Method declared on ASTNode.
85 */
86 final List internalStructuralPropertiesForType(int apiLevel) {
87 return propertyDescriptors(apiLevel);
88 }
Stephan Herrmannab1b9762010-09-26 14:31:00 +000089
Stephan Herrmann7b7062f2010-04-01 19:56:59 +000090 /* (omit javadoc for this method)
91 * Method declared on ASTNode.
92 */
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 /* (omit javadoc for this method)
102 * Method declared on ASTNode.
103 */
104 final int getNodeType0() {
105 return ARRAY_INITIALIZER;
106 }
107
108 /* (omit javadoc for this method)
109 * Method declared on ASTNode.
110 */
111 ASTNode clone0(AST target) {
112 ArrayInitializer result = new ArrayInitializer(target);
113 result.setSourceRange(getStartPosition(), getLength());
114 result.expressions().addAll(ASTNode.copySubtrees(target, expressions()));
115 return result;
116 }
117
118 /* (omit javadoc for this method)
119 * Method declared on ASTNode.
120 */
121 final boolean subtreeMatch0(ASTMatcher matcher, Object other) {
122 // dispatch to correct overloaded match method
123 return matcher.match(this, other);
124 }
125
126 /* (omit javadoc for this method)
127 * Method declared on ASTNode.
128 */
129 void accept0(ASTVisitor visitor) {
130 boolean visitChildren = visitor.visit(this);
131 if (visitChildren) {
132 acceptChildren(visitor, this.expressions);
133 }
134 visitor.endVisit(this);
135 }
Stephan Herrmannab1b9762010-09-26 14:31:00 +0000136
Stephan Herrmann7b7062f2010-04-01 19:56:59 +0000137 /**
138 * Returns the live ordered list of expressions in this array initializer.
Stephan Herrmannab1b9762010-09-26 14:31:00 +0000139 *
140 * @return the live list of expressions
Stephan Herrmann66cc2b62010-09-26 15:38:59 +0000141 * (element type: {@link Expression})
Stephan Herrmannab1b9762010-09-26 14:31:00 +0000142 */
Stephan Herrmann7b7062f2010-04-01 19:56:59 +0000143 public List expressions() {
144 return this.expressions;
145 }
Stephan Herrmannab1b9762010-09-26 14:31:00 +0000146
Stephan Herrmann7b7062f2010-04-01 19:56:59 +0000147 /* (omit javadoc for this method)
148 * Method declared on ASTNode.
149 */
150 int memSize() {
151 return BASE_NODE_SIZE + 1 * 4;
152 }
Stephan Herrmannab1b9762010-09-26 14:31:00 +0000153
Stephan Herrmann7b7062f2010-04-01 19:56:59 +0000154 /* (omit javadoc for this method)
155 * Method declared on ASTNode.
156 */
157 int treeSize() {
158 return memSize() + this.expressions.listSize();
159 }
160}
161