1 /*******************************************************************************
 
   2  * Copyright (c) 2000, 2008 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
 
   9  *     IBM Corporation - initial API and implementation
 
  10  *******************************************************************************/
 
  12 package net.sourceforge.phpdt.core.dom;
 
  14 import java.util.ArrayList;
 
  15 import java.util.List;
 
  18  * Array initializer AST node type.
 
  22  *              <b>{</b> [ Expression { <b>,</b> Expression} [ <b>,</b> ]] <b>}</b>
 
  26  * @noinstantiate This class is not intended to be instantiated by clients.
 
  28 public class ArrayInitializer extends Expression {
 
  31          * The "expressions" structural property of this node type.
 
  34         public static final ChildListPropertyDescriptor EXPRESSIONS_PROPERTY = 
 
  35                 new ChildListPropertyDescriptor(ArrayInitializer.class, "expressions", Expression.class, CYCLE_RISK); //$NON-NLS-1$
 
  38          * A list of property descriptors (element type: 
 
  39          * {@link StructuralPropertyDescriptor}),
 
  40          * or null if uninitialized.
 
  42         private static final List PROPERTY_DESCRIPTORS;
 
  45                 List properyList = new ArrayList(2);
 
  46                 createPropertyList(ArrayInitializer.class, properyList);
 
  47                 addProperty(EXPRESSIONS_PROPERTY, properyList);
 
  48                 PROPERTY_DESCRIPTORS = reapPropertyList(properyList);
 
  52          * Returns a list of structural property descriptors for this node type.
 
  53          * Clients must not modify the result.
 
  55          * @param apiLevel the API level; one of the
 
  56          * <code>AST.JLS*</code> constants
 
  58          * @return a list of property descriptors (element type: 
 
  59          * {@link StructuralPropertyDescriptor})
 
  62         public static List propertyDescriptors(int apiLevel) {
 
  63                 return PROPERTY_DESCRIPTORS;
 
  67          * The list of expressions (element type:
 
  68          * <code>Expression</code>). Defaults to an empty list.
 
  70         private ASTNode.NodeList expressions =
 
  71                 new ASTNode.NodeList(EXPRESSIONS_PROPERTY);
 
  74          * Creates a new AST node for an array initializer owned by the 
 
  75          * given AST. By default, the list of expressions is empty.
 
  77          * @param ast the AST that is to own this node
 
  79         ArrayInitializer(AST ast) {
 
  83         /* (omit javadoc for this method)
 
  84          * Method declared on ASTNode.
 
  86         final List internalStructuralPropertiesForType(int apiLevel) {
 
  87                 return propertyDescriptors(apiLevel);
 
  90         /* (omit javadoc for this method)
 
  91          * Method declared on ASTNode.
 
  93         final List internalGetChildListProperty(ChildListPropertyDescriptor property) {
 
  94                 if (property == EXPRESSIONS_PROPERTY) {
 
  97                 // allow default implementation to flag the error
 
  98                 return super.internalGetChildListProperty(property);
 
 101         /* (omit javadoc for this method)
 
 102          * Method declared on ASTNode.
 
 104         final int getNodeType0() {
 
 105                 return ARRAY_INITIALIZER;
 
 108         /* (omit javadoc for this method)
 
 109          * Method declared on ASTNode.
 
 111         ASTNode clone0(AST target) {
 
 112                 ArrayInitializer result = new ArrayInitializer(target);
 
 113                 result.setSourceRange(this.getStartPosition(), this.getLength());
 
 114                 result.expressions().addAll(ASTNode.copySubtrees(target, expressions()));
 
 118         /* (omit javadoc for this method)
 
 119          * Method declared on ASTNode.
 
 121         final boolean subtreeMatch0(ASTMatcher matcher, Object other) {
 
 122                 // dispatch to correct overloaded match method
 
 123                 return matcher.match(this, other);
 
 126         /* (omit javadoc for this method)
 
 127          * Method declared on ASTNode.
 
 129         void accept0(ASTVisitor visitor) {
 
 130                 boolean visitChildren = visitor.visit(this);
 
 132                         acceptChildren(visitor, this.expressions);
 
 134                 visitor.endVisit(this);
 
 138          * Returns the live ordered list of expressions in this array initializer.
 
 140          * @return the live list of expressions 
 
 141          *    (element type: <code>Expression</code>)
 
 143         public List expressions() {
 
 144                 return this.expressions;
 
 147         /* (omit javadoc for this method)
 
 148          * Method declared on ASTNode.
 
 151                 return BASE_NODE_SIZE + 1 * 4;
 
 154         /* (omit javadoc for this method)
 
 155          * Method declared on ASTNode.
 
 158                 return memSize() + this.expressions.listSize();