removed unused private methods.
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / core / dom / ParenthesizedExpression.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  * Parenthesized expression AST node type.
19  *
20  * <pre>
21  * ParenthesizedExpression:
22  *     <b>(</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 ParenthesizedExpression extends Expression {
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(ParenthesizedExpression.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(ParenthesizedExpression.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          * @return a list of property descriptors (element type: 
58          * {@link StructuralPropertyDescriptor})
59          * @since 3.0
60          */
61         public static List propertyDescriptors(int apiLevel) {
62                 return PROPERTY_DESCRIPTORS;
63         }
64                         
65         /**
66          * The expression; lazily initialized; defaults to a unspecified, but legal,
67          * expression.
68          */
69         private Expression expression = null;
70
71         /**
72          * Creates a new unparented parenthesized expression node owned by the given 
73          * AST. By default, the parenthesized expression has an unspecified, but
74          * legal, expression.
75          * <p>
76          * N.B. This constructor is package-private.
77          * </p>
78          * 
79          * @param ast the AST that is to own this node
80          */
81         ParenthesizedExpression(AST ast) {
82                 super(ast);
83         }
84
85         /* (omit javadoc for this method)
86          * Method declared on ASTNode.
87          */
88         final List internalStructuralPropertiesForType(int apiLevel) {
89                 return propertyDescriptors(apiLevel);
90         }
91         
92         /* (omit javadoc for this method)
93          * Method declared on ASTNode.
94          */
95         final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) {
96                 if (property == EXPRESSION_PROPERTY) {
97                         if (get) {
98                                 return getExpression();
99                         } else {
100                                 setExpression((Expression) child);
101                                 return null;
102                         }
103                 }
104                 // allow default implementation to flag the error
105                 return super.internalGetSetChildProperty(property, get, child);
106         }
107         
108         /* (omit javadoc for this method)
109          * Method declared on ASTNode.
110          */
111         final int getNodeType0() {
112                 return PARENTHESIZED_EXPRESSION;
113         }
114
115         /* (omit javadoc for this method)
116          * Method declared on ASTNode.
117          */
118         ASTNode clone0(AST target) {
119                 ParenthesizedExpression result = new ParenthesizedExpression(target);
120                 result.setSourceRange(this.getStartPosition(), this.getLength());
121                 result.setExpression((Expression) getExpression().clone(target));
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, getExpression());
140                 }
141                 visitor.endVisit(this);
142         }
143         
144         /**
145          * Returns the expression of this parenthesized expression.
146          * 
147          * @return the expression node
148          */ 
149         public Expression getExpression() {
150                 if (this.expression == null) {
151                         // lazy init must be thread-safe for readers
152                         synchronized (this) {
153                                 if (this.expression == null) {
154                                         preLazyInit();
155                                         this.expression = new SimpleName(this.ast);
156                                         postLazyInit(this.expression, EXPRESSION_PROPERTY);
157                                 }
158                         }
159                 }
160                 return this.expression;
161         }
162                 
163         /**
164          * Sets the expression of this parenthesized expression.
165          * 
166          * @param expression the new expression node
167          * @exception IllegalArgumentException if:
168          * <ul>
169          * <li>the node belongs to a different AST</li>
170          * <li>the node already has a parent</li>
171          * <li>a cycle in would be created</li>
172          * </ul>
173          */ 
174         public void setExpression(Expression expression) {
175                 if (expression == null) {
176                         throw new IllegalArgumentException();
177                 }
178                 ASTNode oldChild = this.expression;
179                 preReplaceChild(oldChild, expression, EXPRESSION_PROPERTY);
180                 this.expression = expression;
181                 postReplaceChild(oldChild, expression, EXPRESSION_PROPERTY);
182         }
183
184         /* (omit javadoc for this method)
185          * Method declared on ASTNode.
186          */
187         int memSize() {
188                 return BASE_NODE_SIZE + 1 * 4;
189         }
190         
191         /* (omit javadoc for this method)
192          * Method declared on ASTNode.
193          */
194         int treeSize() {
195                 return 
196                         memSize()
197                         + (this.expression == null ? 0 : getExpression().treeSize());
198         }
199 }
200