1cd6862d8e7cb92cc674b18a46c46ab763aa35af
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / core / dom / ContinueStatement.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  * Continue statement AST node type.
19  *
20  * <pre>
21  * ContinueStatement:
22  *    <b>continue</b> [ Identifier ] <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 ContinueStatement extends Statement {
29                         
30         /**
31          * The "label" structural property of this node type.
32          * @since 3.0
33          */
34         public static final ChildPropertyDescriptor LABEL_PROPERTY = 
35                 new ChildPropertyDescriptor(ContinueStatement.class, "label", SimpleName.class, OPTIONAL, NO_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(ContinueStatement.class, properyList);
47                 addProperty(LABEL_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
58          * @return a list of property descriptors (element type: 
59          * {@link StructuralPropertyDescriptor})
60          * @since 3.0
61          */
62         public static List propertyDescriptors(int apiLevel) {
63                 return PROPERTY_DESCRIPTORS;
64         }
65                         
66         /**
67          * The label, or <code>null</code> if none; none by default.
68          */
69         private SimpleName optionalLabel = null;
70
71         /**
72          * Creates a new unparented continue statement node owned by the given 
73          * AST. By default, the continue statement has no label.
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         ContinueStatement(AST ast) {
81                 super(ast);
82         }
83
84         /* (omit javadoc for this method)
85          * Method declared on ASTNode.
86          */
87         final List internalStructuralPropertiesForType(int apiLevel) {
88                 return propertyDescriptors(apiLevel);
89         }
90         
91         /* (omit javadoc for this method)
92          * Method declared on ASTNode.
93          */
94         final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) {
95                 if (property == LABEL_PROPERTY) {
96                         if (get) {
97                                 return getLabel();
98                         } else {
99                                 setLabel((SimpleName) child);
100                                 return null;
101                         }
102                 }
103                 // allow default implementation to flag the error
104                 return super.internalGetSetChildProperty(property, get, child);
105         }
106         
107         /* (omit javadoc for this method)
108          * Method declared on ASTNode.
109          */
110         final int getNodeType0() {
111                 return CONTINUE_STATEMENT;
112         }
113
114         /* (omit javadoc for this method)
115          * Method declared on ASTNode.
116          */
117         ASTNode clone0(AST target) {
118                 ContinueStatement result = new ContinueStatement(target);
119                 result.setSourceRange(this.getStartPosition(), this.getLength());
120                 result.copyLeadingComment(this);
121                 result.setLabel((SimpleName) ASTNode.copySubtree(target, getLabel()));
122                 return result;
123         }
124
125         /* (omit javadoc for this method)
126          * Method declared on ASTNode.
127          */
128         final boolean subtreeMatch0(ASTMatcher matcher, Object other) {
129                 // dispatch to correct overloaded match method
130                 return matcher.match(this, other);
131         }
132
133         /* (omit javadoc for this method)
134          * Method declared on ASTNode.
135          */
136         void accept0(ASTVisitor visitor) {
137                 boolean visitChildren = visitor.visit(this);
138                 if (visitChildren) {
139                         acceptChild(visitor, getLabel());
140                 }
141                 visitor.endVisit(this);
142         }
143         
144         /**
145          * Returns the label of this continue statement, or <code>null</code> if
146          * there is none.
147          * 
148          * @return the label, or <code>null</code> if there is none
149          */ 
150         public SimpleName getLabel() {
151                 return this.optionalLabel;
152         }
153         
154         /**
155          * Sets or clears the label of this continue statement.
156          * 
157          * @param label the label, or <code>null</code> if 
158          *    there is none
159          * @exception IllegalArgumentException if:
160          * <ul>
161          * <li>the node belongs to a different AST</li>
162          * <li>the node already has a parent</li>
163          * </ul>
164          */ 
165         public void setLabel(SimpleName label) {
166                 ASTNode oldChild = this.optionalLabel;
167                 preReplaceChild(oldChild, label, LABEL_PROPERTY);
168                 this.optionalLabel = label;
169                 postReplaceChild(oldChild, label, LABEL_PROPERTY);
170         }
171         
172         /* (omit javadoc for this method)
173          * Method declared on ASTNode.
174          */
175         int memSize() {
176                 return super.memSize() + 1 * 4;
177         }
178         
179         /* (omit javadoc for this method)
180          * Method declared on ASTNode.
181          */
182         int treeSize() {
183                 return
184                         memSize()
185                         + (optionalLabel == null ? 0 : getLabel().treeSize());
186         }
187 }
188