Initial upgrade to Platform/JDT 3.4.1
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / core / dom / AnnotationTypeDeclaration.java
1 /*******************************************************************************
2  * Copyright (c) 2004, 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  * 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  * @noinstantiate This class is not intended to be instantiated by clients.
45  */
46 public class AnnotationTypeDeclaration extends AbstractTypeDeclaration {
47         
48         /**
49          * The "javadoc" structural property of this node type.
50          */
51         public static final ChildPropertyDescriptor JAVADOC_PROPERTY = 
52                 internalJavadocPropertyFactory(AnnotationTypeDeclaration.class);
53
54         /**
55          * The "modifiers" structural property of this node type.
56          */
57         public static final ChildListPropertyDescriptor MODIFIERS2_PROPERTY = 
58                 internalModifiers2PropertyFactory(AnnotationTypeDeclaration.class);
59         
60         /**
61          * The "name" structural property of this node type.
62          */
63         public static final ChildPropertyDescriptor NAME_PROPERTY = 
64                 internalNamePropertyFactory(AnnotationTypeDeclaration.class);
65
66         /**
67          * The "bodyDeclarations" structural property of this node type.
68          */
69         public static final ChildListPropertyDescriptor BODY_DECLARATIONS_PROPERTY = 
70                 internalBodyDeclarationPropertyFactory(AnnotationTypeDeclaration.class);
71         
72         /**
73          * A list of property descriptors (element type: 
74          * {@link StructuralPropertyDescriptor}),
75          * or null if uninitialized.
76          */
77         private static final List PROPERTY_DESCRIPTORS;
78         
79         static {
80                 List properyList = new ArrayList(5);
81                 createPropertyList(AnnotationTypeDeclaration.class, properyList);
82                 addProperty(JAVADOC_PROPERTY, properyList);
83                 addProperty(MODIFIERS2_PROPERTY, properyList);
84                 addProperty(NAME_PROPERTY, properyList);
85                 addProperty(BODY_DECLARATIONS_PROPERTY, properyList);
86                 PROPERTY_DESCRIPTORS = 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          */
99         public static List propertyDescriptors(int apiLevel) {
100                 return PROPERTY_DESCRIPTORS;
101         }
102                         
103         /**
104          * Creates a new AST node for an annotation type declaration owned by the given 
105          * AST. By default, the type declaration is for an annotation
106          * type of an unspecified, but legal, name; no modifiers; no javadoc; 
107          * and an empty list of body declarations.
108          * <p>
109          * N.B. This constructor is package-private; all subclasses must be 
110          * declared in the same package; clients are unable to declare 
111          * additional subclasses.
112          * </p>
113          * 
114          * @param ast the AST that is to own this node
115          */
116         AnnotationTypeDeclaration(AST ast) {
117                 super(ast);
118             unsupportedIn2();
119         }
120
121         /* (omit javadoc for this method)
122          * Method declared on ASTNode.
123          */
124         final List internalStructuralPropertiesForType(int apiLevel) {
125                 return propertyDescriptors(apiLevel);
126         }
127         
128         /* (omit javadoc for this method)
129          * Method declared on ASTNode.
130          */
131         final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) {
132                 if (property == JAVADOC_PROPERTY) {
133                         if (get) {
134                                 return getJavadoc();
135                         } else {
136                                 setJavadoc((Javadoc) child);
137                                 return null;
138                         }
139                 }
140                 if (property == NAME_PROPERTY) {
141                         if (get) {
142                                 return getName();
143                         } else {
144                                 setName((SimpleName) child);
145                                 return null;
146                         }
147                 }
148                 // allow default implementation to flag the error
149                 return super.internalGetSetChildProperty(property, get, child);
150         }
151         
152         /* (omit javadoc for this method)
153          * Method declared on ASTNode.
154          */
155         final List internalGetChildListProperty(ChildListPropertyDescriptor property) {
156                 if (property == MODIFIERS2_PROPERTY) {
157                         return modifiers();
158                 }
159                 if (property == BODY_DECLARATIONS_PROPERTY) {
160                         return bodyDeclarations();
161                 }
162                 // allow default implementation to flag the error
163                 return super.internalGetChildListProperty(property);
164         }
165         
166         /* (omit javadoc for this method)
167          * Method declared on BodyDeclaration.
168          */
169         final ChildPropertyDescriptor internalJavadocProperty() {
170                 return JAVADOC_PROPERTY;
171         }
172
173         /* (omit javadoc for this method)
174          * Method declared on BodyDeclaration.
175          */
176         final ChildListPropertyDescriptor internalModifiers2Property() {
177                 return MODIFIERS2_PROPERTY;
178         }
179
180         /* (omit javadoc for this method)
181          * Method declared on BodyDeclaration.
182          */
183         final SimplePropertyDescriptor internalModifiersProperty() {
184                 // this property will not be asked for (node type did not exist in JLS2)
185                 return null;
186         }
187
188         /* (omit javadoc for this method)
189          * Method declared on AbstractTypeDeclaration.
190          */
191         final ChildPropertyDescriptor internalNameProperty() {
192                 return NAME_PROPERTY;
193         }
194
195         /* (omit javadoc for this method)
196          * Method declared on AbstractTypeDeclaration.
197          */
198         final ChildListPropertyDescriptor internalBodyDeclarationsProperty() {
199                 return BODY_DECLARATIONS_PROPERTY;
200         }
201
202         /* (omit javadoc for this method)
203          * Method declared on ASTNode.
204          */
205         final int getNodeType0() {
206                 return ANNOTATION_TYPE_DECLARATION;
207         }
208
209         /* (omit javadoc for this method)
210          * Method declared on ASTNode.
211          */
212         ASTNode clone0(AST target) {
213                 AnnotationTypeDeclaration result = new AnnotationTypeDeclaration(target);
214                 result.setSourceRange(this.getStartPosition(), this.getLength());
215                 result.setJavadoc(
216                         (Javadoc) ASTNode.copySubtree(target, getJavadoc()));
217                 result.modifiers().addAll(ASTNode.copySubtrees(target, modifiers()));
218                 result.setName((SimpleName) getName().clone(target));
219                 result.bodyDeclarations().addAll(ASTNode.copySubtrees(target, bodyDeclarations()));
220                 return result;
221         }
222
223         /* (omit javadoc for this method)
224          * Method declared on ASTNode.
225          */
226         final boolean subtreeMatch0(ASTMatcher matcher, Object other) {
227                 // dispatch to correct overloaded match method
228                 return matcher.match(this, other);
229         }
230         
231         /* (omit javadoc for this method)
232          * Method declared on ASTNode.
233          */
234         void accept0(ASTVisitor visitor) {
235                 boolean visitChildren = visitor.visit(this);
236                 if (visitChildren) {
237                         // visit children in normal left to right reading order
238                         acceptChild(visitor, getJavadoc());
239                         acceptChildren(visitor, this.modifiers);
240                         acceptChild(visitor, getName());
241                         acceptChildren(visitor, this.bodyDeclarations);
242                 }
243                 visitor.endVisit(this);
244         }
245         
246         /* (omit javadoc for this method)
247          * Method declared on AsbtractTypeDeclaration.
248          */
249         ITypeBinding internalResolveBinding() {
250                 return this.ast.getBindingResolver().resolveType(this);
251         }
252         
253         /* (omit javadoc for this method)
254          * Method declared on ASTNode.
255          */
256         int memSize() {
257                 return super.memSize();
258         }
259         
260         /* (omit javadoc for this method)
261          * Method declared on ASTNode.
262          */
263         int treeSize() {
264                 return
265                         memSize()
266                         + (this.optionalDocComment == null ? 0 : getJavadoc().treeSize())
267                         + this.modifiers.listSize()
268                         + (this.typeName == null ? 0 : getName().treeSize())
269                         + this.bodyDeclarations.listSize();
270         }
271 }
272