KickJava   Java API By Example, From Geeks To Geeks.

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


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

43 public class EnumDeclaration extends AbstractTypeDeclaration {
44     
45     /**
46      * The "javadoc" structural property of this node type.
47      */

48     public static final ChildPropertyDescriptor JAVADOC_PROPERTY =
49         internalJavadocPropertyFactory(EnumDeclaration.class);
50
51     /**
52      * The "modifiers" structural property of this node type (added in JLS3 API).
53      */

54     public static final ChildListPropertyDescriptor MODIFIERS2_PROPERTY =
55         internalModifiers2PropertyFactory(EnumDeclaration.class);
56     
57     /**
58      * The "name" structural property of this node type.
59      */

60     public static final ChildPropertyDescriptor NAME_PROPERTY =
61         internalNamePropertyFactory(EnumDeclaration.class);
62
63     /**
64      * The "superInterfaceTypes" structural property of this node type.
65      */

66     public static final ChildListPropertyDescriptor SUPER_INTERFACE_TYPES_PROPERTY =
67         new ChildListPropertyDescriptor(EnumDeclaration.class, "superInterfaceTypes", Type.class, NO_CYCLE_RISK); //$NON-NLS-1$
68

69     /**
70      * The "enumConstants" structural property of this node type.
71      */

72     public static final ChildListPropertyDescriptor ENUM_CONSTANTS_PROPERTY =
73         new ChildListPropertyDescriptor(EnumDeclaration.class, "enumConstants", EnumConstantDeclaration.class, CYCLE_RISK); //$NON-NLS-1$
74

75     /**
76      * The "bodyDeclarations" structural property of this node type.
77      */

78     public static final ChildListPropertyDescriptor BODY_DECLARATIONS_PROPERTY =
79         internalBodyDeclarationPropertyFactory(EnumDeclaration.class);
80     
81     /**
82      * A list of property descriptors (element type:
83      * {@link StructuralPropertyDescriptor}),
84      * or null if uninitialized.
85      */

86     private static final List JavaDoc PROPERTY_DESCRIPTORS;
87     
88     static {
89         List JavaDoc properyList = new ArrayList JavaDoc(6);
90         createPropertyList(EnumDeclaration.class, properyList);
91         addProperty(JAVADOC_PROPERTY, properyList);
92         addProperty(MODIFIERS2_PROPERTY, properyList);
93         addProperty(NAME_PROPERTY, properyList);
94         addProperty(SUPER_INTERFACE_TYPES_PROPERTY, properyList);
95         addProperty(ENUM_CONSTANTS_PROPERTY, properyList);
96         addProperty(BODY_DECLARATIONS_PROPERTY, properyList);
97         PROPERTY_DESCRIPTORS = reapPropertyList(properyList);
98     }
99
100     /**
101      * Returns a list of structural property descriptors for this node type.
102      * Clients must not modify the result.
103      *
104      * @param apiLevel the API level; one of the
105      * <code>AST.JLS&ast;</code> constants
106
107      * @return a list of property descriptors (element type:
108      * {@link StructuralPropertyDescriptor})
109      */

110     public static List JavaDoc propertyDescriptors(int apiLevel) {
111         return PROPERTY_DESCRIPTORS;
112     }
113             
114     /**
115      * The superinterface types (element type: <code>Type</code>).
116      * Defaults to an empty list.
117      */

118     private ASTNode.NodeList superInterfaceTypes =
119         new ASTNode.NodeList(SUPER_INTERFACE_TYPES_PROPERTY);
120
121     /**
122      * The enum constant declarations
123      * (element type: <code>EnumConstantDeclaration</code>).
124      * Defaults to an empty list.
125      */

126     private ASTNode.NodeList enumConstants =
127         new ASTNode.NodeList(ENUM_CONSTANTS_PROPERTY);
128
129     /**
130      * Creates a new AST node for an enum declaration owned by the given
131      * AST. By default, the enum declaration has an unspecified, but legal,
132      * name; no modifiers; no javadoc; no superinterfaces;
133      * and empty lists of enum constants and body declarations.
134      * <p>
135      * N.B. This constructor is package-private; all subclasses must be
136      * declared in the same package; clients are unable to declare
137      * additional subclasses.
138      * </p>
139      *
140      * @param ast the AST that is to own this node
141      */

142     EnumDeclaration(AST ast) {
143         super(ast);
144         unsupportedIn2();
145     }
146
147     /* (omit javadoc for this method)
148      * Method declared on ASTNode.
149      */

150     final List JavaDoc internalStructuralPropertiesForType(int apiLevel) {
151         return propertyDescriptors(apiLevel);
152     }
153     
154     /* (omit javadoc for this method)
155      * Method declared on ASTNode.
156      */

157     final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) {
158         if (property == JAVADOC_PROPERTY) {
159             if (get) {
160                 return getJavadoc();
161             } else {
162                 setJavadoc((Javadoc) child);
163                 return null;
164             }
165         }
166         if (property == NAME_PROPERTY) {
167             if (get) {
168                 return getName();
169             } else {
170                 setName((SimpleName) child);
171                 return null;
172             }
173         }
174         // allow default implementation to flag the error
175
return super.internalGetSetChildProperty(property, get, child);
176     }
177     
178     /* (omit javadoc for this method)
179      * Method declared on ASTNode.
180      */

