removed unused private methods.
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / core / dom / EnumDeclaration.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 package net.sourceforge.phpdt.core.dom;
12
13 import java.util.ArrayList;
14 import java.util.List;
15
16 /**
17  * Enum declaration AST node type (added in JLS3 API).
18  *
19  * <pre>
20  * EnumDeclaration:
21  *     [ Javadoc ] { ExtendedModifier } <b>enum</b> Identifier
22  *         [ <b>implements</b> Type { <b>,</b> Type } ]
23  *         <b>{</b>
24  *         [ EnumConstantDeclaration { <b>,</b> EnumConstantDeclaration } ] [ <b>,</b> ]
25  *         [ <b>;</b> { ClassBodyDeclaration | <b>;</b> } ]
26  *         <b>}</b>
27  * </pre>
28  * The {@link #enumConstants()} list holds the enum constant declarations,
29  * while the {@link #bodyDeclarations()} list holds the class body declarations
30  * that appear after the semicolon.
31  * <p>
32  * When a Javadoc comment is present, the source
33  * range begins with the first character of the "/**" comment delimiter.
34  * When there is no Javadoc comment, the source range begins with the first
35  * character of the first modifier or annotation (if present), or the
36  * first character of the "enum" keyword (if no
37  * modifiers or annotations). The source range extends through the last
38  * character of the "}" token following the body declarations.
39  * </p>
40  * 
41  * @since 3.1
42  * @noinstantiate This class is not intended to be instantiated by clients.
43  */
44 public class EnumDeclaration extends AbstractTypeDeclaration {
45         
46         /**
47          * The "javadoc" structural property of this node type.
48          */
49         public static final ChildPropertyDescriptor JAVADOC_PROPERTY = 
50                 internalJavadocPropertyFactory(EnumDeclaration.class);
51
52         /**
53          * The "modifiers" structural property of this node type (added in JLS3 API).
54          */
55         public static final ChildListPropertyDescriptor MODIFIERS2_PROPERTY = 
56                 internalModifiers2PropertyFactory(EnumDeclaration.class);
57         
58         /**
59          * The "name" structural property of this node type.
60          */
61         public static final ChildPropertyDescriptor NAME_PROPERTY = 
62                 internalNamePropertyFactory(EnumDeclaration.class);
63
64         /**
65          * The "superInterfaceTypes" structural property of this node type.
66          */
67         public static final ChildListPropertyDescriptor SUPER_INTERFACE_TYPES_PROPERTY = 
68                 new ChildListPropertyDescriptor(EnumDeclaration.class, "superInterfaceTypes", Type.class, NO_CYCLE_RISK); //$NON-NLS-1$
69         
70         /**
71          * The "enumConstants" structural property of this node type.
72          */
73         public static final ChildListPropertyDescriptor ENUM_CONSTANTS_PROPERTY = 
74                 new ChildListPropertyDescriptor(EnumDeclaration.class, "enumConstants", EnumConstantDeclaration.class, CYCLE_RISK); //$NON-NLS-1$
75         
76         /**
77          * The "bodyDeclarations" structural property of this node type.
78          */
79         public static final ChildListPropertyDescriptor BODY_DECLARATIONS_PROPERTY = 
80                 internalBodyDeclarationPropertyFactory(EnumDeclaration.class);
81         
82         /**
83          * A list of property descriptors (element type: 
84          * {@link StructuralPropertyDescriptor}),
85          * or null if uninitialized.
86          */
87         private static final List PROPERTY_DESCRIPTORS;
88         
89         static {
90                 List properyList = new ArrayList(6);
91                 createPropertyList(EnumDeclaration.class, properyList);
92                 addProperty(JAVADOC_PROPERTY, properyList);
93                 addProperty(MODIFIERS2_PROPERTY, properyList);
94                 addProperty(NAME_PROPERTY, properyList);
95                 addProperty(SUPER_INTERFACE_TYPES_PROPERTY, properyList);
96                 addProperty(ENUM_CONSTANTS_PROPERTY, properyList);
97                 addProperty(BODY_DECLARATIONS_PROPERTY, properyList);
98                 PROPERTY_DESCRIPTORS = reapPropertyList(properyList);
99         }
100
101         /**
102          * Returns a list of structural property descriptors for this node type.
103          * Clients must not modify the result.
104          * 
105          * @param apiLevel the API level; one of the
106          * <code>AST.JLS*</code> constants
107
108          * @return a list of property descriptors (element type: 
109          * {@link StructuralPropertyDescriptor})
110          */
111         public static List propertyDescriptors(int apiLevel) {
112                 return PROPERTY_DESCRIPTORS;
113         }
114                         
115         /**
116          * The superinterface types (element type: <code>Type</code>). 
117          * Defaults to an empty list.
118          */
119         private ASTNode.NodeList superInterfaceTypes =
120                 new ASTNode.NodeList(SUPER_INTERFACE_TYPES_PROPERTY);
121
122         /**
123          * The enum constant declarations
124          * (element type: <code>EnumConstantDeclaration</code>).
125          * Defaults to an empty list.
126          */
127         private ASTNode.NodeList enumConstants = 
128                 new ASTNode.NodeList(ENUM_CONSTANTS_PROPERTY);
129
130         /**
131          * Creates a new AST node for an enum declaration owned by the given 
132          * AST. By default, the enum declaration has an unspecified, but legal,
133          * name; no modifiers; no javadoc; no superinterfaces; 
134          * and empty lists of enum constants and body declarations.
135          * <p>
136          * N.B. This constructor is package-private; all subclasses must be 
137          * declared in the same package; clients are unable to declare 
138          * additional subclasses.
139          * </p>
140          * 
141          * @param ast the AST that is to own this node
142          */
143         EnumDeclaration(AST ast) {
144                 super(ast);
145             unsupportedIn2();
146         }
147
148         /* (omit javadoc for this method)
149          * Method declared on ASTNode.
150          */
151         final List internalStructuralPropertiesForType(int apiLevel) {
152                 return propertyDescriptors(apiLevel);
153         }
154         
155         /* (omit javadoc for this method)
156          * Method declared on ASTNode.
157          */
158         final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) {
159                 if (property == JAVADOC_PROPERTY) {
160                         if (get) {
161                                 return getJavadoc();
162                         } else {
163                                 setJavadoc((Javadoc) child);
164                                 return null;
165                         }
166                 }
167                 if (property == NAME_PROPERTY) {
168                         if (get) {
169                                 return getName();
170                         } else {
171                                 setName((SimpleName) child);
172                                 return null;
173                         }
174                 }
175                 // allow default implementation to flag the error
176                 return super.internalGetSetChildProperty(property, get, child);
177         }
178         
179         /* (omit javadoc for this method)
180          * Method declared on ASTNode.
181          */
182         final List internalGetChildListProperty(ChildListPropertyDescriptor property) {
183                 if (property == MODIFIERS2_PROPERTY) {
184                         return modifiers();
185                 }
186                 if (property == SUPER_INTERFACE_TYPES_PROPERTY) {
187                         return superInterfaceTypes();
188                 }
189                 if (property == ENUM_CONSTANTS_PROPERTY) {
190                         return enumConstants();
191                 }
192                 if (property == BODY_DECLARATIONS_PROPERTY) {
193                         return bodyDeclarations();
194                 }
195                 // allow default implementation to flag the error
196                 return super.internalGetChildListProperty(property);
197         }
198         
199         /* (omit javadoc for this method)
200          * Method declared on BodyDeclaration.
201          */
202         final ChildPropertyDescriptor internalJavadocProperty() {
203                 return JAVADOC_PROPERTY;
204         }
205
206         /* (omit javadoc for this method)
207          * Method declared on BodyDeclaration.
208          */
209         final ChildListPropertyDescriptor internalModifiers2Property() {
210                 return MODIFIERS2_PROPERTY;
211         }
212
213         /* (omit javadoc for this method)
214          * Method declared on BodyDeclaration.
215          */
216         final SimplePropertyDescriptor internalModifiersProperty() {
217                 // this property will not be asked for (node type did not exist in JLS2)
218                 return null;
219         }
220
221         /* (omit javadoc for this method)
222          * Method declared on AbstractTypeDeclaration.
223          */
224         final ChildPropertyDescriptor internalNameProperty() {
225                 return NAME_PROPERTY;
226         }
227
228         /* (omit javadoc for this method)
229          * Method declared on AbstractTypeDeclaration.
230          */
231         final ChildListPropertyDescriptor internalBodyDeclarationsProperty() {
232                 return BODY_DECLARATIONS_PROPERTY;
233         }
234
235         /* (omit javadoc for this method)
236          * Method declared on ASTNode.
237          */
238         final int getNodeType0() {
239                 return ENUM_DECLARATION;
240         }
241
242         /* (omit javadoc for this method)
243          * Method declared on ASTNode.
244          */
245         ASTNode clone0(AST target) {
246                 EnumDeclaration result = new EnumDeclaration(target);
247                 result.setSourceRange(this.getStartPosition(), this.getLength());
248                 result.setJavadoc(
249                         (Javadoc) ASTNode.copySubtree(target, getJavadoc()));
250                 result.modifiers().addAll(ASTNode.copySubtrees(target, modifiers()));
251                 result.setName((SimpleName) getName().clone(target));
252                 result.superInterfaceTypes().addAll(
253                         ASTNode.copySubtrees(target, superInterfaceTypes()));
254                 result.enumConstants().addAll(
255                                 ASTNode.copySubtrees(target, enumConstants()));
256                 result.bodyDeclarations().addAll(
257                         ASTNode.copySubtrees(target, bodyDeclarations()));
258                 return result;
259         }
260
261         /* (omit javadoc for this method)
262          * Method declared on ASTNode.
263          */
264         final boolean subtreeMatch0(ASTMatcher matcher, Object other) {
265                 // dispatch to correct overloaded match method
266                 return matcher.match(this, other);
267         }
268         
269         /* (omit javadoc for this method)
270          * Method declared on ASTNode.
271          */
272         void accept0(ASTVisitor visitor) {
273                 boolean visitChildren = visitor.visit(this);
274                 if (visitChildren) {
275                         // visit children in normal left to right reading order
276                         acceptChild(visitor, getJavadoc());
277                         acceptChildren(visitor, this.modifiers);
278                         acceptChild(visitor, getName());
279                         acceptChildren(visitor, this.superInterfaceTypes);
280                         acceptChildren(visitor, this.enumConstants);
281                         acceptChildren(visitor, this.bodyDeclarations);
282                 }
283                 visitor.endVisit(this);
284         }
285         
286         /**
287          * Returns the live ordered list of superinterfaces of this enum
288          * declaration.
289          * 
290          * @return the live list of super interface types
291          *    (element type: <code>Type</code>)
292          */ 
293         public List superInterfaceTypes() {
294                 return this.superInterfaceTypes;
295         }
296         
297         /**
298          * Returns the live ordered list of enum constant declarations
299          * of this enum declaration.
300          * 
301          * @return the live list of enum constant declarations
302          *    (element type: {@link EnumConstantDeclaration})
303          */ 
304         public List enumConstants() {
305                 return enumConstants;
306         }
307
308         /* (omit javadoc for this method)
309          * Method declared on AsbtractTypeDeclaration.
310          */
311         ITypeBinding internalResolveBinding() {
312                 return this.ast.getBindingResolver().resolveType(this);
313         }
314         
315         /* (omit javadoc for this method)
316          * Method declared on ASTNode.
317          */
318         int memSize() {
319                 return super.memSize() + 2 * 4;
320         }
321         
322         /* (omit javadoc for this method)
323          * Method declared on ASTNode.
324          */
325         int treeSize() {
326                 return memSize()
327                         + (this.optionalDocComment == null ? 0 : getJavadoc().treeSize())
328                         + this.modifiers.listSize()
329                         + (this.typeName == null ? 0 : getName().treeSize())
330                         + this.superInterfaceTypes.listSize()
331                         + this.enumConstants.listSize()
332                         + this.bodyDeclarations.listSize();
333         }
334 }
335