001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.jdt.core.dom;
011:
012: import java.util.ArrayList;
013: import java.util.List;
014:
015: /**
016: * Continue statement AST node type.
017: *
018: * <pre>
019: * ContinueStatement:
020: * <b>continue</b> [ Identifier ] <b>;</b>
021: * </pre>
022: *
023: * @since 2.0
024: */
025: public class ContinueStatement extends Statement {
026:
027: /**
028: * The "label" structural property of this node type.
029: * @since 3.0
030: */
031: public static final ChildPropertyDescriptor LABEL_PROPERTY = new ChildPropertyDescriptor(
032: ContinueStatement.class,
033: "label", SimpleName.class, OPTIONAL, NO_CYCLE_RISK); //$NON-NLS-1$
034:
035: /**
036: * A list of property descriptors (element type:
037: * {@link StructuralPropertyDescriptor}),
038: * or null if uninitialized.
039: */
040: private static final List PROPERTY_DESCRIPTORS;
041:
042: static {
043: List properyList = new ArrayList(2);
044: createPropertyList(ContinueStatement.class, properyList);
045: addProperty(LABEL_PROPERTY, properyList);
046: PROPERTY_DESCRIPTORS = reapPropertyList(properyList);
047: }
048:
049: /**
050: * Returns a list of structural property descriptors for this node type.
051: * Clients must not modify the result.
052: *
053: * @param apiLevel the API level; one of the
054: * <code>AST.JLS*</code> constants
055:
056: * @return a list of property descriptors (element type:
057: * {@link StructuralPropertyDescriptor})
058: * @since 3.0
059: */
060: public static List propertyDescriptors(int apiLevel) {
061: return PROPERTY_DESCRIPTORS;
062: }
063:
064: /**
065: * The label, or <code>null</code> if none; none by default.
066: */
067: private SimpleName optionalLabel = null;
068:
069: /**
070: * Creates a new unparented continue statement node owned by the given
071: * AST. By default, the continue statement has no label.
072: * <p>
073: * N.B. This constructor is package-private.
074: * </p>
075: *
076: * @param ast the AST that is to own this node
077: */
078: ContinueStatement(AST ast) {
079: super (ast);
080: }
081:
082: /* (omit javadoc for this method)
083: * Method declared on ASTNode.
084: */
085: final List internalStructuralPropertiesForType(int apiLevel) {
086: return propertyDescriptors(apiLevel);
087: }
088:
089: /* (omit javadoc for this method)
090: * Method declared on ASTNode.
091: */
092: final ASTNode internalGetSetChildProperty(
093: ChildPropertyDescriptor property, boolean get, ASTNode child) {
094: if (property == LABEL_PROPERTY) {
095: if (get) {
096: return getLabel();
097: } else {
098: setLabel((SimpleName) child);
099: 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 CONTINUE_STATEMENT;
111: }
112:
113: /* (omit javadoc for this method)
114: * Method declared on ASTNode.
115: */
116: ASTNode clone0(AST target) {
117: ContinueStatement result = new ContinueStatement(target);
118: result
119: .setSourceRange(this .getStartPosition(), this
120: .getLength());
121: result.copyLeadingComment(this );
122: result.setLabel((SimpleName) ASTNode.copySubtree(target,
123: getLabel()));
124: return result;
125: }
126:
127: /* (omit javadoc for this method)
128: * Method declared on ASTNode.
129: */
130: final boolean subtreeMatch0(ASTMatcher matcher, Object other) {
131: // dispatch to correct overloaded match method
132: return matcher.match(this , other);
133: }
134:
135: /* (omit javadoc for this method)
136: * Method declared on ASTNode.
137: */
138: void accept0(ASTVisitor visitor) {
139: boolean visitChildren = visitor.visit(this );
140: if (visitChildren) {
141: acceptChild(visitor, getLabel());
142: }
143: visitor.endVisit(this );
144: }
145:
146: /**
147: * Returns the label of this continue statement, or <code>null</code> if
148: * there is none.
149: *
150: * @return the label, or <code>null</code> if there is none
151: */
152: public SimpleName getLabel() {
153: return this .optionalLabel;
154: }
155:
156: /**
157: * Sets or clears the label of this continue statement.
158: *
159: * @param label the label, or <code>null</code> if
160: * there is none
161: * @exception IllegalArgumentException if:
162: * <ul>
163: * <li>the node belongs to a different AST</li>
164: * <li>the node already has a parent</li>
165: * </ul>
166: */
167: public void setLabel(SimpleName label) {
168: ASTNode oldChild = this .optionalLabel;
169: preReplaceChild(oldChild, label, LABEL_PROPERTY);
170: this .optionalLabel = label;
171: postReplaceChild(oldChild, label, LABEL_PROPERTY);
172: }
173:
174: /* (omit javadoc for this method)
175: * Method declared on ASTNode.
176: */
177: int memSize() {
178: return super .memSize() + 1 * 4;
179: }
180:
181: /* (omit javadoc for this method)
182: * Method declared on ASTNode.
183: */
184: int treeSize() {
185: return memSize()
186: + (optionalLabel == null ? 0 : getLabel().treeSize());
187: }
188: }
|