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 * Normal annotation node (added in JLS3 API).
21 * <b>@</b> TypeName <b>(</b> [ MemberValuePair { <b>,</b> MemberValuePair } ] <b>)</b>
26 * @noinstantiate This class is not intended to be instantiated by clients.
28 public final class NormalAnnotation extends Annotation {
31 * The "typeName" structural property of this node type.
33 public static final ChildPropertyDescriptor TYPE_NAME_PROPERTY =
34 internalTypeNamePropertyFactory(NormalAnnotation.class);
37 * The "values" structural property of this node type.
39 public static final ChildListPropertyDescriptor VALUES_PROPERTY =
40 new ChildListPropertyDescriptor(NormalAnnotation.class, "values", MemberValuePair.class, CYCLE_RISK); //$NON-NLS-1$
43 * A list of property descriptors (element type:
44 * {@link StructuralPropertyDescriptor}),
45 * or null if uninitialized.
47 private static final List PROPERTY_DESCRIPTORS;
50 List propertyList = new ArrayList(3);
51 createPropertyList(NormalAnnotation.class, propertyList);
52 addProperty(TYPE_NAME_PROPERTY, propertyList);
53 addProperty(VALUES_PROPERTY, propertyList);
54 PROPERTY_DESCRIPTORS = reapPropertyList(propertyList);
58 * Returns a list of structural property descriptors for this node type.
59 * Clients must not modify the result.
61 * @param apiLevel the API level; one of the AST.JLS* constants
62 * @return a list of property descriptors (element type:
63 * {@link StructuralPropertyDescriptor})
65 public static List propertyDescriptors(int apiLevel) {
66 return PROPERTY_DESCRIPTORS;
70 * The list of member value pairs (element type:
71 * <code MemberValuePair</code>). Defaults to an empty list.
73 private ASTNode.NodeList values =
74 new ASTNode.NodeList(VALUES_PROPERTY);
77 * Creates a new unparented normal annotation node owned
78 * by the given AST. By default, the annotation has an
79 * unspecified type name and an empty list of member value
82 * N.B. This constructor is package-private.
85 * @param ast the AST that is to own this node
87 NormalAnnotation(AST ast) {
92 /* (omit javadoc for this method)
93 * Method declared on ASTNode.
95 final List internalStructuralPropertiesForType(int apiLevel) {
96 return propertyDescriptors(apiLevel);
99 /* (omit javadoc for this method)
100 * Method declared on ASTNode.
102 final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) {
103 if (property == TYPE_NAME_PROPERTY) {
105 return getTypeName();
107 setTypeName((Name) child);
111 // allow default implementation to flag the error
112 return super.internalGetSetChildProperty(property, get, child);
115 /* (omit javadoc for this method)
116 * Method declared on ASTNode.
118 final List internalGetChildListProperty(ChildListPropertyDescriptor property) {
119 if (property == VALUES_PROPERTY) {
122 // allow default implementation to flag the error
123 return super.internalGetChildListProperty(property);
126 /* (omit javadoc for this method)
127 * Method declared on BodyDeclaration.
129 final ChildPropertyDescriptor internalTypeNameProperty() {
130 return TYPE_NAME_PROPERTY;
133 /* (omit javadoc for this method)
134 * Method declared on ASTNode.
136 final int getNodeType0() {
137 return NORMAL_ANNOTATION;
140 /* (omit javadoc for this method)
141 * Method declared on ASTNode.
143 ASTNode clone0(AST target) {
144 NormalAnnotation result = new NormalAnnotation(target);
145 result.setSourceRange(this.getStartPosition(), this.getLength());
146 result.setTypeName((Name) ASTNode.copySubtree(target, getTypeName()));
147 result.values().addAll(ASTNode.copySubtrees(target, values()));
151 /* (omit javadoc for this method)
152 * Method declared on ASTNode.
154 final boolean subtreeMatch0(ASTMatcher matcher, Object other) {
155 // dispatch to correct overloaded match method
156 return matcher.match(this, other);
159 /* (omit javadoc for this method)
160 * Method declared on ASTNode.
162 void accept0(ASTVisitor visitor) {
163 boolean visitChildren = visitor.visit(this);
165 // visit children in normal left to right reading order
166 acceptChild(visitor, getTypeName());
167 acceptChildren(visitor, this.values);
169 visitor.endVisit(this);
173 * Returns the live list of member value pairs in this annotation.
174 * Adding and removing nodes from this list affects this node
175 * dynamically. All nodes in this list must be
176 * {@link MemberValuePair}s; attempts to add any other
177 * type of node will trigger an exception.
179 * @return the live list of member value pairs in this
180 * annotation (element type: <code>MemberValuePair</code>)
182 public List values() {
186 /* (omit javadoc for this method)
187 * Method declared on ASTNode.
190 return super.memSize() + 1 * 4;
193 /* (omit javadoc for this method)
194 * Method declared on ASTNode.
199 + (this.typeName == null ? 0 : getTypeName().treeSize())
200 + this.values.listSize();