KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2004, 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  * Annotation type declaration AST node type (added in JLS3 API).
18  * <pre>
19  * AnnotationTypeDeclaration:
20  * [ Javadoc ] { ExtendedModifier } <b>@</b> <b>interface</b> Identifier
21  * <b>{</b> { AnnotationTypeBodyDeclaration | <b>;</b> } <b>}</b>
22  * AnnotationTypeBodyDeclaration:
23  * AnnotationTypeMemberDeclaration
24  * FieldDeclaration
25  * TypeDeclaration
26  * EnumDeclaration
27  * AnnotationTypeDeclaration
28  * </pre>
29  * <p>
30  * The thing to note is that method declaration are replaced
31  * by annotation type member declarations in this context.
32  * </p>
33  * <p>
34  * When a Javadoc comment is present, the source
35  * range begins with the first character of the "/**" comment delimiter.
36  * When there is no Javadoc comment, the source range begins with the first
37  * character of the first modifier keyword (if modifiers), or the
38  * first character of the "@interface" (if no
39  * modifiers). The source range extends through the last character of the "}"
40  * token following the body declarations.
41  * </p>
42  *
43  * @since 3.1
44  */

45 public class AnnotationTypeDeclaration extends AbstractTypeDeclaration {
46     
47     /**
48      * The "javadoc" structural property of this node type.
49      */

50     public static final ChildPropertyDescriptor JAVADOC_PROPERTY =
51         internalJavadocPropertyFactory(AnnotationTypeDeclaration.class);
52
53     /**
54      * The "modifiers" structural property of this node type.
55      */

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

62     public static final ChildPropertyDescriptor NAME_PROPERTY =
63         internalNamePropertyFactory(AnnotationTypeDeclaration.class);
64
65     /**
66      * The "bodyDeclarations" structural property of this node type.
67      */

68     public static final ChildListPropertyDescriptor BODY_DECLARATIONS_PROPERTY =
69         internalBodyDeclarationPropertyFactory(AnnotationTypeDeclaration.class);
70     
71     /**
72      * A list of property descriptors (element type:
73      * {@link StructuralPropertyDescriptor}),
74      * or null if uninitialized.
75      */

76     private static final List JavaDoc PROPERTY_DESCRIPTORS;
77     
78     static {
79         List JavaDoc properyList = new ArrayList JavaDoc(5);
80         createPropertyList(AnnotationTypeDeclaration.class, properyList);
81         addProperty(JAVADOC_PROPERTY, properyList);
82         addProperty(MODIFIERS2_PROPERTY, properyList);
83         addProperty(NAME_PROPERTY, properyList);
84         addProperty(BODY_DECLARATIONS_PROPERTY, properyList);
85         PROPERTY_DESCRIPTORS = reapPropertyList(properyList);
86     }
87
88     /**
89      * Returns a list of structural property descriptors for this node type.
90      * Clients must not modify the result.
91      *
92      * @param apiLevel the API level; one of the
93      * <code>AST.JLS*</code> constants
94
95      * @return a list of property descriptors (element type:
96      * {@link StructuralPropertyDescriptor})
97      */

98     public static List JavaDoc propertyDescriptors(int apiLevel) {
99         return PROPERTY_DESCRIPTORS;
100     }
101             
102     /**
103      * Creates a new AST node for an annotation type declaration owned by the given
104      * AST. By default, the type declaration is for an annotation
105      * type of an unspecified, but legal, name; no modifiers; no javadoc;
106      * and an empty list of body declarations.
107      * <p>
108      * N.B. This constructor is package-private; all subclasses must be
109      * declared in the same package; clients are unable to declare
110      * additional subclasses.
111      * </p>
112      *
113      * @param ast the AST that is to own this node
114      */

115     AnnotationTypeDeclaration(AST ast) {
116         super(ast);
117         unsupportedIn2();
118     }
119
120     /* (omit javadoc for this method)
121      * Method declared on ASTNode.
122      */

123     final List JavaDoc internalStructuralPropertiesForType(int apiLevel) {
124         return propertyDescriptors(apiLevel);
125     }
126     
127     /* (omit javadoc for this method)
128      * Method declared on ASTNode.
129      */

130     final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) {
131         if (property == JAVADOC_PROPERTY) {
132             if (get) {
133                 return getJavadoc();
134             } else {
135                 setJavadoc((Javadoc) child);
136                 return null;
137             }
138         }
139         if (property == NAME_PROPERTY) {
140             if (get) {
141                 return getName();
142             } else {
143                 setName((SimpleName) child);
144                 return null;
145             }
146         }
147         // allow default implementation to flag the error
148
return super.internalGetSetChildProperty(property, get, child);
149     }
150     
151     /* (omit javadoc for this method)
152      * Method declared on ASTNode.
153      */

