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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.core.dom;
13 import java.util.ArrayList;
14 import java.util.List;
17 * Annotation type declaration AST node type (added in JLS3 API).
19 * AnnotationTypeDeclaration:
20 * [ Javadoc ] { ExtendedModifier } <b>@</b> <b>interface</b> Identifier
21 * <b>{</b> { AnnotationTypeBodyDeclaration | <b>;</b> } <b>}</b>
22 * AnnotationTypeBodyDeclaration:
23 * AnnotationTypeMemberDeclaration
27 * AnnotationTypeDeclaration
30 * The thing to note is that method declaration are replaced
31 * by annotation type member declarations in this context.
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.
44 * @noinstantiate This class is not intended to be instantiated by clients.
46 public class AnnotationTypeDeclaration extends AbstractTypeDeclaration {
49 * The "javadoc" structural property of this node type.
51 public static final ChildPropertyDescriptor JAVADOC_PROPERTY =
52 internalJavadocPropertyFactory(AnnotationTypeDeclaration.class);
55 * The "modifiers" structural property of this node type.
57 public static final ChildListPropertyDescriptor MODIFIERS2_PROPERTY =
58 internalModifiers2PropertyFactory(AnnotationTypeDeclaration.class);
61 * The "name" structural property of this node type.
63 public static final ChildPropertyDescriptor NAME_PROPERTY =
64 internalNamePropertyFactory(AnnotationTypeDeclaration.class);
67 * The "bodyDeclarations" structural property of this node type.
69 public static final ChildListPropertyDescriptor BODY_DECLARATIONS_PROPERTY =
70 internalBodyDeclarationPropertyFactory(AnnotationTypeDeclaration.class);
73 * A list of property descriptors (element type:
74 * {@link StructuralPropertyDescriptor}),
75 * or null if uninitialized.
77 private static final List PROPERTY_DESCRIPTORS;
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);
90 * Returns a list of structural property descriptors for this node type.
91 * Clients must not modify the result.
93 * @param apiLevel the API level; one of the
94 * <code>AST.JLS*</code> constants
96 * @return a list of property descriptors (element type:
97 * {@link StructuralPropertyDescriptor})
99 public static List propertyDescriptors(int apiLevel) {
100 return PROPERTY_DESCRIPTORS;
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.
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.
114 * @param ast the AST that is to own this node
116 AnnotationTypeDeclaration(AST ast) {
121 /* (omit javadoc for this method)
122 * Method declared on ASTNode.
124 final List internalStructuralPropertiesForType(int apiLevel) {
125 return propertyDescriptors(apiLevel);
128 /* (omit javadoc for this method)
129 * Method declared on ASTNode.
131 final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) {
132 if (property == JAVADOC_PROPERTY) {
136 setJavadoc((Javadoc) child);
140 if (property == NAME_PROPERTY) {
144 setName((SimpleName) child);
148 // allow default implementation to flag the error
149 return super.internalGetSetChildProperty(property, get, child);
152 /* (omit javadoc for this method)
153 * Method declared on ASTNode.
155 final List internalGetChildListProperty(ChildListPropertyDescriptor property) {
156 if (property == MODIFIERS2_PROPERTY) {
159 if (property == BODY_DECLARATIONS_PROPERTY) {
160 return bodyDeclarations();
162 // allow default implementation to flag the error
163 return super.internalGetChildListProperty(property);
166 /* (omit javadoc for this method)
167 * Method declared on BodyDeclaration.
169 final ChildPropertyDescriptor internalJavadocProperty() {
170 return JAVADOC_PROPERTY;
173 /* (omit javadoc for this method)
174 * Method declared on BodyDeclaration.
176 final ChildListPropertyDescriptor internalModifiers2Property() {
177 return MODIFIERS2_PROPERTY;
180 /* (omit javadoc for this method)
181 * Method declared on BodyDeclaration.
183 final SimplePropertyDescriptor internalModifiersProperty() {
184 // this property will not be asked for (node type did not exist in JLS2)
188 /* (omit javadoc for this method)
189 * Method declared on AbstractTypeDeclaration.
191 final ChildPropertyDescriptor internalNameProperty() {
192 return NAME_PROPERTY;
195 /* (omit javadoc for this method)
196 * Method declared on AbstractTypeDeclaration.
198 final ChildListPropertyDescriptor internalBodyDeclarationsProperty() {
199 return BODY_DECLARATIONS_PROPERTY;
202 /* (omit javadoc for this method)
203 * Method declared on ASTNode.
205 final int getNodeType0() {
206 return ANNOTATION_TYPE_DECLARATION;
209 /* (omit javadoc for this method)
210 * Method declared on ASTNode.
212 ASTNode clone0(AST target) {
213 AnnotationTypeDeclaration result = new AnnotationTypeDeclaration(target);
214 result.setSourceRange(this.getStartPosition(), this.getLength());
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()));
223 /* (omit javadoc for this method)
224 * Method declared on ASTNode.
226 final boolean subtreeMatch0(ASTMatcher matcher, Object other) {
227 // dispatch to correct overloaded match method
228 return matcher.match(this, other);
231 /* (omit javadoc for this method)
232 * Method declared on ASTNode.
234 void accept0(ASTVisitor visitor) {
235 boolean visitChildren = visitor.visit(this);
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);
243 visitor.endVisit(this);
246 /* (omit javadoc for this method)
247 * Method declared on AsbtractTypeDeclaration.
249 ITypeBinding internalResolveBinding() {
250 return this.ast.getBindingResolver().resolveType(this);
253 /* (omit javadoc for this method)
254 * Method declared on ASTNode.
257 return super.memSize();
260 /* (omit javadoc for this method)
261 * Method declared on ASTNode.
266 + (this.optionalDocComment == null ? 0 : getJavadoc().treeSize())
267 + this.modifiers.listSize()
268 + (this.typeName == null ? 0 : getName().treeSize())
269 + this.bodyDeclarations.listSize();