removed unused private methods.
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / core / dom / InstanceofExpression.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  * Instanceof expression AST node type.
19  * <pre>
20  * InstanceofExpression:
21  *    Expression <b>instanceof</b> Type
22  * </pre>
23  * 
24  * @since 2.0
25  * @noinstantiate This class is not intended to be instantiated by clients.
26  */
27 public class InstanceofExpression extends Expression {
28
29         /**
30          * The "leftOperand" structural property of this node type.
31          * @since 3.0
32          */
33         public static final ChildPropertyDescriptor LEFT_OPERAND_PROPERTY = 
34                 new ChildPropertyDescriptor(InstanceofExpression.class, "leftOperand", Expression.class, MANDATORY, CYCLE_RISK); //$NON-NLS-1$
35
36         /**
37          * The "rightOperand" structural property of this node type.
38          * @since 3.0
39          */
40         public static final ChildPropertyDescriptor RIGHT_OPERAND_PROPERTY = 
41                 new ChildPropertyDescriptor(InstanceofExpression.class, "rightOperand", Type.class, MANDATORY, CYCLE_RISK); //$NON-NLS-1$
42
43         /**
44          * A list of property descriptors (element type: 
45          * {@link StructuralPropertyDescriptor}),
46          * or null if uninitialized.
47          */
48         private static final List PROPERTY_DESCRIPTORS;
49         
50         static {
51                 List properyList = new ArrayList(3);
52                 createPropertyList(InstanceofExpression.class, properyList);
53                 addProperty(LEFT_OPERAND_PROPERTY, properyList);
54                 addProperty(RIGHT_OPERAND_PROPERTY, properyList);
55                 PROPERTY_DESCRIPTORS = reapPropertyList(properyList);
56         }
57
58         /**
59          * Returns a list of structural property descriptors for this node type.
60          * Clients must not modify the result.
61          * 
62          * @param apiLevel the API level; one of the
63          * <code>AST.JLS*</code> constants
64
65          * @return a list of property descriptors (element type: 
66          * {@link StructuralPropertyDescriptor})
67          * @since 3.0
68          */
69         public static List propertyDescriptors(int apiLevel) {
70                 return PROPERTY_DESCRIPTORS;
71         }
72                         
73         /**
74          * The left operand; lazily initialized; defaults to an unspecified,
75          * but legal, simple name.
76          */
77         private Expression leftOperand = null;
78
79         /**
80          * The right operand; lazily initialized; defaults to an unspecified,
81          * but legal, simple type.
82          */
83         private Type rightOperand = null;
84
85         /**
86          * Creates a new AST node for an instanceof expression owned by the given 
87          * AST. By default, the node has unspecified (but legal) operator,
88          * left and right operands.
89          * 
90          * @param ast the AST that is to own this node
91          */
92         InstanceofExpression(AST ast) {
93                 super(ast);
94         }
95
96         /* (omit javadoc for this method)
97          * Method declared on ASTNode.
98          */
99         final List internalStructuralPropertiesForType(int apiLevel) {
100                 return propertyDescriptors(apiLevel);
101         }
102         
103         /* (omit javadoc for this method)
104          * Method declared on ASTNode.
105          */
106         final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) {
107                 if (property == LEFT_OPERAND_PROPERTY) {
108                         if (get) {
109                                 return getLeftOperand();
110                         } else {
111                                 setLeftOperand((Expression) child);
112                                 return null;
113                         }
114                 }
115                 if (property == RIGHT_OPERAND_PROPERTY) {
116                         if (get) {
117                                 return getRightOperand();
118                         } else {
119                                 setRightOperand((Type) child);
120                                 return null;
121                         }
122                 }
123                 // allow default implementation to flag the error
124                 return super.internalGetSetChildProperty(property, get, child);
125         }
126         
127         /* (omit javadoc for this method)
128          * Method declared on ASTNode.
129          */
130         final int getNodeType0() {
131                 return INSTANCEOF_EXPRESSION;
132         }
133
134         /* (omit javadoc for this method)
135          * Method declared on ASTNode.
136          */
137         ASTNode clone0(AST target) {
138                 InstanceofExpression result = new InstanceofExpression(target);
139                 result.setSourceRange(this.getStartPosition(), this.getLength());
140                 result.setLeftOperand((Expression) getLeftOperand().clone(target));
141                 result.setRightOperand((Type) getRightOperand().clone(target));
142                 return result;
143         }
144
145         /* (omit javadoc for this method)
146          * Method declared on ASTNode.
147          */
148         final boolean subtreeMatch0(ASTMatcher matcher, Object other) {
149                 // dispatch to correct overloaded match method
150                 return matcher.match(this, other);
151         }
152
153         /* (omit javadoc for this method)
154          * Method declared on ASTNode.
155          */
156         void accept0(ASTVisitor visitor) {
157                 boolean visitChildren = visitor.visit(this);
158                 if (visitChildren) {
159                         // visit children in normal left to right reading order
160                         acceptChild(visitor, getLeftOperand());
161                         acceptChild(visitor, getRightOperand());
162                 }
163                 visitor.endVisit(this);
164         }
165         
166         /**
167          * Returns the left operand of this instanceof expression.
168          * 
169          * @return the left operand node
170          */ 
171         public Expression getLeftOperand() {
172                 if (this.leftOperand  == null) {
173                         // lazy init must be thread-safe for readers
174                         synchronized (this) {
175                                 if (this.leftOperand == null) {
176                                         preLazyInit();
177                                         this.leftOperand= new SimpleName(this.ast);
178                                         postLazyInit(this.leftOperand, LEFT_OPERAND_PROPERTY);
179                                 }
180                         }
181                 }
182                 return this.leftOperand;
183         }
184                 
185         /**
186          * Sets the left operand of this instanceof expression.
187          * 
188          * @param expression the left operand node
189          * @exception IllegalArgumentException if:
190          * <ul>
191          * <li>the node belongs to a different AST</li>
192          * <li>the node already has a parent</li>
193          * <li>a cycle in would be created</li>
194          * </ul>
195          */ 
196         public void setLeftOperand(Expression expression) {
197                 if (expression == null) {
198                         throw new IllegalArgumentException();
199                 }
200                 ASTNode oldChild = this.leftOperand;
201                 preReplaceChild(oldChild, expression, LEFT_OPERAND_PROPERTY);
202                 this.leftOperand = expression;
203                 postReplaceChild(oldChild, expression, LEFT_OPERAND_PROPERTY);
204         }
205
206         /**
207          * Returns the right operand of this instanceof expression.
208          * 
209          * @return the right operand node
210          */ 
211         public Type getRightOperand() {
212                 if (this.rightOperand  == null) {
213                         // lazy init must be thread-safe for readers
214                         synchronized (this) {
215                                 if (this.rightOperand == null) {
216                                         preLazyInit();
217                                         this.rightOperand= new SimpleType(this.ast);
218                                         postLazyInit(this.rightOperand, RIGHT_OPERAND_PROPERTY);
219                                 }
220                         }
221                 }
222                 return this.rightOperand;
223         }
224                 
225         /**
226          * Sets the right operand of this instanceof expression.
227          * 
228          * @param referenceType the right operand node
229          * @exception IllegalArgumentException if:
230          * <ul>
231          * <li>the node belongs to a different AST</li>
232          * <li>the node already has a parent</li>
233          * <li>a cycle in would be created</li>
234          * </ul>
235          */ 
236         public void setRightOperand(Type referenceType) {
237                 if (referenceType == null) {
238                         throw new IllegalArgumentException();
239                 }
240                 ASTNode oldChild = this.rightOperand;
241                 preReplaceChild(oldChild, referenceType, RIGHT_OPERAND_PROPERTY);
242                 this.rightOperand = referenceType;
243                 postReplaceChild(oldChild, referenceType, RIGHT_OPERAND_PROPERTY);
244         }
245         
246         /* (omit javadoc for this method)
247          * Method declared on ASTNode.
248          */
249         int memSize() {
250                 // treat Operator as free
251                 return BASE_NODE_SIZE + 2 * 4;
252         }
253         
254         /* (omit javadoc for this method)
255          * Method declared on ASTNode.
256          */
257         int treeSize() {
258                 return 
259                         memSize()
260                         + (this.leftOperand == null ? 0 : getLeftOperand().treeSize())
261                         + (this.rightOperand == null ? 0 : getRightOperand().treeSize());
262         }
263 }