removed unused private methods.
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / core / dom / Initializer.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  * Static or instance initializer AST node type.
19  * <pre>
20  * Initializer:
21  *     [ <b>static</b> ] Block
22  * </pre>
23  * 
24  * @since 2.0
25  * @noinstantiate This class is not intended to be instantiated by clients.
26  */
27 public class Initializer extends BodyDeclaration {
28         
29         /**
30          * The "javadoc" structural property of this node type.
31          * @since 3.0
32          */
33         public static final ChildPropertyDescriptor JAVADOC_PROPERTY = 
34                 internalJavadocPropertyFactory(Initializer.class);
35
36         /**
37          * The "modifiers" structural property of this node type (JLS2 API only).
38          * @since 3.0
39          */
40         public static final SimplePropertyDescriptor MODIFIERS_PROPERTY = 
41                 internalModifiersPropertyFactory(Initializer.class);
42         
43         /**
44          * The "modifiers" structural property of this node type (added in JLS3 API).
45          * @since 3.1
46          */
47         public static final ChildListPropertyDescriptor MODIFIERS2_PROPERTY = 
48                 internalModifiers2PropertyFactory(Initializer.class);
49         
50         /**
51          * The "body" structural property of this node type.
52          * @since 3.0
53          */
54         public static final ChildPropertyDescriptor BODY_PROPERTY = 
55                 new ChildPropertyDescriptor(Initializer.class, "body", Block.class, MANDATORY, CYCLE_RISK); //$NON-NLS-1$
56
57         /**
58          * A list of property descriptors (element type: 
59          * {@link StructuralPropertyDescriptor}),
60          * or null if uninitialized.
61          * @since 3.0
62          */
63         private static final List PROPERTY_DESCRIPTORS_2_0;
64         
65         /**
66          * A list of property descriptors (element type: 
67          * {@link StructuralPropertyDescriptor}),
68          * or null if uninitialized.
69          * @since 3.1
70          */
71         private static final List PROPERTY_DESCRIPTORS_3_0;
72         
73         static {
74                 List properyList = new ArrayList(4);
75                 createPropertyList(Initializer.class, properyList);
76                 addProperty(JAVADOC_PROPERTY, properyList);
77                 addProperty(MODIFIERS_PROPERTY, properyList);
78                 addProperty(BODY_PROPERTY, properyList);
79                 PROPERTY_DESCRIPTORS_2_0 = reapPropertyList(properyList);
80                 
81                 properyList = new ArrayList(4);
82                 createPropertyList(Initializer.class, properyList);
83                 addProperty(JAVADOC_PROPERTY, properyList);
84                 addProperty(MODIFIERS2_PROPERTY, properyList);
85                 addProperty(BODY_PROPERTY, properyList);
86                 PROPERTY_DESCRIPTORS_3_0 = reapPropertyList(properyList);
87         }
88
89         /**
90          * Returns a list of structural property descriptors for this node type.
91          * Clients must not modify the result.
92          * 
93          * @param apiLevel the API level; one of the
94          * <code>AST.JLS*</code> constants
95
96          * @return a list of property descriptors (element type: 
97          * {@link StructuralPropertyDescriptor})
98          * @since 3.0
99          */
100         public static List propertyDescriptors(int apiLevel) {
101                 if (apiLevel == AST.JLS2_INTERNAL) {
102                         return PROPERTY_DESCRIPTORS_2_0;
103                 } else {
104                         return PROPERTY_DESCRIPTORS_3_0;
105                 }
106         }
107                         
108         /**
109          * The initializer body; lazily initialized; defaults to an empty block.
110          */
111         private Block body = null;
112
113         /**
114          * Creates a new AST node for an initializer declaration owned by the given 
115          * AST. By default, the initializer has no modifiers and an empty block.
116          * The javadoc comment is not used for initializers.
117          * <p>
118          * N.B. This constructor is package-private.
119          * </p>
120          * 
121          * @param ast the AST that is to own this node
122          */
123         Initializer(AST ast) {
124                 super(ast);
125         }
126
127         /* (omit javadoc for this method)
128          * Method declared on ASTNode.
129          * @since 3.0
130          */
131         final List internalStructuralPropertiesForType(int apiLevel) {
132                 return propertyDescriptors(apiLevel);
133         }
134         
135         /* (omit javadoc for this method)
136          * Method declared on ASTNode.
137          */
138         final int internalGetSetIntProperty(SimplePropertyDescriptor property, boolean get, int value) {
139                 if (property == MODIFIERS_PROPERTY) {
140                         if (get) {
141                                 return getModifiers();
142                         } else {
143                                 internalSetModifiers(value);
144                                 return 0;
145                         }
146                 }
147                 // allow default implementation to flag the error
148                 return super.internalGetSetIntProperty(property, get, value);
149         }
150
151         /* (omit javadoc for this method)
152          * Method declared on ASTNode.
153          */
154         final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) {
155                 if (property == JAVADOC_PROPERTY) {
156                         if (get) {
157                                 return getJavadoc();
158                         } else {
159                                 setJavadoc((Javadoc) child);
160                                 return null;
161                         }
162                 }
163                 if (property == BODY_PROPERTY) {
164                         if (get) {
165                                 return getBody();
166                         } else {
167                                 setBody((Block) child);
168                                 return null;
169                         }
170                 }
171                 // allow default implementation to flag the error
172                 return super.internalGetSetChildProperty(property, get, child);
173         }
174         
175         /* (omit javadoc for this method)
176          * Method declared on ASTNode.
177          */
178         final List internalGetChildListProperty(ChildListPropertyDescriptor property) {
179                 if (property == MODIFIERS2_PROPERTY) {
180                         return modifiers();
181                 }
182                 // allow default implementation to flag the error
183                 return super.internalGetChildListProperty(property);
184         }
185         
186         /* (omit javadoc for this method)
187          * Method declared on BodyDeclaration.
188          */
189         final ChildPropertyDescriptor internalJavadocProperty() {
190                 return JAVADOC_PROPERTY;
191         }
192
193         /* (omit javadoc for this method)
194          * Method declared on BodyDeclaration.
195          */
196         final ChildListPropertyDescriptor internalModifiers2Property() {
197                 return MODIFIERS2_PROPERTY;
198         }
199
200         /* (omit javadoc for this method)
201          * Method declared on BodyDeclaration.
202          */
203         final SimplePropertyDescriptor internalModifiersProperty() {
204                 return MODIFIERS_PROPERTY;
205         }
206
207         /* (omit javadoc for this method)
208          * Method declared on ASTNode.
209          */
210         final int getNodeType0() {
211                 return INITIALIZER;
212         }
213
214         /* (omit javadoc for this method)
215          * Method declared on ASTNode.
216          */
217         ASTNode clone0(AST target) {
218                 Initializer result = new Initializer(target);
219                 result.setSourceRange(this.getStartPosition(), this.getLength());
220                 if (this.ast.apiLevel == AST.JLS2_INTERNAL) {
221                         result.internalSetModifiers(getModifiers());
222                 }
223                 if (this.ast.apiLevel >= AST.JLS3) {
224                         result.modifiers().addAll(ASTNode.copySubtrees(target, modifiers()));
225                 }
226                 result.setJavadoc(
227                         (Javadoc) ASTNode.copySubtree(target, getJavadoc()));
228                 result.setBody((Block) getBody().clone(target));
229                 return result;
230         }
231
232         /* (omit javadoc for this method)
233          * Method declared on ASTNode.
234          */
235         final boolean subtreeMatch0(ASTMatcher matcher, Object other) {
236                 // dispatch to correct overloaded match method
237                 return matcher.match(this, other);
238         }
239
240         /* (omit javadoc for this method)
241          * Method declared on ASTNode.
242          */
243         void accept0(ASTVisitor visitor) {
244                 boolean visitChildren = visitor.visit(this);
245                 if (visitChildren) {
246                         acceptChild(visitor, getJavadoc());
247                         if (this.ast.apiLevel >= AST.JLS3) {
248                                 acceptChildren(visitor, this.modifiers);
249                         }
250                         acceptChild(visitor, getBody());
251                 }
252                 visitor.endVisit(this);
253         }
254         
255         /**
256          * Returns the body of this initializer declaration.
257          * 
258          * @return the initializer body
259          */ 
260         public Block getBody() {
261                 if (this.body == null) {
262                         // lazy init must be thread-safe for readers
263                         synchronized (this) {
264                                 if (this.body == null) {
265                                         preLazyInit();
266                                         this.body= new Block(this.ast);
267                                         postLazyInit(this.body, BODY_PROPERTY);
268                                 }
269                         }
270                 }
271                 return this.body;
272         }
273         
274         /**
275          * Sets the body of this initializer declaration.
276          * 
277          * @param body the block node
278          * @exception IllegalArgumentException if:
279          * <ul>
280          * <li>the node belongs to a different AST</li>
281          * <li>the node already has a parent</li>
282          * <li>a cycle in would be created</li>
283          * </ul>
284          */ 
285         public void setBody(Block body) {
286                 if (body == null) {
287                         throw new IllegalArgumentException();
288                 }
289                 ASTNode oldChild = this.body;
290                 preReplaceChild(oldChild, body, BODY_PROPERTY);
291                 this.body = body;
292                 postReplaceChild(oldChild, body, BODY_PROPERTY);
293         }
294         
295         /* (omit javadoc for this method)
296          * Method declared on ASTNode.
297          */
298         int memSize() {
299                 return super.memSize() + 1 * 4;
300         }
301         
302         /* (omit javadoc for this method)
303          * Method declared on ASTNode.
304          */
305         int treeSize() {
306                 return
307                         memSize()
308                         + (this.optionalDocComment == null ? 0 : getJavadoc().treeSize())
309                         + (this.modifiers == null ? 0 : this.modifiers.listSize())
310                         + (this.body == null ? 0 : getBody().treeSize());
311         }
312 }
313