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: * Normal annotation node (added in JLS3 API).
017: * <p>
018: * <pre>
019: * NormalAnnotation:
020: * <b>@</b> TypeName <b>(</b> [ MemberValuePair { <b>,</b> MemberValuePair } ] <b>)</b>
021: * </pre>
022: * </p>
023: *
024: * @since 3.1
025: */
026: public final class NormalAnnotation extends Annotation {
027:
028: /**
029: * The "typeName" structural property of this node type.
030: */
031: public static final ChildPropertyDescriptor TYPE_NAME_PROPERTY = internalTypeNamePropertyFactory(NormalAnnotation.class);
032:
033: /**
034: * The "values" structural property of this node type.
035: */
036: public static final ChildListPropertyDescriptor VALUES_PROPERTY = new ChildListPropertyDescriptor(
037: NormalAnnotation.class,
038: "values", MemberValuePair.class, CYCLE_RISK); //$NON-NLS-1$
039:
040: /**
041: * A list of property descriptors (element type:
042: * {@link StructuralPropertyDescriptor}),
043: * or null if uninitialized.
044: */
045: private static final List PROPERTY_DESCRIPTORS;
046:
047: static {
048: List propertyList = new ArrayList(3);
049: createPropertyList(NormalAnnotation.class, propertyList);
050: addProperty(TYPE_NAME_PROPERTY, propertyList);
051: addProperty(VALUES_PROPERTY, propertyList);
052: PROPERTY_DESCRIPTORS = reapPropertyList(propertyList);
053: }
054:
055: /**
056: * Returns a list of structural property descriptors for this node type.
057: * Clients must not modify the result.
058: *
059: * @param apiLevel the API level; one of the AST.JLS* constants
060: * @return a list of property descriptors (element type:
061: * {@link StructuralPropertyDescriptor})
062: */
063: public static List propertyDescriptors(int apiLevel) {
064: return PROPERTY_DESCRIPTORS;
065: }
066:
067: /**
068: * The list of member value pairs (element type:
069: * <code MemberValuePair</code>). Defaults to an empty list.
070: */
071: private ASTNode.NodeList values = new ASTNode.NodeList(
072: VALUES_PROPERTY);
073:
074: /**
075: * Creates a new unparented normal annotation node owned
076: * by the given AST. By default, the annotation has an
077: * unspecified type name and an empty list of member value
078: * pairs.
079: * <p>
080: * N.B. This constructor is package-private.
081: * </p>
082: *
083: * @param ast the AST that is to own this node
084: */
085: NormalAnnotation(AST ast) {
086: super (ast);
087: unsupportedIn2();
088: }
089:
090: /* (omit javadoc for this method)
091: * Method declared on ASTNode.
092: */
093: final List internalStructuralPropertiesForType(int apiLevel) {
094: return propertyDescriptors(apiLevel);
095: }
096:
097: /* (omit javadoc for this method)
098: * Method declared on ASTNode.
099: */
100: final ASTNode internalGetSetChildProperty(
101: 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 internalGetChildListProperty(
118: ChildListPropertyDescriptor property) {
119: if (property == VALUES_PROPERTY) {
120: return values();
121: }
122: // allow default implementation to flag the error
123: return super .internalGetChildListProperty(property);
124: }
125:
126: /* (omit javadoc for this method)
127: * Method declared on BodyDeclaration.
128: */
129: final ChildPropertyDescriptor internalTypeNameProperty() {
130: return TYPE_NAME_PROPERTY;
131: }
132:
133: /* (omit javadoc for this method)
134: * Method declared on ASTNode.
135: */
136: final int getNodeType0() {
137: return NORMAL_ANNOTATION;
138: }
139:
140: /* (omit javadoc for this method)
141: * Method declared on ASTNode.
142: */
143: ASTNode clone0(AST target) {
144: NormalAnnotation result = new NormalAnnotation(target);
145: result
146: .setSourceRange(this .getStartPosition(), this
147: .getLength());
148: result.setTypeName((Name) ASTNode.copySubtree(target,
149: getTypeName()));
150: result.values().addAll(ASTNode.copySubtrees(target, values()));
151: return result;
152: }
153:
154: /* (omit javadoc for this method)
155: * Method declared on ASTNode.
156: */
157: final boolean subtreeMatch0(ASTMatcher matcher, Object other) {
158: // dispatch to correct overloaded match method
159: return matcher.match(this , other);
160: }
161:
162: /* (omit javadoc for this method)
163: * Method declared on ASTNode.
164: */
165: void accept0(ASTVisitor visitor) {
166: boolean visitChildren = visitor.visit(this );
167: if (visitChildren) {
168: // visit children in normal left to right reading order
169: acceptChild(visitor, getTypeName());
170: acceptChildren(visitor, this .values);
171: }
172: visitor.endVisit(this );
173: }
174:
175: /**
176: * Returns the live list of member value pairs in this annotation.
177: * Adding and removing nodes from this list affects this node
178: * dynamically. All nodes in this list must be
179: * {@link MemberValuePair}s; attempts to add any other
180: * type of node will trigger an exception.
181: *
182: * @return the live list of member value pairs in this
183: * annotation (element type: <code>MemberValuePair</code>)
184: */
185: public List values() {
186: return this .values;
187: }
188:
189: /* (omit javadoc for this method)
190: * Method declared on ASTNode.
191: */
192: int memSize() {
193: return super .memSize() + 1 * 4;
194: }
195:
196: /* (omit javadoc for this method)
197: * Method declared on ASTNode.
198: */
199: int treeSize() {
200: return memSize()
201: + (this .typeName == null ? 0 : getTypeName().treeSize())
202: + this.values.listSize();
203: }
204: }
|