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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
12 package net.sourceforge.phpdt.core.dom;
14 import java.util.ArrayList;
15 import java.util.List;
18 * Break statement AST node type.
22 * <b>break</b> [ Identifier ] <b>;</b>
26 * @noinstantiate This class is not intended to be instantiated by clients.
28 public class BreakStatement extends Statement {
31 * The "label" structural property of this node type.
34 public static final ChildPropertyDescriptor LABEL_PROPERTY =
35 new ChildPropertyDescriptor(BreakStatement.class, "label", SimpleName.class, OPTIONAL, NO_CYCLE_RISK); //$NON-NLS-1$
38 * A list of property descriptors (element type:
39 * {@link StructuralPropertyDescriptor}),
40 * or null if uninitialized.
42 private static final List PROPERTY_DESCRIPTORS;
45 List properyList = new ArrayList(2);
46 createPropertyList(BreakStatement.class, properyList);
47 addProperty(LABEL_PROPERTY, properyList);
48 PROPERTY_DESCRIPTORS = reapPropertyList(properyList);
52 * Returns a list of structural property descriptors for this node type.
53 * Clients must not modify the result.
55 * @param apiLevel the API level; one of the
56 * <code>AST.JLS*</code> constants
58 * @return a list of property descriptors (element type:
59 * {@link StructuralPropertyDescriptor})
62 public static List propertyDescriptors(int apiLevel) {
63 return PROPERTY_DESCRIPTORS;
67 * The label, or <code>null</code> if none; none by default.
69 private SimpleName optionalLabel = null;
72 * Creates a new unparented break statement node owned by the given
73 * AST. By default, the break statement has no label.
75 * N.B. This constructor is package-private.
78 * @param ast the AST that is to own this node
80 BreakStatement(AST ast) {
84 /* (omit javadoc for this method)
85 * Method declared on ASTNode.
87 final List internalStructuralPropertiesForType(int apiLevel) {
88 return propertyDescriptors(apiLevel);
91 /* (omit javadoc for this method)
92 * Method declared on ASTNode.
94 final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) {
95 if (property == LABEL_PROPERTY) {
99 setLabel((SimpleName) child);
103 // allow default implementation to flag the error
104 return super.internalGetSetChildProperty(property, get, child);
107 /* (omit javadoc for this method)
108 * Method declared on ASTNode.
110 final int getNodeType0() {
111 return BREAK_STATEMENT;
114 /* (omit javadoc for this method)
115 * Method declared on ASTNode.
117 ASTNode clone0(AST target) {
118 BreakStatement result = new BreakStatement(target);
119 result.setSourceRange(this.getStartPosition(), this.getLength());
120 result.copyLeadingComment(this);
121 result.setLabel((SimpleName) ASTNode.copySubtree(target, getLabel()));
125 /* (omit javadoc for this method)
126 * Method declared on ASTNode.
128 final boolean subtreeMatch0(ASTMatcher matcher, Object other) {
129 // dispatch to correct overloaded match method
130 return matcher.match(this, other);
133 /* (omit javadoc for this method)
134 * Method declared on ASTNode.
136 void accept0(ASTVisitor visitor) {
137 boolean visitChildren = visitor.visit(this);
139 acceptChild(visitor, getLabel());
141 visitor.endVisit(this);
145 * Returns the label of this break statement, or <code>null</code> if
148 * @return the label, or <code>null</code> if there is none
150 public SimpleName getLabel() {
151 return this.optionalLabel;
155 * Sets or clears the label of this break statement.
157 * @param label the label, or <code>null</code> if
159 * @exception IllegalArgumentException if:
161 * <li>the node belongs to a different AST</li>
162 * <li>the node already has a parent</li>
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);
172 /* (omit javadoc for this method)
173 * Method declared on ASTNode.
176 return super.memSize() + 1 * 4;
179 /* (omit javadoc for this method)
180 * Method declared on ASTNode.
185 + (this.optionalLabel == null ? 0 : getLabel().treeSize());