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: * Marker annotation node (added in JLS3 API). The marker annotation
017: * "@foo" is equivalent to the normal annotation "@foo()".
018: * <p>
019: * <pre>
020: * MarkerAnnotation:
021: * <b>@</b> TypeName
022: * </pre>
023: * </p>
024: *
025: * @since 3.1
026: */
027: public final class MarkerAnnotation extends Annotation {
028:
029: /**
030: * The "typeName" structural property of this node type.
031: */
032: public static final ChildPropertyDescriptor TYPE_NAME_PROPERTY = internalTypeNamePropertyFactory(MarkerAnnotation.class);
033:
034: /**
035: * A list of property descriptors (element type:
036: * {@link StructuralPropertyDescriptor}),
037: * or null if uninitialized.
038: */
039: private static final List PROPERTY_DESCRIPTORS;
040:
041: static {
042: List propertyList = new ArrayList(2);
043: createPropertyList(MarkerAnnotation.class, propertyList);
044: addProperty(TYPE_NAME_PROPERTY, propertyList);
045: PROPERTY_DESCRIPTORS = reapPropertyList(propertyList);
046: }
047:
048: /**
049: * Returns a list of structural property descriptors for this node type.
050: * Clients must not modify the result.
051: *
052: * @param apiLevel the API level; one of the AST.JLS* constants
053: * @return a list of property descriptors (element type:
054: * {@link StructuralPropertyDescriptor})
055: */
056: public static List propertyDescriptors(int apiLevel) {
057: return PROPERTY_DESCRIPTORS;
058: }
059:
060: /**
061: * Creates a new unparented marker annotation node owned
062: * by the given AST. By default, the annotation has an
063: * unspecified type name .
064: * <p>
065: * N.B. This constructor is package-private.
066: * </p>
067: *
068: * @param ast the AST that is to own this node
069: */
070: MarkerAnnotation(AST ast) {
071: super (ast);
072: unsupportedIn2();
073: }
074:
075: /* (omit javadoc for this method)
076: * Method declared on ASTNode.
077: */
078: final List internalStructuralPropertiesForType(int apiLevel) {
079: return propertyDescriptors(apiLevel);
080: }
081:
082: /* (omit javadoc for this method)
083: * Method declared on ASTNode.
084: */
085: final ASTNode internalGetSetChildProperty(
086: ChildPropertyDescriptor property, boolean get, ASTNode child) {
087: if (property == TYPE_NAME_PROPERTY) {
088: if (get) {
089: return getTypeName();
090: } else {
091: setTypeName((Name) child);
092: return null;
093: }
094: }
095: // allow default implementation to flag the error
096: return super .internalGetSetChildProperty(property, get, child);
097: }
098:
099: /* (omit javadoc for this method)
100: * Method declared on BodyDeclaration.
101: */
102: final ChildPropertyDescriptor internalTypeNameProperty() {
103: return TYPE_NAME_PROPERTY;
104: }
105:
106: /* (omit javadoc for this method)
107: * Method declared on ASTNode.
108: */
109: final int getNodeType0() {
110: return MARKER_ANNOTATION;
111: }
112:
113: /* (omit javadoc for this method)
114: * Method declared on ASTNode.
115: */
116: ASTNode clone0(AST target) {
117: MarkerAnnotation result = new MarkerAnnotation(target);
118: result
119: .setSourceRange(this .getStartPosition(), this
120: .getLength());
121: result.setTypeName((Name) ASTNode.copySubtree(target,
122: getTypeName()));
123: return result;
124: }
125:
126: /* (omit javadoc for this method)
127: * Method declared on ASTNode.
128: */
129: final boolean subtreeMatch0(ASTMatcher matcher, Object other) {
130: // dispatch to correct overloaded match method
131: return matcher.match(this , other);
132: }
133:
134: /* (omit javadoc for this method)
135: * Method declared on ASTNode.
136: */
137: void accept0(ASTVisitor visitor) {
138: boolean visitChildren = visitor.visit(this );
139: if (visitChildren) {
140: // visit children in normal left to right reading order
141: acceptChild(visitor, getTypeName());
142: }
143: visitor.endVisit(this );
144: }
145:
146: /* (omit javadoc for this method)
147: * Method declared on ASTNode.
148: */
149: int memSize() {
150: return super .memSize();
151: }
152:
153: /* (omit javadoc for this method)
154: * Method declared on ASTNode.
155: */
156: int treeSize() {
157: return memSize()
158: + (this .typeName == null ? 0 : getTypeName().treeSize());
159: }
160: }
|