org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/AbstractTypeDeclaration.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.19 - (download) (annotate)
Sat Mar 7 01:08:09 2009 UTC (8 months, 3 weeks ago) by oliviert
Branch: MAIN
CVS Tags: v_943, v_942, v_974_R35x, v_969_R35x, v_A03, v_A02, v_A01, v_A00, v_A07, v_A06, v_A05, v_A04, v_A09, v_A08, v_968_R35x, v_958, v_959, v_950, v_951, v_952, v_953, v_954, v_955, v_956, v_957, v_971_R35x, v_978_R35x, v_961, v_960, v_963, v_962, v_964_R35x, v_977_R35x, R3_5, v_A18, v_A19, v_A14, v_A15, v_A16, v_A10, v_A11, v_A12, v_A13, v_966_R35x, v_970_R35x, v_A21, v_A20, v_A23, v_A22, v_975_R35x, v_976_R35x, v_967_R35x, v_965_R35x, v_A21d, v_A21a, jsr308_A22, v_972_R35x, v_949, v_948, v_947, v_946, v_945, v_944, R3_5_1, v_A17b, v_A17c, v_973_R35x, HEAD
Branch point for: JSR_308, R3_5_maintenance
Changes since 1.18: +1 -1 lines
HEAD - Fix copyrights
/*******************************************************************************
 * Copyright (c) 2004, 2009 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.jdt.core.dom;

import java.util.List;

/**
 * Abstract subclass for type declaration, enum declaration,
 * and annotation type declaration AST node types.
 * <pre>
 * AbstractTypeDeclaration:
 * 		TypeDeclaration
 * 		EnumDeclaration
 * 		AnnotationTypeDeclaration
 * </pre>
 *
 * @since 3.0
 */
public abstract class AbstractTypeDeclaration extends BodyDeclaration {

	/**
	 * The type name; lazily initialized; defaults to a unspecified,
	 * legal Java class identifier.
	 * @since 2.0 (originally declared on <code>TypeDeclaration</code>)
	 */
	SimpleName typeName = null;

	/**
	 * The body declarations (element type: <code>BodyDeclaration</code>).
	 * Defaults to an empty list.
	 * @since 2.0 (originally declared on <code>TypeDeclaration</code>)
	 */
	ASTNode.NodeList bodyDeclarations;

	/**
	 * Returns structural property descriptor for the "bodyDeclarations" property
	 * of this node.
	 *
	 * @return the property descriptor
	 */
	abstract ChildListPropertyDescriptor internalBodyDeclarationsProperty();

	/**
	 * Returns structural property descriptor for the "bodyDeclarations" property
	 * of this node.
	 *
	 * @return the property descriptor
	 * @since 3.1
	 */
	public final ChildListPropertyDescriptor getBodyDeclarationsProperty() {
		return internalBodyDeclarationsProperty();
	}

	/**
	 * Returns structural property descriptor for the "name" property
	 * of this node.
	 *
	 * @return the property descriptor
	 */
	abstract ChildPropertyDescriptor internalNameProperty();

	/**
	 * Returns structural property descriptor for the "name" property
	 * of this node.
	 *
	 * @return the property descriptor
	 * @since 3.1
	 */
	public final ChildPropertyDescriptor getNameProperty() {
		return internalNameProperty();
	}

	/**
	 * Creates and returns a structural property descriptor for the
	 * "bodyDeclaration" property declared on the given concrete node type.
	 *
	 * @return the property descriptor
	 */
	static final ChildListPropertyDescriptor internalBodyDeclarationPropertyFactory(Class nodeClass) {
		return new ChildListPropertyDescriptor(nodeClass, "bodyDeclarations", BodyDeclaration.class, CYCLE_RISK); //$NON-NLS-1$
	}

	/**
	 * Creates and returns a structural property descriptor for the
	 * "name" property declared on the given concrete node type.
	 *
	 * @return the property descriptor
	 */
	static final ChildPropertyDescriptor internalNamePropertyFactory(Class nodeClass) {
		return new ChildPropertyDescriptor(nodeClass, "name", SimpleName.class, MANDATORY, NO_CYCLE_RISK); //$NON-NLS-1$
	}

	/**
	 * Creates a new AST node for an abstract type declaration owned by the given
	 * AST.
	 * <p>
	 * N.B. This constructor is package-private; all subclasses must be
	 * declared in the same package; clients are unable to declare
	 * additional subclasses.
	 * </p>
	 *
	 * @param ast the AST that is to own this node
	 */
	AbstractTypeDeclaration(AST ast) {
		super(ast);
		this.bodyDeclarations = new ASTNode.NodeList(internalBodyDeclarationsProperty());
	}