154     final List JavaDoc internalGetChildListProperty(ChildListPropertyDescriptor property) {
155         if (property == MODIFIERS2_PROPERTY) {
156             return modifiers();
157         }
158         if (property == BODY_DECLARATIONS_PROPERTY) {
159             return bodyDeclarations();
160         }
161         // allow default implementation to flag the error
162
return super.internalGetChildListProperty(property);
163     }
164     
165     /* (omit javadoc for this method)
166      * Method declared on BodyDeclaration.
167      */

168     final ChildPropertyDescriptor internalJavadocProperty() {
169         return JAVADOC_PROPERTY;
170     }
171
172     /* (omit javadoc for this method)
173      * Method declared on BodyDeclaration.
174      */

175     final ChildListPropertyDescriptor internalModifiers2Property() {
176         return MODIFIERS2_PROPERTY;
177     }
178
179     /* (omit javadoc for this method)
180      * Method declared on BodyDeclaration.
181      */

182     final SimplePropertyDescriptor internalModifiersProperty() {
183         // this property will not be asked for (node type did not exist in JLS2)
184
return null;
185     }
186
187     /* (omit javadoc for this method)
188      * Method declared on AbstractTypeDeclaration.
189      */

190     final ChildPropertyDescriptor internalNameProperty() {
191         return NAME_PROPERTY;
192     }
193
194     /* (omit javadoc for this method)
195      * Method declared on AbstractTypeDeclaration.
196      */

197     final ChildListPropertyDescriptor internalBodyDeclarationsProperty() {
198         return BODY_DECLARATIONS_PROPERTY;
199     }
200
201     /* (omit javadoc for this method)
202      * Method declared on ASTNode.
203      */

204     final int getNodeType0() {
205         return ANNOTATION_TYPE_DECLARATION;
206     }
207
208     /* (omit javadoc for this method)
209      * Method declared on ASTNode.
210      */

211     ASTNode clone0(AST target) {
212         AnnotationTypeDeclaration result = new AnnotationTypeDeclaration(target);
213         result.setSourceRange(this.getStartPosition(), this.getLength());
214         result.setJavadoc(
215             (Javadoc) ASTNode.copySubtree(target, getJavadoc()));
216         result.modifiers().addAll(ASTNode.copySubtrees(target, modifiers()));
217         result.setName((SimpleName) getName().clone(target));
218         result.bodyDeclarations().addAll(ASTNode.copySubtrees(target, bodyDeclarations()));
219         return result;
220     }
221
222     /* (omit javadoc for this method)
223      * Method declared on ASTNode.
224      */

225     final boolean subtreeMatch0(ASTMatcher matcher, Object JavaDoc other) {
226         // dispatch to correct overloaded match method
227
return matcher.match(this, other);
228     }
229     
230     /* (omit javadoc for this method)
231      * Method declared on ASTNode.
232      */

233     void accept0(ASTVisitor visitor) {
234         boolean visitChildren = visitor.visit(this);
235         if (visitChildren) {
236             // visit children in normal left to right reading order
237
acceptChild(visitor, getJavadoc());
238             acceptChildren(visitor, this.modifiers);
239             acceptChild(visitor, getName());
240             acceptChildren(visitor, this.bodyDeclarations);
241         }
242         visitor.endVisit(this);
243     }
244     
245     /* (omit javadoc for this method)
246      * Method declared on AsbtractTypeDeclaration.
247      */

248     ITypeBinding internalResolveBinding() {
249         return this.ast.getBindingResolver().resolveType(this);
250     }
251     
252     /* (omit javadoc for this method)
253      * Method declared on ASTNode.
254      */

255     int memSize() {
256         return super.memSize();
257     }
258     
259     /* (omit javadoc for this method)
260      * Method declared on ASTNode.
261      */

262     int treeSize() {
263         return
264             memSize()
265             + (this.optionalDocComment == null ? 0 : getJavadoc().treeSize())
266             + this.modifiers.listSize()
267             + (this.typeName == null ? 0 : getName().treeSize())
268             + this.bodyDeclarations.listSize();
269     }
270 }
271
272
Popular Tags