1 /*******************************************************************************
2 * Copyright (c) 2000, 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 *******************************************************************************/
12 package net.sourceforge.phpdt.core.dom;
15 * Abstract base class for all AST nodes that represent names.
16 * There are exactly two kinds of name: simple ones
17 * (<code>SimpleName</code>) and qualified ones (<code>QualifiedName</code>).
27 * @noextend This class is not intended to be subclassed by clients.
29 public abstract class Name extends Expression implements IDocElement {
32 * Approximate base size of an expression node instance in bytes,
33 * including object header and instance fields.
35 static final int BASE_NAME_NODE_SIZE = BASE_NODE_SIZE + 1 * 4;
38 * This index represents the position inside a qualified name.
43 * Creates a new AST node for a name owned by the given AST.
45 * N.B. This constructor is package-private.
48 * @param ast the AST that is to own this node
55 * Returns whether this name is a simple name
56 * (<code>SimpleName</code>).
58 * @return <code>true</code> if this is a simple name, and
59 * <code>false</code> otherwise
61 public final boolean isSimpleName() {
62 return (this instanceof SimpleName);
66 * Returns whether this name is a qualified name
67 * (<code>QualifiedName</code>).
69 * @return <code>true</code> if this is a qualified name, and
70 * <code>false</code> otherwise
72 public final boolean isQualifiedName() {
73 return (this instanceof QualifiedName);
77 * Resolves and returns the binding for the entity referred to by this name.
79 * Note that bindings are generally unavailable unless requested when the
83 * @return the binding, or <code>null</code> if the binding cannot be
86 public final IBinding resolveBinding() {
87 return this.ast.getBindingResolver().resolveName(this);
91 * Returns the standard dot-separated representation of this name.
92 * If the name is a simple name, the result is the name's identifier.
93 * If the name is a qualified name, the result is the name of the qualifier
94 * (as computed by this method) followed by "." followed by the name's
97 * @return the fully qualified name
100 public final String getFullyQualifiedName() {
101 if (isSimpleName()) {
102 // avoid creating garbage for common case
103 return ((SimpleName) this).getIdentifier();
105 StringBuffer buffer = new StringBuffer(50);
107 return new String(buffer);
112 * Appends the standard representation of this name to the given string
115 * @param buffer the buffer
118 abstract void appendName(StringBuffer buffer);