001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.jdt.core.dom;
011:
012: import java.util.ArrayList;
013: import java.util.List;
014:
015: /**
016: * Array initializer AST node type.
017: *
018: * <pre>
019: * ArrayInitializer:
020: * <b>{</b> [ Expression { <b>,</b> Expression} [ <b>,</b> ]] <b>}</b>
021: * </pre>
022: *
023: * @since 2.0
024: */
025: public class ArrayInitializer extends Expression {
026:
027: /**
028: * The "expressions" structural property of this node type.
029: * @since 3.0
030: */
031: public static final ChildListPropertyDescriptor EXPRESSIONS_PROPERTY = new ChildListPropertyDescriptor(
032: ArrayInitializer.class,
033: "expressions", Expression.class, CYCLE_RISK); //$NON-NLS-1$
034:
035: /**
036: * A list of property descriptors (element type:
037: * {@link StructuralPropertyDescriptor}),
038: * or null if uninitialized.
039: */
040: private static final List PROPERTY_DESCRIPTORS;
041:
042: static {
043: List properyList = new ArrayList(2);
044: createPropertyList(ArrayInitializer.class, properyList);
045: addProperty(EXPRESSIONS_PROPERTY, properyList);
046: PROPERTY_DESCRIPTORS = reapPropertyList(properyList);
047: }
048:
049: /**
050: * Returns a list of structural property descriptors for this node type.
051: * Clients must not modify the result.
052: *
053: * @param apiLevel the API level; one of the
054: * <code>AST.JLS*</code> constants
055:
056: * @return a list of property descriptors (element type:
057: * {@link StructuralPropertyDescriptor})
058: * @since 3.0
059: */
060: public static List propertyDescriptors(int apiLevel) {
061: return PROPERTY_DESCRIPTORS;
062: }
063:
064: /**
065: * The list of expressions (element type:
066: * <code>Expression</code>). Defaults to an empty list.
067: */
068: private ASTNode.NodeList expressions = new ASTNode.NodeList(
069: EXPRESSIONS_PROPERTY);
070:
071: /**
072: * Creates a new AST node for an array initializer owned by the
073: * given AST. By default, the list of expressions is empty.
074: *
075: * @param ast the AST that is to own this node
076: */
077: ArrayInitializer(AST ast) {
078: super (ast);
079: }
080:
081: /* (omit javadoc for this method)
082: * Method declared on ASTNode.
083: */
084: final List internalStructuralPropertiesForType(int apiLevel) {
085: return propertyDescriptors(apiLevel);
086: }
087:
088: /* (omit javadoc for this method)
089: * Method declared on ASTNode.
090: */
091: final List internalGetChildListProperty(
092: ChildListPropertyDescriptor property) {
093: if (property == EXPRESSIONS_PROPERTY) {
094: return expressions();
095: }
096: // allow default implementation to flag the error
097: return super .internalGetChildListProperty(property);
098: }
099:
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
113: .setSourceRange(this .getStartPosition(), this
114: .getLength());
115: result.expressions().addAll(
116: ASTNode.copySubtrees(target, expressions()));
117: return result;
118: }
119:
120: /* (omit javadoc for this method)
121: * Method declared on ASTNode.
122: */
123: final boolean subtreeMatch0(ASTMatcher matcher, Object other) {
124: // dispatch to correct overloaded match method
125: return matcher.match(this , other);
126: }
127:
128: /* (omit javadoc for this method)
129: * Method declared on ASTNode.
130: */
131: void accept0(ASTVisitor visitor) {
132: boolean visitChildren = visitor.visit(this );
133: if (visitChildren) {
134: acceptChildren(visitor, this .expressions);
135: }
136: visitor.endVisit(this );
137: }
138:
139: /**
140: * Returns the live ordered list of expressions in this array initializer.
141: *
142: * @return the live list of expressions
143: * (element type: <code>Expression</code>)
144: */
145: public List expressions() {
146: return this .expressions;
147: }
148:
149: /* (omit javadoc for this method)
150: * Method declared on ASTNode.
151: */
152: int memSize() {
153: return BASE_NODE_SIZE + 1 * 4;
154: }
155:
156: /* (omit javadoc for this method)
157: * Method declared on ASTNode.
158: */
159: int treeSize() {
160: return memSize() + this.expressions.listSize();
161: }
162: }
|