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 * Throw statement AST node type.
22 * <b>throw</b> Expression <b>;</b>
26 * @noinstantiate This class is not intended to be instantiated by clients.
28 public class ThrowStatement extends Statement {
31 * The "expression" structural property of this node type.
34 public static final ChildPropertyDescriptor EXPRESSION_PROPERTY =
35 new ChildPropertyDescriptor(ThrowStatement.class, "expression", Expression.class, MANDATORY, 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 propertyList = new ArrayList(2);
46 createPropertyList(ThrowStatement.class, propertyList);
47 addProperty(EXPRESSION_PROPERTY, propertyList);
48 PROPERTY_DESCRIPTORS = reapPropertyList(propertyList);
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 expression; lazily initialized; defaults to a unspecified, but legal,
70 private Expression expression = null;
73 * Creates a new unparented throw statement node owned by the given
74 * AST. By default, the throw statement has an unspecified, but legal,
77 * N.B. This constructor is package-private.
80 * @param ast the AST that is to own this node
82 ThrowStatement(AST ast) {
86 /* (omit javadoc for this method)
87 * Method declared on ASTNode.
89 final List internalStructuralPropertiesForType(int apiLevel) {
90 return propertyDescriptors(apiLevel);
93 /* (omit javadoc for this method)
94 * Method declared on ASTNode.
96 final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) {
97 if (property == EXPRESSION_PROPERTY) {
99 return getExpression();
101 setExpression((Expression) child);
105 // allow default implementation to flag the error
106 return super.internalGetSetChildProperty(property, get, child);
109 /* (omit javadoc for this method)
110 * Method declared on ASTNode.
112 final int getNodeType0() {
113 return THROW_STATEMENT;
116 /* (omit javadoc for this method)
117 * Method declared on ASTNode.
119 ASTNode clone0(AST target) {
120 ThrowStatement result = new ThrowStatement(target);
121 result.setSourceRange(this.getStartPosition(), this.getLength());
122 result.copyLeadingComment(this);
123 result.setExpression((Expression) getExpression().clone(target));
127 /* (omit javadoc for this method)
128 * Method declared on ASTNode.
130 final boolean subtreeMatch0(ASTMatcher matcher, Object other) {
131 // dispatch to correct overloaded match method
132 return matcher.match(this, other);
135 /* (omit javadoc for this method)
136 * Method declared on ASTNode.
138 void accept0(ASTVisitor visitor) {
139 boolean visitChildren = visitor.visit(this);
141 acceptChild(visitor, getExpression());
143 visitor.endVisit(this);
147 * Returns the expression of this throw statement.
149 * @return the expression node
151 public Expression getExpression() {
152 if (this.expression == null) {
153 // lazy init must be thread-safe for readers
154 synchronized (this) {
155 if (this.expression == null) {
157 this.expression = new SimpleName(this.ast);
158 postLazyInit(this.expression, EXPRESSION_PROPERTY);
162 return this.expression;
166 * Sets the expression of this throw statement.
168 * @param expression the new expression node
169 * @exception IllegalArgumentException if:
171 * <li>the node belongs to a different AST</li>
172 * <li>the node already has a parent</li>
173 * <li>a cycle in would be created</li>
176 public void setExpression(Expression expression) {
177 if (expression == null) {
178 throw new IllegalArgumentException();
180 ASTNode oldChild = this.expression;
181 preReplaceChild(oldChild, expression, EXPRESSION_PROPERTY);
182 this.expression = expression;
183 postReplaceChild(oldChild, expression, EXPRESSION_PROPERTY);
186 /* (omit javadoc for this method)
187 * Method declared on ASTNode.
190 return super.memSize() + 1 * 4;
193 /* (omit javadoc for this method)
194 * Method declared on ASTNode.
199 + (this.expression == null ? 0 : getExpression().treeSize());