KickJava   Java API By Example, From Geeks To Geeks.

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


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  * Block statement AST node type.
19  *
20  * <pre>
21  * Block:
22  * <b>{</b> { Statement } <b>}</b>
23  * </pre>
24  *
25  * @since 2.0
26  */

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

33     public static final ChildListPropertyDescriptor STATEMENTS_PROPERTY =
34         new ChildListPropertyDescriptor(Block.class, "statements", Statement.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(Block.class, properyList);
46         addProperty(STATEMENTS_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      * @return a list of property descriptors (element type:
57      * {@link StructuralPropertyDescriptor})
58      * @since 3.0
59      */

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

68     private ASTNode.NodeList statements =
69         new ASTNode.NodeList(STATEMENTS_PROPERTY);
70
71     /**
72      * Creates a new unparented block node owned by the given AST.
73      * By default, the block is empty.
74      * <p>
75      * N.B. This constructor is package-private.
76      * </p>
77      *
78      * @param ast the AST that is to own this node
79      */

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

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

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

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

112     ASTNode clone0(AST target) {
113         Block result = new Block(target);
114         result.setSourceRange(this.getStartPosition(), this.getLength());
115         result.copyLeadingComment(this);
116         result.statements().addAll(
117             ASTNode.copySubtrees(target, statements()));
118         return result;
119     }
120
121     /* (omit javadoc for this method)
122      * Method declared on ASTNode.
123      */

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

132     void accept0(ASTVisitor visitor) {
133         boolean visitChildren = visitor.visit(this);
134         if (visitChildren) {
135             acceptChildren(visitor, this.statements);
136         }
137         visitor.endVisit(this);
138     }
139     
140     /**
141      * Returns the live list of statements in this block. Adding and
142      * removing nodes from this list affects this node dynamically.
143      * All nodes in this list must be <code>Statement</code>s;
144      * attempts to add any other type of node will trigger an
145      * exception.
146      *
147      * @return the live list of statements in this block
148      * (element type: <code>Statement</code>)
149      */

150     public List JavaDoc statements() {
151         return this.statements;
152     }
153     
154     /* (omit javadoc for this method)
155      * Method declared on ASTNode.
156      */

157     int memSize() {
158         return super.memSize() + 1 * 4;
159     }
160     
161     /* (omit javadoc for this method)
162      * Method declared on ASTNode.
163      */

164     int treeSize() {
165         return memSize() + this.statements.listSize();
166     }
167 }
168
169
Popular Tags