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 * Block statement AST node type.
22 * <b>{</b> { Statement } <b>}</b>
26 * @noinstantiate This class is not intended to be instantiated by clients.
28 public class Block extends Statement {
31 * The "statements" structural property of this node type.
34 public static final ChildListPropertyDescriptor STATEMENTS_PROPERTY =
35 new ChildListPropertyDescriptor(Block.class, "statements", Statement.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(Block.class, properyList);
47 addProperty(STATEMENTS_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
57 * @return a list of property descriptors (element type:
58 * {@link StructuralPropertyDescriptor})
61 public static List propertyDescriptors(int apiLevel) {
62 return PROPERTY_DESCRIPTORS;
66 * The list of statements (element type: <code>Statement</code>).
67 * Defaults to an empty list.
69 private ASTNode.NodeList statements =
70 new ASTNode.NodeList(STATEMENTS_PROPERTY);
73 * Creates a new unparented block node owned by the given AST.
74 * By default, the block is empty.
76 * N.B. This constructor is package-private.
79 * @param ast the AST that is to own this node
85 /* (omit javadoc for this method)
86 * Method declared on ASTNode.
88 final List internalStructuralPropertiesForType(int apiLevel) {
89 return propertyDescriptors(apiLevel);
92 /* (omit javadoc for this method)
93 * Method declared on ASTNode.
95 final List internalGetChildListProperty(ChildListPropertyDescriptor property) {
96 if (property == STATEMENTS_PROPERTY) {
99 // allow default implementation to flag the error
100 return super.internalGetChildListProperty(property);
103 /* (omit javadoc for this method)
104 * Method declared on ASTNode.
106 final int getNodeType0() {
110 /* (omit javadoc for this method)
111 * Method declared on ASTNode.
113 ASTNode clone0(AST target) {
114 Block result = new Block(target);
115 result.setSourceRange(this.getStartPosition(), this.getLength());
116 result.copyLeadingComment(this);
117 result.statements().addAll(
118 ASTNode.copySubtrees(target, statements()));
122 /* (omit javadoc for this method)
123 * Method declared on ASTNode.
125 final boolean subtreeMatch0(ASTMatcher matcher, Object other) {
126 // dispatch to correct overloaded match method
127 return matcher.match(this, other);
130 /* (omit javadoc for this method)
131 * Method declared on ASTNode.
133 void accept0(ASTVisitor visitor) {
134 boolean visitChildren = visitor.visit(this);
136 acceptChildren(visitor, this.statements);
138 visitor.endVisit(this);
142 * Returns the live list of statements in this block. Adding and
143 * removing nodes from this list affects this node dynamically.
144 * All nodes in this list must be <code>Statement</code>s;
145 * attempts to add any other type of node will trigger an
148 * @return the live list of statements in this block
149 * (element type: <code>Statement</code>)
151 public List statements() {
152 return this.statements;
155 /* (omit javadoc for this method)
156 * Method declared on ASTNode.
159 return super.memSize() + 1 * 4;
162 /* (omit javadoc for this method)
163 * Method declared on ASTNode.
166 return memSize() + this.statements.listSize();