KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > core > dom > ParenthesizedExpression


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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 org.eclipse.jdt.core.dom;
13
14 import java.util.ArrayList JavaDoc;
15 import java.util.List JavaDoc;
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  */

27 public class ParenthesizedExpression extends Expression {
28     
29     /**
30      * The "expression" structural property of this node type.
31      * @since 3.0
32      */

33     public static final ChildPropertyDescriptor EXPRESSION_PROPERTY =
34         new ChildPropertyDescriptor(ParenthesizedExpression.class, "expression", Expression.class, MANDATORY, CYCLE_RISK); //$NON-NLS-1$
35

36     /**
37      * A list of property descriptors (element type:
38      * {@link StructuralPropertyDescriptor}),
39      * or null if uninitialized.
40      */

41     private static final List JavaDoc PROPERTY_DESCRIPTORS;
42     
43     static {
44         List JavaDoc propertyList = new ArrayList JavaDoc(2);
45         createPropertyList(ParenthesizedExpression.class, propertyList);
46         addProperty(EXPRESSION_PROPERTY, propertyList);
47         PROPERTY_DESCRIPTORS = reapPropertyList(propertyList);
48     }
49
50     /**
51      * Returns a list of structural property descriptors for this node type.
52      * Clients must not modify the result.
53      *
54      * @param apiLevel the API level; one of the
55      * <code>AST.JLS*</code> constants
56      * @return a list of property descriptors (element type:
57      * {@link StructuralPropertyDescriptor})
58      * @since 3.0
59      */

60     public static List JavaDoc propertyDescriptors(int apiLevel) {
61         return PROPERTY_DESCRIPTORS;
62     }
63             
64     /**
65      * The expression; lazily initialized; defaults to a unspecified, but legal,
66      * expression.
67      */

68     private Expression expression = null;
69
70     /**
71      * Creates a new unparented parenthesized expression node owned by the given
72      * AST. By default, the parenthesized expression has an unspecified, but
73      * legal, expression.
74      * <p>
75      * N.B. This constructor is package-private.
76      * </p>
77      *
78      * @param ast the AST that is to own this node
79      */

80     ParenthesizedExpression(AST ast) {
81         super(ast);
82     }
83
84     /* (omit javadoc for this method)
85      * Method declared on ASTNode.
86      */

87     final List JavaDoc internalStructuralPropertiesForType(int apiLevel) {
88         return propertyDescriptors(apiLevel);
89     }
90     
91     /* (omit javadoc for this method)
92      * Method declared on ASTNode.
93      */

94     final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) {
95         if (property == EXPRESSION_PROPERTY) {
96             if (get) {
97                 return getExpression();
98             } else {
99                 setExpression((Expression) child);
100                 return null;
101             }
102         }
103         // allow default implementation to flag the error
104
return super.internalGetSetChildProperty(property, get, child);
105     }
106     
107     /* (omit javadoc for this method)
108      * Method declared on ASTNode.
109      */

110     final int getNodeType0() {
111         return PARENTHESIZED_EXPRESSION;
112     }
113
114     /* (omit javadoc for this method)
115      * Method declared on ASTNode.
116      */

117     ASTNode clone0(AST target) {
118         ParenthesizedExpression result = new ParenthesizedExpression(target);
119         result.setSourceRange(this.getStartPosition(), this.getLength());
120         result.setExpression((Expression) getExpression().clone(target));
121         return result;
122     }
123     
124     /* (omit javadoc for this method)
125      * Method declared on ASTNode.
126      */

127     final boolean subtreeMatch0(ASTMatcher matcher, Object JavaDoc other) {
128         // dispatch to correct overloaded match method
129
return matcher.match(this, other);
130     }
131
132     /* (omit javadoc for this method)
133      * Method declared on ASTNode.
134      */

135     void accept0(ASTVisitor visitor) {
136         boolean visitChildren = visitor.visit(this);
137         if (visitChildren) {
138             acceptChild(visitor, getExpression());
139         }
140         visitor.endVisit(this);
141     }
142     
143     /**
144      * Returns the expression of this parenthesized expression.
145      *
146      * @return the expression node
147      */

148     public Expression getExpression() {
149         if (this.expression == null) {
150             // lazy init must be thread-safe for readers
151
synchronized (this) {
152                 if (this.expression == null) {
153                     preLazyInit();
154                     this.expression = new SimpleName(this.ast);
155                     postLazyInit(this.expression, EXPRESSION_PROPERTY);
156                 }
157             }
158         }
159         return this.expression;
160     }
161         
162     /**
163      * Sets the expression of this parenthesized expression.
164      *
165      * @param expression the new expression node
166      * @exception IllegalArgumentException if:
167      * <ul>
168      * <li>the node belongs to a different AST</li>
169      * <li>the node already has a parent</li>
170      * <li>a cycle in would be created</li>
171      * </ul>
172      */

173     public void setExpression(Expression expression) {
174         if (expression == null) {
175             throw new IllegalArgumentException JavaDoc();
176         }
177         ASTNode oldChild = this.expression;
178         preReplaceChild(oldChild, expression, EXPRESSION_PROPERTY);
179         this.expression = expression;
180         postReplaceChild(oldChild, expression, EXPRESSION_PROPERTY);
181     }
182
183     /* (omit javadoc for this method)
184      * Method declared on ASTNode.
185      */

186     int memSize() {
187         return BASE_NODE_SIZE + 1 * 4;
188     }
189     
190     /* (omit javadoc for this method)
191      * Method declared on ASTNode.
192      */

193     int treeSize() {
194         return
195             memSize()
196             + (this.expression == null ? 0 : getExpression().treeSize());
197     }
198 }
199
200
Popular Tags