001: /*******************************************************************************
002: * Copyright (c) 2004, 2005 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.jdt.core.dom;
011:
012: import java.util.ArrayList;
013: import java.util.List;
014:
015: /**
016: * Annotation type declaration AST node type (added in JLS3 API).
017: * <pre>
018: * AnnotationTypeDeclaration:
019: * [ Javadoc ] { ExtendedModifier } <b>@</b> <b>interface</b> Identifier
020: * <b>{</b> { AnnotationTypeBodyDeclaration | <b>;</b> } <b>}</b>
021: * AnnotationTypeBodyDeclaration:
022: * AnnotationTypeMemberDeclaration
023: * FieldDeclaration
024: * TypeDeclaration
025: * EnumDeclaration
026: * AnnotationTypeDeclaration
027: * </pre>
028: * <p>
029: * The thing to note is that method declaration are replaced
030: * by annotation type member declarations in this context.
031: * </p>
032: * <p>
033: * When a Javadoc comment is present, the source
034: * range begins with the first character of the "/**" comment delimiter.
035: * When there is no Javadoc comment, the source range begins with the first
036: * character of the first modifier keyword (if modifiers), or the
037: * first character of the "@interface" (if no
038: * modifiers). The source range extends through the last character of the "}"
039: * token following the body declarations.
040: * </p>
041: *
042: * @since 3.1
043: */
044: public class AnnotationTypeDeclaration extends AbstractTypeDeclaration {
045:
046: /**
047: * The "javadoc" structural property of this node type.
048: */
049: public static final ChildPropertyDescriptor JAVADOC_PROPERTY = internalJavadocPropertyFactory(AnnotationTypeDeclaration.class);
050:
051: /**
052: * The "modifiers" structural property of this node type.
053: */
054: public static final ChildListPropertyDescriptor MODIFIERS2_PROPERTY = internalModifiers2PropertyFactory(AnnotationTypeDeclaration.class);
055:
056: /**
057: * The "name" structural property of this node type.
058: */
059: public static final ChildPropertyDescriptor NAME_PROPERTY = internalNamePropertyFactory(AnnotationTypeDeclaration.class);
060:
061: /**
062: * The "bodyDeclarations" structural property of this node type.
063: */
064: public static final ChildListPropertyDescriptor BODY_DECLARATIONS_PROPERTY = internalBodyDeclarationPropertyFactory(AnnotationTypeDeclaration.class);
065:
066: /**
067: * A list of property descriptors (element type:
068: * {@link StructuralPropertyDescriptor}),
069: * or null if uninitialized.
070: */
071: private static final List PROPERTY_DESCRIPTORS;
072:
073: static {
074: List properyList = new ArrayList(5);
075: createPropertyList(AnnotationTypeDeclaration.class, properyList);
076: addProperty(JAVADOC_PROPERTY, properyList);
077: addProperty(MODIFIERS2_PROPERTY, properyList);
078: addProperty(NAME_PROPERTY, properyList);
079: addProperty(BODY_DECLARATIONS_PROPERTY, properyList);
080: PROPERTY_DESCRIPTORS = reapPropertyList(properyList);
081: }
082:
083: /**
084: * Returns a list of structural property descriptors for this node type.
085: * Clients must not modify the result.
086: *
087: * @param apiLevel the API level; one of the
088: * <code>AST.JLS*</code> constants
089:
090: * @return a list of property descriptors (element type:
091: * {@link StructuralPropertyDescriptor})
092: */
093: public static List propertyDescriptors(int apiLevel) {
094: return PROPERTY_DESCRIPTORS;
095: }
096:
097: /**
098: * Creates a new AST node for an annotation type declaration owned by the given
099: * AST. By default, the type declaration is for an annotation
100: * type of an unspecified, but legal, name; no modifiers; no javadoc;
101: * and an empty list of body declarations.
102: * <p>
103: * N.B. This constructor is package-private; all subclasses must be
104: * declared in the same package; clients are unable to declare
105: * additional subclasses.
106: * </p>
107: *
108: * @param ast the AST that is to own this node
109: */
110: AnnotationTypeDeclaration(AST ast) {
111: super (ast);
112: unsupportedIn2();
113: }
114:
115: /* (omit javadoc for this method)
116: * Method declared on ASTNode.
117: */
118: final List internalStructuralPropertiesForType(int apiLevel) {
119: return propertyDescriptors(apiLevel);
120: }
121:
122: /* (omit javadoc for this method)
123: * Method declared on ASTNode.
124: */
125: final ASTNode internalGetSetChildProperty(
126: ChildPropertyDescriptor property, boolean get, ASTNode child) {
127: if (property == JAVADOC_PROPERTY) {
128: if (get) {
129: return getJavadoc();
130: } else {
131: setJavadoc((Javadoc) child);
132: return null;
133: }
134: }
135: if (property == NAME_PROPERTY) {
136: if (get) {
137: return getName();
138: } else {
139: setName((SimpleName) child);
140: return null;
141: }
142: }
143: // allow default implementation to flag the error
144: return super .internalGetSetChildProperty(property, get, child);
145: }
146:
147: /* (omit javadoc for this method)
148: * Method declared on ASTNode.
149: */
150: final List internalGetChildListProperty(
151: ChildListPropertyDescriptor property) {
152: if (property == MODIFIERS2_PROPERTY) {
153: return modifiers();
154: }
155: if (property == BODY_DECLARATIONS_PROPERTY) {
156: return bodyDeclarations();
157: }
158: // allow default implementation to flag the error
159: return super .internalGetChildListProperty(property);
160: }
161:
162: /* (omit javadoc for this method)
163: * Method declared on BodyDeclaration.
164: */
165: final ChildPropertyDescriptor internalJavadocProperty() {
166: return JAVADOC_PROPERTY;
167: }
168:
169: /* (omit javadoc for this method)
170: * Method declared on BodyDeclaration.
171: */
172: final ChildListPropertyDescriptor internalModifiers2Property() {
173: return MODIFIERS2_PROPERTY;
174: }
175:
176: /* (omit javadoc for this method)
177: * Method declared on BodyDeclaration.
178: */
179: final SimplePropertyDescriptor internalModifiersProperty() {
180: // this property will not be asked for (node type did not exist in JLS2)
181: return null;
182: }
183:
184: /* (omit javadoc for this method)
185: * Method declared on AbstractTypeDeclaration.
186: */
187: final ChildPropertyDescriptor internalNameProperty() {
188: return NAME_PROPERTY;
189: }
190:
191: /* (omit javadoc for this method)
192: * Method declared on AbstractTypeDeclaration.
193: */
194: final ChildListPropertyDescriptor internalBodyDeclarationsProperty() {
195: return BODY_DECLARATIONS_PROPERTY;
196: }
197:
198: /* (omit javadoc for this method)
199: * Method declared on ASTNode.
200: */
201: final int getNodeType0() {
202: return ANNOTATION_TYPE_DECLARATION;
203: }
204:
205: /* (omit javadoc for this method)
206: * Method declared on ASTNode.
207: */
208: ASTNode clone0(AST target) {
209: AnnotationTypeDeclaration result = new AnnotationTypeDeclaration(
210: target);
211: result
212: .setSourceRange(this .getStartPosition(), this
213: .getLength());
214: result.setJavadoc((Javadoc) ASTNode.copySubtree(target,
215: getJavadoc()));
216: result.modifiers().addAll(
217: ASTNode.copySubtrees(target, modifiers()));
218: result.setName((SimpleName) getName().clone(target));
219: result.bodyDeclarations().addAll(
220: ASTNode.copySubtrees(target, bodyDeclarations()));
221: return result;
222: }
223:
224: /* (omit javadoc for this method)
225: * Method declared on ASTNode.
226: */
227: final boolean subtreeMatch0(ASTMatcher matcher, Object other) {
228: // dispatch to correct overloaded match method
229: return matcher.match(this , other);
230: }
231:
232: /* (omit javadoc for this method)
233: * Method declared on ASTNode.
234: */
235: void accept0(ASTVisitor visitor) {
236: boolean visitChildren = visitor.visit(this );
237: if (visitChildren) {
238: // visit children in normal left to right reading order
239: acceptChild(visitor, getJavadoc());
240: acceptChildren(visitor, this .modifiers);
241: acceptChild(visitor, getName());
242: acceptChildren(visitor, this .bodyDeclarations);
243: }
244: visitor.endVisit(this );
245: }
246:
247: /* (omit javadoc for this method)
248: * Method declared on AsbtractTypeDeclaration.
249: */
250: ITypeBinding internalResolveBinding() {
251: return this .ast.getBindingResolver().resolveType(this );
252: }
253:
254: /* (omit javadoc for this method)
255: * Method declared on ASTNode.
256: */
257: int memSize() {
258: return super .memSize();
259: }
260:
261: /* (omit javadoc for this method)
262: * Method declared on ASTNode.
263: */
264: int treeSize() {
265: return memSize()
266: + (this .optionalDocComment == null ? 0 : getJavadoc()
267: .treeSize()) + this .modifiers.listSize()
268: + (this .typeName == null ? 0 : getName().treeSize())
269: + this.bodyDeclarations.listSize();
270: }
271: }
|