KickJava   Java API By Example, From Geeks To Geeks.

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


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  * Normal annotation node (added in JLS3 API).
18  * <p>
19  * <pre>
20  * NormalAnnotation:
21  * <b>@</b> TypeName <b>(</b> [ MemberValuePair { <b>,</b> MemberValuePair } ] <b>)</b>
22  * </pre>
23  * </p>
24  *
25  * @since 3.1
26  */

27 public final class NormalAnnotation extends Annotation {
28     
29     /**
30      * The "typeName" structural property of this node type.
31      */

32     public static final ChildPropertyDescriptor TYPE_NAME_PROPERTY =
33         internalTypeNamePropertyFactory(NormalAnnotation.class);
34
35     /**
36      * The "values" structural property of this node type.
37      */

38     public static final ChildListPropertyDescriptor VALUES_PROPERTY =
39         new ChildListPropertyDescriptor(NormalAnnotation.class, "values", MemberValuePair.class, CYCLE_RISK); //$NON-NLS-1$
40

41     /**
42      * A list of property descriptors (element type:
43      * {@link StructuralPropertyDescriptor}),
44      * or null if uninitialized.
45      */

46     private static final List JavaDoc PROPERTY_DESCRIPTORS;
47     
48     static {
49         List JavaDoc propertyList = new ArrayList JavaDoc(3);
50         createPropertyList(NormalAnnotation.class, propertyList);
51         addProperty(TYPE_NAME_PROPERTY, propertyList);
52         addProperty(VALUES_PROPERTY, propertyList);
53         PROPERTY_DESCRIPTORS = reapPropertyList(propertyList);
54     }
55     
56     /**
57      * Returns a list of structural property descriptors for this node type.
58      * Clients must not modify the result.
59      *
60      * @param apiLevel the API level; one of the AST.JLS* constants
61      * @return a list of property descriptors (element type:
62      * {@link StructuralPropertyDescriptor})
63      */

64     public static List JavaDoc propertyDescriptors(int apiLevel) {
65         return PROPERTY_DESCRIPTORS;
66     }
67     
68     /**
69      * The list of member value pairs (element type:
70      * <code MemberValuePair</code>). Defaults to an empty list.
71      */

72     private ASTNode.NodeList values =
73         new ASTNode.NodeList(VALUES_PROPERTY);
74
75     /**
76      * Creates a new unparented normal annotation node owned
77      * by the given AST. By default, the annotation has an
78      * unspecified type name and an empty list of member value
79      * pairs.
80      * <p>
81      * N.B. This constructor is package-private.
82      * </p>
83      *
84      * @param ast the AST that is to own this node
85      */

86     NormalAnnotation(AST ast) {
87         super(ast);
88         unsupportedIn2();
89     }
90
91     /* (omit javadoc for this method)
92      * Method declared on ASTNode.
93      */

94     final List JavaDoc internalStructuralPropertiesForType(int apiLevel) {
95         return propertyDescriptors(apiLevel);
96     }
97     
98     /* (omit javadoc for this method)
99      * Method declared on ASTNode.
100      */

101     final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) {
102         if (property == TYPE_NAME_PROPERTY) {
103             if (get) {
104                 return getTypeName();
105             } else {
106                 setTypeName((Name) child);
107                 return null;
108             }
109         }
110         // allow default implementation to flag the error
111
return super.internalGetSetChildProperty(property, get, child);
112     }
113     
114     /* (omit javadoc for this method)
115      * Method declared on ASTNode.
116      */

117     final List JavaDoc internalGetChildListProperty(ChildListPropertyDescriptor property) {
118         if (property == VALUES_PROPERTY) {
119             return values();
120         }
121         // allow default implementation to flag the error
122
return super.internalGetChildListProperty(property);
123     }
124
125     /* (omit javadoc for this method)
126      * Method declared on BodyDeclaration.
127      */

128     final ChildPropertyDescriptor internalTypeNameProperty() {
129         return TYPE_NAME_PROPERTY;
130     }
131
132     /* (omit javadoc for this method)
133      * Method declared on ASTNode.
134      */

135     final int getNodeType0() {
136         return NORMAL_ANNOTATION;
137     }
138
139     /* (omit javadoc for this method)
140      * Method declared on ASTNode.
141      */

142     ASTNode clone0(AST target) {
143         NormalAnnotation result = new NormalAnnotation(target);
144         result.setSourceRange(this.getStartPosition(), this.getLength());
145         result.setTypeName((Name) ASTNode.copySubtree(target, getTypeName()));
146         result.values().addAll(ASTNode.copySubtrees(target, values()));
147         return result;
148     }
149     
150     /* (omit javadoc for this method)
151      * Method declared on ASTNode.
152      */

153     final boolean subtreeMatch0(ASTMatcher matcher, Object JavaDoc other) {
154         // dispatch to correct overloaded match method
155
return matcher.match(this, other);
156     }
157     
158     /* (omit javadoc for this method)
159      * Method declared on ASTNode.
160      */

161     void accept0(ASTVisitor visitor) {
162         boolean visitChildren = visitor.visit(this);
163         if (visitChildren) {
164             // visit children in normal left to right reading order
165
acceptChild(visitor, getTypeName());
166             acceptChildren(visitor, this.values);
167         }
168         visitor.endVisit(this);
169     }
170     
171     /**
172      * Returns the live list of member value pairs in this annotation.
173      * Adding and removing nodes from this list affects this node
174      * dynamically. All nodes in this list must be
175      * {@link MemberValuePair}s; attempts to add any other
176      * type of node will trigger an exception.
177      *
178      * @return the live list of member value pairs in this
179      * annotation (element type: <code>MemberValuePair</code>)
180      */

181     public List JavaDoc values() {
182         return this.values;
183     }
184         
185     /* (omit javadoc for this method)
186      * Method declared on ASTNode.
187      */

188     int memSize() {
189         return super.memSize() + 1 * 4;
190     }
191     
192     /* (omit javadoc for this method)
193      * Method declared on ASTNode.
194      */

195     int treeSize() {
196         return
197             memSize()
198             + (this.typeName == null ? 0 : getTypeName().treeSize())
199             + this.values.listSize();
200     }
201 }
202
Popular Tags