1 /*******************************************************************************
2 * Copyright (c) 2004, 2006 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;
14 * Abstract base class of AST nodes that represent annotations.
20 * SingleMemberAnnotation
25 public abstract class Annotation extends Expression implements IExtendedModifier {
28 * Returns structural property descriptor for the "typeName" property
31 * @return the property descriptor
33 abstract ChildPropertyDescriptor internalTypeNameProperty();
36 * Returns structural property descriptor for the "typeName" property
39 * @return the property descriptor
41 public final ChildPropertyDescriptor getTypeNameProperty() {
42 return internalTypeNameProperty();
46 * Creates and returns a structural property descriptor for the
47 * "typeName" property declared on the given concrete node type.
49 * @return the property descriptor
51 static final ChildPropertyDescriptor internalTypeNamePropertyFactory(Class nodeClass) {
52 return new ChildPropertyDescriptor(nodeClass, "typeName", Name.class, MANDATORY, NO_CYCLE_RISK); //$NON-NLS-1$
56 * The annotation type name; lazily initialized; defaults to an unspecified,
57 * legal Java identifier.
62 * Creates a new AST node for an annotation node owned by the
65 * N.B. This constructor is package-private.
68 * @param ast the AST that is to own this node
75 * @see IExtendedModifier#isModifier()
77 public boolean isModifier() {
82 * @see IExtendedModifier#isAnnotation()
84 public boolean isAnnotation() {
89 * Returns the annotation type name of this annotation.
91 * @return the annotation type name
93 public Name getTypeName() {
94 if (this.typeName == null) {
95 // lazy init must be thread-safe for readers
97 if (this.typeName == null) {
99 this.typeName = new SimpleName(this.ast);
100 postLazyInit(this.typeName, internalTypeNameProperty());
104 return this.typeName;
108 * Sets the annotation type name of this annotation.
110 * @param typeName the annotation type name
111 * @exception IllegalArgumentException if:
113 * <li>the node belongs to a different AST</li>
114 * <li>the node already has a parent</li>
117 public void setTypeName(Name typeName) {
118 if (typeName == null) {
119 throw new IllegalArgumentException();
121 ChildPropertyDescriptor p = internalTypeNameProperty();
122 ASTNode oldChild = this.typeName;
123 preReplaceChild(oldChild, typeName, p);
124 this.typeName = typeName;
125 postReplaceChild(oldChild, typeName, p);
129 * Returns whether this is a normal annotation
130 * ({@link NormalAnnotation}).
132 * @return <code>true</code> if this is a normal annotation,
133 * and <code>false</code> otherwise
135 public boolean isNormalAnnotation() {
136 return (this instanceof NormalAnnotation);
140 * Returns whether this is a marker annotation
141 * ({@link MarkerAnnotation}).
143 * @return <code>true</code> if this is a marker annotation,
144 * and <code>false</code> otherwise
146 public boolean isMarkerAnnotation() {
147 return (this instanceof MarkerAnnotation);
151 * Returns whether this is a single member annotation.
152 * ({@link SingleMemberAnnotation}).
154 * @return <code>true</code> if this is a single member annotation,
155 * and <code>false</code> otherwise
157 public boolean isSingleMemberAnnotation() {
158 return (this instanceof SingleMemberAnnotation);
161 /* (omit javadoc for this method)
162 * Method declared on ASTNode.
165 return BASE_NODE_SIZE + 1 * 4;
169 * Resolves and returns the resolved annotation for this annotation.
171 * Note that bindings (which includes resolved annotations) are generally unavailable unless
172 * requested when the AST is being built.
175 * @return the resolved annotation, or <code>null</code> if the annotation cannot be resolved
178 public IAnnotationBinding resolveAnnotationBinding() {
179 return this.ast.getBindingResolver().resolveAnnotation(this);