removed unused private methods.
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / core / dom / ThrowStatement.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  * Throw statement AST node type.
19  *
20  * <pre>
21  * ThrowStatement:
22  *    <b>throw</b> Expression <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 ThrowStatement extends Statement {
29                         
30         /**
31          * The "expression" structural property of this node type.
32          * @since 3.0
33          */
34         public static final ChildPropertyDescriptor EXPRESSION_PROPERTY = 
35                 new ChildPropertyDescriptor(ThrowStatement.class, "expression", Expression.class, MANDATORY, 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 propertyList = new ArrayList(2);
46                 createPropertyList(ThrowStatement.class, propertyList);
47                 addProperty(EXPRESSION_PROPERTY, propertyList);
48                 PROPERTY_DESCRIPTORS = reapPropertyList(propertyList);
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 expression; lazily initialized; defaults to a unspecified, but legal,
68          * expression.
69          */
70         private Expression expression = null;
71
72         /**
73          * Creates a new unparented throw statement node owned by the given 
74          * AST. By default, the throw statement has an unspecified, but legal,
75          * expression.
76          * <p>
77          * N.B. This constructor is package-private.
78          * </p>
79          * 
80          * @param ast the AST that is to own this node
81          */
82         ThrowStatement(AST ast) {
83                 super(ast);
84         }
85
86         /* (omit javadoc for this method)
87          * Method declared on ASTNode.
88          */
89         final List internalStructuralPropertiesForType(int apiLevel) {
90                 return propertyDescriptors(apiLevel);
91         }
92         
93         /* (omit javadoc for this method)
94          * Method declared on ASTNode.
95          */
96         final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) {
97                 if (property == EXPRESSION_PROPERTY) {
98                         if (get) {
99                                 return getExpression();
100                         } else {
101                                 setExpression((Expression) child);
102                                 return null;
103                         }
104                 }
105                 // allow default implementation to flag the error
106                 return super.internalGetSetChildProperty(property, get, child);
107         }
108         
109         /* (omit javadoc for this method)
110          * Method declared on ASTNode.
111          */
112         final int getNodeType0() {
113                 return THROW_STATEMENT;
114         }
115
116         /* (omit javadoc for this method)
117          * Method declared on ASTNode.
118          */
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));
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, getExpression());
142                 }
143                 visitor.endVisit(this);
144         }
145         
146         /**
147          * Returns the expression of this throw statement.
148          * 
149          * @return the expression node
150          */ 
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) {
156                                         preLazyInit();
157                                         this.expression = new SimpleName(this.ast);
158                                         postLazyInit(this.expression, EXPRESSION_PROPERTY);
159                                 }
160                         }
161                 }
162                 return this.expression;
163         }
164                 
165         /**
166          * Sets the expression of this throw statement.
167          * 
168          * @param expression the new expression node
169          * @exception IllegalArgumentException if:
170          * <ul>
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>
174          * </ul>
175          */ 
176         public void setExpression(Expression expression) {
177                 if (expression == null) {
178                         throw new IllegalArgumentException();
179                 }
180                 ASTNode oldChild = this.expression;
181                 preReplaceChild(oldChild, expression, EXPRESSION_PROPERTY);
182                 this.expression = expression;
183                 postReplaceChild(oldChild, expression, EXPRESSION_PROPERTY);
184         }
185         
186         /* (omit javadoc for this method)
187          * Method declared on ASTNode.
188          */
189         int memSize() {
190                 return super.memSize() + 1 * 4;
191         }
192         
193         /* (omit javadoc for this method)
194          * Method declared on ASTNode.
195          */
196         int treeSize() {
197                 return
198                         memSize()
199                         + (this.expression == null ? 0 : getExpression().treeSize());
200         }
201 }