removed unused private methods.
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / core / dom / Block.java
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
7  *
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11
12 package net.sourceforge.phpdt.core.dom;
13
14 import java.util.ArrayList;
15 import java.util.List;
16
17 /**
18  * Block statement AST node type.
19  *
20  * <pre>
21  * Block:
22  *    <b>{</b> { Statement } <b>}</b>
23  * </pre>
24  * 
25  * @since 2.0
26  * @noinstantiate This class is not intended to be instantiated by clients.
27  */
28 public class Block extends Statement {
29         
30         /**
31          * The "statements" structural property of this node type.
32          * @since 3.0
33          */
34         public static final ChildListPropertyDescriptor STATEMENTS_PROPERTY = 
35                 new ChildListPropertyDescriptor(Block.class, "statements", Statement.class, CYCLE_RISK); //$NON-NLS-1$
36
37         /**
38          * A list of property descriptors (element type: 
39          * {@link StructuralPropertyDescriptor}),
40          * or null if uninitialized.
41          */
42         private static final List PROPERTY_DESCRIPTORS;
43         
44         static {
45                 List properyList = new ArrayList(2);
46                 createPropertyList(Block.class, properyList);
47                 addProperty(STATEMENTS_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.
54          * 
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})
59          * @since 3.0
60          */
61         public static List propertyDescriptors(int apiLevel) {
62                 return PROPERTY_DESCRIPTORS;
63         }
64                         
65         /**
66          * The list of statements (element type: <code>Statement</code>). 
67          * Defaults to an empty list.
68          */
69         private ASTNode.NodeList statements = 
70                 new ASTNode.NodeList(STATEMENTS_PROPERTY);
71
72         /**
73          * Creates a new unparented block node owned by the given AST.
74          * By default, the block is empty.
75          * <p>
76          * N.B. This constructor is package-private.
77          * </p>
78          * 
79          * @param ast the AST that is to own this node
80          */
81         Block(AST ast) {
82                 super(ast);
83         }
84
85         /* (omit javadoc for this method)
86          * Method declared on ASTNode.
87          */
88         final List internalStructuralPropertiesForType(int apiLevel) {
89                 return propertyDescriptors(apiLevel);
90         }
91         
92         /* (omit javadoc for this method)
93          * Method declared on ASTNode.
94          */
95         final List internalGetChildListProperty(ChildListPropertyDescriptor property) {
96                 if (property == STATEMENTS_PROPERTY) {
97                         return statements();
98                 }
99                 // allow default implementation to flag the error
100                 return super.internalGetChildListProperty(property);
101         }
102
103         /* (omit javadoc for this method)
104          * Method declared on ASTNode.
105          */
106         final int getNodeType0() {
107                 return BLOCK;
108         }
109
110         /* (omit javadoc for this method)
111          * Method declared on ASTNode.
112          */
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()));
119                 return result;
120         }
121
122         /* (omit javadoc for this method)
123          * Method declared on ASTNode.
124          */
125         final boolean subtreeMatch0(ASTMatcher matcher, Object other) {
126                 // dispatch to correct overloaded match method
127                 return matcher.match(this, other);
128         }
129
130         /* (omit javadoc for this method)
131          * Method declared on ASTNode.
132          */
133         void accept0(ASTVisitor visitor) {
134                 boolean visitChildren = visitor.visit(this);
135                 if (visitChildren) {
136                         acceptChildren(visitor, this.statements);
137                 }
138                 visitor.endVisit(this);
139         }
140         
141         /**
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
146          * exception.
147          * 
148          * @return the live list of statements in this block
149          *    (element type: <code>Statement</code>)
150          */ 
151         public List statements() {
152                 return this.statements;
153         }
154         
155         /* (omit javadoc for this method)
156          * Method declared on ASTNode.
157          */
158         int memSize() {
159                 return super.memSize() + 1 * 4;
160         }
161         
162         /* (omit javadoc for this method)
163          * Method declared on ASTNode.
164          */
165         int treeSize() {
166                 return memSize() + this.statements.listSize();
167         }
168 }
169