	/**
	 * Returns the name of the type declared in this type declaration.
	 *
	 * @return the type name node
	 * @since 2.0 (originally declared on <code>TypeDeclaration</code>)
	 */
	public SimpleName getName() {
		if (this.typeName == null) {
			// lazy init must be thread-safe for readers
			synchronized (this) {
				if (this.typeName == null) {
					preLazyInit();
					this.typeName = new SimpleName(this.ast);
					postLazyInit(this.typeName, internalNameProperty());
				}
			}
		}
		return this.typeName;
	}

	/**
	 * Sets the name of the type declared in this type declaration to the
	 * given name.
	 *
	 * @param typeName the new type name
	 * @exception IllegalArgumentException if:
	 * <ul>
	 * <li>the node belongs to a different AST</li>
	 * <li>the node already has a parent</li>
	 * </ul>
	 * @since 2.0 (originally declared on <code>TypeDeclaration</code>)
	 */
	public void setName(SimpleName typeName) {
		if (typeName == null) {
			throw new IllegalArgumentException();
		}
		ChildPropertyDescriptor p = internalNameProperty();
		ASTNode oldChild = this.typeName;
		preReplaceChild(oldChild, typeName, p);
		this.typeName = typeName;
		postReplaceChild(oldChild, typeName, p);
	}

	/**
	 * Returns the live ordered list of body declarations of this type
	 * declaration.
	 *
	 * @return the live list of body declarations
	 *    (element type: <code>BodyDeclaration</code>)
	 * @since 2.0 (originally declared on <code>TypeDeclaration</code>)
	 */
	public List bodyDeclarations() {
		return this.bodyDeclarations;
	}

	/**
	 * Returns whether this type declaration is a package member (that is,
	 * a top-level type).
	 * <p>
	 * Note that this is a convenience method that simply checks whether
	 * this node's parent is a compilation unit node.
	 * </p>
	 *
	 * @return <code>true</code> if this type declaration is a child of
	 *   a compilation unit node, and <code>false</code> otherwise
	 * @since 2.0 (originally declared on <code>TypeDeclaration</code>)
	 */
	public boolean isPackageMemberTypeDeclaration() {
		ASTNode parent = getParent();
		return (parent instanceof CompilationUnit);
	}

	/**
	 * Returns whether this type declaration is a type member.
	 * <p>
	 * Note that this is a convenience method that simply checks whether
	 * this node's parent is a type declaration node or an anonymous
	 * class declaration.
	 * </p>
	 *
	 * @return <code>true</code> if this type declaration is a child of
	 *   a type declaration node or an anonymous class declaration node,
	 *   and <code>false</code> otherwise
	 * @since 2.0 (originally declared on <code>TypeDeclaration</code>)
	 */
	public boolean isMemberTypeDeclaration() {
		ASTNode parent = getParent();
		return (parent instanceof AbstractTypeDeclaration)
			|| (parent instanceof AnonymousClassDeclaration);
	}

	/**
	 * Returns whether this type declaration is a local type.
	 * <p>
	 * Note that this is a convenience method that simply checks whether
	 * this node's parent is a type declaration statement node.
	 * </p>
	 *
	 * @return <code>true</code> if this type declaration is a child of
	 *   a type declaration statement node, and <code>false</code> otherwise
	 * @since 2.0 (originally declared on <code>TypeDeclaration</code>)
	 */
	public boolean isLocalTypeDeclaration() {
		ASTNode parent = getParent();
		return (parent instanceof TypeDeclarationStatement);
	}

	/**
	 * Resolves and returns the binding for the type declared in this type
	 * declaration.
	 * <p>
	 * Note that bindings are generally unavailable unless requested when the
	 * AST is being built.
	 * </p>
	 *
	 * @return the binding, or <code>null</code> if the binding cannot be
	 *    resolved
	 * @since 3.1 Declared in 3.0 on the individual subclasses.
	 */
	public final ITypeBinding resolveBinding() {
		return internalResolveBinding();
	}

	/**
	 * Resolves and returns the binding for the type declared in this type
	 * declaration. This method must be implemented by subclasses.
	 *
	 * @return the binding, or <code>null</code> if the binding cannot be
	 *    resolved
	 */
	abstract ITypeBinding internalResolveBinding();

	/* (omit javadoc for this method)
	 * Method declared on ASTNode.
	 */
	int memSize() {
		return super.memSize() + 2 * 4;
	}

}