KickJava   Java API By Example, From Geeks To Geeks.

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


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  * Break statement AST node type.
19  *
20  * <pre>
21  * BreakStatement:
22  * <b>break</b> [ Identifier ] <b>;</b>
23  * </pre>
24  *
25  * @since 2.0
26  */

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

33     public static final ChildPropertyDescriptor LABEL_PROPERTY =
34         new ChildPropertyDescriptor(BreakStatement.class, "label", SimpleName.class, OPTIONAL, NO_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(BreakStatement.class, properyList);
46         addProperty(LABEL_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
57      * @return a list of property descriptors (element type:
58      * {@link StructuralPropertyDescriptor})
59      * @since 3.0
60      */

61     public static List JavaDoc propertyDescriptors(int apiLevel) {
62         return PROPERTY_DESCRIPTORS;
63     }
64             
65     /**
66      * The label, or <code>null</code> if none; none by default.
67      */

68     private SimpleName optionalLabel = null;
69
70     /**
71      * Creates a new unparented break statement node owned by the given
72      * AST. By default, the break statement has no label.
73      * <p>
74      * N.B. This constructor is package-private.
75      * </p>
76      *
77      * @param ast the AST that is to own this node
78      */

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

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

93     final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) {
94         if (property == LABEL_PROPERTY) {
95             if (get) {
96                 return getLabel();
97             } else {
98                 setLabel((SimpleName) child);
99                 return null;
100             }
101         }
102         // allow default implementation to flag the error
103
return super.internalGetSetChildProperty(property, get, child);
104     }
105     
106     /* (omit javadoc for this method)
107      * Method declared on ASTNode.
108      */

109     final int getNodeType0() {
110         return BREAK_STATEMENT;
111     }
112
113     /* (omit javadoc for this method)
114      * Method declared on ASTNode.
115      */

116     ASTNode clone0(AST target) {
117         BreakStatement result = new BreakStatement(target);
118         result.setSourceRange(this.getStartPosition(), this.getLength());
119         result.copyLeadingComment(this);
120         result.setLabel((SimpleName) ASTNode.copySubtree(target, getLabel()));
121         return result;
122     }
123
124     /* (omit javadoc for this method)
125      * Method declared on ASTNode.
126      */

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

135     void accept0(ASTVisitor visitor) {
136         boolean visitChildren = visitor.visit(this);
137         if (visitChildren) {
138             acceptChild(visitor, getLabel());
139         }
140         visitor.endVisit(this);
141     }
142     
143     /**
144      * Returns the label of this break statement, or <code>null</code> if
145      * there is none.
146      *
147      * @return the label, or <code>null</code> if there is none
148      */

149     public SimpleName getLabel() {
150         return this.optionalLabel;
151     }
152     
153     /**
154      * Sets or clears the label of this break statement.
155      *
156      * @param label the label, or <code>null</code> if
157      * there is none
158      * @exception IllegalArgumentException if:
159      * <ul>
160      * <li>the node belongs to a different AST</li>
161      * <li>the node already has a parent</li>
162      * </ul>
163      */

164     public void setLabel(SimpleName label) {
165         ASTNode oldChild = this.optionalLabel;
166         preReplaceChild(oldChild, label, LABEL_PROPERTY);
167         this.optionalLabel = label;
168         postReplaceChild(oldChild, label, LABEL_PROPERTY);
169     }
170     
171     /* (omit javadoc for this method)
172      * Method declared on ASTNode.
173      */

174     int memSize() {
175         return super.memSize() + 1 * 4;
176     }
177     
178     /* (omit javadoc for this method)
179      * Method declared on ASTNode.
180      */

181     int treeSize() {
182         return
183             memSize()
184             + (this.optionalLabel == null ? 0 : getLabel().treeSize());
185     }
186 }
187
188
Popular Tags