KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 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  * Array initializer AST node type.
19  *
20  * <pre>
21  * ArrayInitializer:
22  * <b>{</b> [ Expression { <b>,</b> Expression} [ <b>,</b> ]] <b>}</b>
23  * </pre>
24  *
25  * @since 2.0
26  */

27 public class ArrayInitializer extends Expression {
28     
29     /**
30      * The "expressions" structural property of this node type.
31      * @since 3.0
32      */

33     public static final ChildListPropertyDescriptor EXPRESSIONS_PROPERTY =
34         new ChildListPropertyDescriptor(ArrayInitializer.class, "expressions", Expression.class, CYCLE_RISK); //$NON-NLS-1$
35

36     /**
37      * A list of property descriptors (element type:
38      * {@link StructuralPropertyDescriptor}),
39      * or null if uninitialized.
40      */

41     private static final List JavaDoc PROPERTY_DESCRIPTORS;
42     
43     static {
44         List JavaDoc properyList = new ArrayList JavaDoc(2);
45         createPropertyList(ArrayInitializer.class, properyList);
46         addProperty(EXPRESSIONS_PROPERTY, properyList);
47         PROPERTY_DESCRIPTORS = reapPropertyList(properyList);
48     }
49
50     /**
51      * Returns a list of structural property descriptors for this node type.
52      * Clients must not modify the result.
53      *
54      * @param apiLevel the API level; one of the
55      * <code>AST.JLS&ast;</code> constants
56
57      * @return a list of property descriptors (element type:
58      * {@link StructuralPropertyDescriptor})
59      * @since 3.0
60      */

61     public static List JavaDoc propertyDescriptors(int apiLevel) {
62         return PROPERTY_DESCRIPTORS;
63     }
64             
65     /**
66      * The list of expressions (element type:
67      * <code>Expression</code>). Defaults to an empty list.
68      */

69     private ASTNode.NodeList expressions =
70         new ASTNode.NodeList(EXPRESSIONS_PROPERTY);
71
72     /**
73      * Creates a new AST node for an array initializer owned by the
74      * given AST. By default, the list of expressions is empty.
75      *
76      * @param ast the AST that is to own this node
77      */

78     ArrayInitializer(AST ast) {
79         super(ast);
80     }
81
82     /* (omit javadoc for this method)
83      * Method declared on ASTNode.
84      */

85     final List JavaDoc internalStructuralPropertiesForType(int apiLevel) {
86         return propertyDescriptors(apiLevel);
87     }
88     
89     /* (omit javadoc for this method)
90      * Method declared on ASTNode.
91      */

92     final List JavaDoc internalGetChildListProperty(ChildListPropertyDescriptor property) {
93         if (property == EXPRESSIONS_PROPERTY) {
94             return expressions();
95         }
96         // allow default implementation to flag the error
97
return super.internalGetChildListProperty(property);
98     }
99
100     /* (omit javadoc for this method)
101      * Method declared on ASTNode.
102      */

103     final int getNodeType0() {
104         return ARRAY_INITIALIZER;
105     }
106
107     /* (omit javadoc for this method)
108      * Method declared on ASTNode.
109      */

110     ASTNode clone0(AST target) {
111         ArrayInitializer result = new ArrayInitializer(target);
112         result.setSourceRange(this.getStartPosition(), this.getLength());
113         result.expressions().addAll(ASTNode.copySubtrees(target, expressions()));
114         return result;
115     }
116
117     /* (omit javadoc for this method)
118      * Method declared on ASTNode.
119      */

120     final boolean subtreeMatch0(ASTMatcher matcher, Object JavaDoc other) {
121         // dispatch to correct overloaded match method
122
return matcher.match(this, other);
123     }
124
125     /* (omit javadoc for this method)
126      * Method declared on ASTNode.
127      */

128     void accept0(ASTVisitor visitor) {
129         boolean visitChildren = visitor.visit(this);
130         if (visitChildren) {
131             acceptChildren(visitor, this.expressions);
132         }
133         visitor.endVisit(this);
134     }
135     
136     /**
137      * Returns the live ordered list of expressions in this array initializer.
138      *
139      * @return the live list of expressions
140      * (element type: <code>Expression</code>)
141      */

142     public List JavaDoc expressions() {
143         return this.expressions;
144     }
145     
146     /* (omit javadoc for this method)
147      * Method declared on ASTNode.
148      */

149     int memSize() {
150         return BASE_NODE_SIZE + 1 * 4;
151     }
152     
153     /* (omit javadoc for this method)
154      * Method declared on ASTNode.
155      */

156     int treeSize() {
157         return memSize() + this.expressions.listSize();
158     }
159 }
160
161
Popular Tags