181     final List JavaDoc internalGetChildListProperty(ChildListPropertyDescriptor property) {
182         if (property == MODIFIERS2_PROPERTY) {
183             return modifiers();
184         }
185         if (property == SUPER_INTERFACE_TYPES_PROPERTY) {
186             return superInterfaceTypes();
187         }
188         if (property == ENUM_CONSTANTS_PROPERTY) {
189             return enumConstants();
190         }
191         if (property == BODY_DECLARATIONS_PROPERTY) {
192             return bodyDeclarations();
193         }
194         // allow default implementation to flag the error
195
return super.internalGetChildListProperty(property);
196     }
197     
198     /* (omit javadoc for this method)
199      * Method declared on BodyDeclaration.
200      */

201     final ChildPropertyDescriptor internalJavadocProperty() {
202         return JAVADOC_PROPERTY;
203     }
204
205     /* (omit javadoc for this method)
206      * Method declared on BodyDeclaration.
207      */

208     final ChildListPropertyDescriptor internalModifiers2Property() {
209         return MODIFIERS2_PROPERTY;
210     }
211
212     /* (omit javadoc for this method)
213      * Method declared on BodyDeclaration.
214      */

215     final SimplePropertyDescriptor internalModifiersProperty() {
216         // this property will not be asked for (node type did not exist in JLS2)
217
return null;
218     }
219
220     /* (omit javadoc for this method)
221      * Method declared on AbstractTypeDeclaration.
222      */

223     final ChildPropertyDescriptor internalNameProperty() {
224         return NAME_PROPERTY;
225     }
226
227     /* (omit javadoc for this method)
228      * Method declared on AbstractTypeDeclaration.
229      */

230     final ChildListPropertyDescriptor internalBodyDeclarationsProperty() {
231         return BODY_DECLARATIONS_PROPERTY;
232     }
233
234     /* (omit javadoc for this method)
235      * Method declared on ASTNode.
236      */

237     final int getNodeType0() {
238         return ENUM_DECLARATION;
239     }
240
241     /* (omit javadoc for this method)
242      * Method declared on ASTNode.
243      */

244     ASTNode clone0(AST target) {
245         EnumDeclaration result = new EnumDeclaration(target);
246         result.setSourceRange(this.getStartPosition(), this.getLength());
247         result.setJavadoc(
248             (Javadoc) ASTNode.copySubtree(target, getJavadoc()));
249         result.modifiers().addAll(ASTNode.copySubtrees(target, modifiers()));
250         result.setName((SimpleName) getName().clone(target));
251         result.superInterfaceTypes().addAll(
252             ASTNode.copySubtrees(target, superInterfaceTypes()));
253         result.enumConstants().addAll(
254                 ASTNode.copySubtrees(target, enumConstants()));
255         result.bodyDeclarations().addAll(
256             ASTNode.copySubtrees(target, bodyDeclarations()));
257         return result;
258     }
259
260     /* (omit javadoc for this method)
261      * Method declared on ASTNode.
262      */

263     final boolean subtreeMatch0(ASTMatcher matcher, Object JavaDoc other) {
264         // dispatch to correct overloaded match method
265
return matcher.match(this, other);
266     }
267     
268     /* (omit javadoc for this method)
269      * Method declared on ASTNode.
270      */

271     void accept0(ASTVisitor visitor) {
272         boolean visitChildren = visitor.visit(this);
273         if (visitChildren) {
274             // visit children in normal left to right reading order
275
acceptChild(visitor, getJavadoc());
276             acceptChildren(visitor, this.modifiers);
277             acceptChild(visitor, getName());
278             acceptChildren(visitor, this.superInterfaceTypes);
279             acceptChildren(visitor, this.enumConstants);
280             acceptChildren(visitor, this.bodyDeclarations);
281         }
282         visitor.endVisit(this);
283     }
284     
285     /**
286      * Returns the live ordered list of superinterfaces of this enum
287      * declaration.
288      *
289      * @return the live list of super interface types
290      * (element type: <code>Type</code>)
291      */

292     public List JavaDoc superInterfaceTypes() {
293         return this.superInterfaceTypes;
294     }
295     
296     /**
297      * Returns the live ordered list of enum constant declarations
298      * of this enum declaration.
299      *
300      * @return the live list of enum constant declarations
301      * (element type: {@link EnumConstantDeclaration})
302      */

303     public List JavaDoc enumConstants() {
304         return enumConstants;
305     }
306
307     /* (omit javadoc for this method)
308      * Method declared on AsbtractTypeDeclaration.
309      */

310     ITypeBinding internalResolveBinding() {
311         return this.ast.getBindingResolver().resolveType(this);
312     }
313     
314     /* (omit javadoc for this method)
315      * Method declared on ASTNode.
316      */

317     int memSize() {
318         return super.memSize() + 2 * 4;
319     }
320     
321     /* (omit javadoc for this method)
322      * Method declared on ASTNode.
323      */

324     int treeSize() {
325         return memSize()
326             + (this.optionalDocComment == null ? 0 : getJavadoc().treeSize())
327             + this.modifiers.listSize()
328             + (this.typeName == null ? 0 : getName().treeSize())
329             + this.superInterfaceTypes.listSize()
330             + this.enumConstants.listSize()
331             + this.bodyDeclarations.listSize();
332     }
333 }
334
335
Popular Tags