removed unused private methods.
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / core / dom / Name.java
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
7  *
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11
12 package net.sourceforge.phpdt.core.dom;
13
14 /**
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>).
18  * <p>
19  * <pre>
20  * Name:
21  *     SimpleName
22  *     QualifiedName
23  * </pre>
24  * </p>
25  * 
26  * @since 2.0
27  * @noextend This class is not intended to be subclassed by clients.
28  */
29 public abstract class Name extends Expression implements IDocElement {
30         
31         /**
32          * Approximate base size of an expression node instance in bytes, 
33          * including object header and instance fields.
34          */
35         static final int BASE_NAME_NODE_SIZE = BASE_NODE_SIZE + 1 * 4;
36         
37         /**
38          * This index represents the position inside a qualified name.
39          */
40         int index;
41         
42         /**
43          * Creates a new AST node for a name owned by the given AST.
44          * <p>
45          * N.B. This constructor is package-private.
46          * </p>
47          * 
48          * @param ast the AST that is to own this node
49          */
50         Name(AST ast) {
51                 super(ast);
52         }
53         
54         /**
55          * Returns whether this name is a simple name
56          * (<code>SimpleName</code>).
57          * 
58          * @return <code>true</code> if this is a simple name, and 
59          *    <code>false</code> otherwise
60          */
61         public final boolean isSimpleName() {
62                 return (this instanceof SimpleName);
63         }
64                 
65         /**
66          * Returns whether this name is a qualified name
67          * (<code>QualifiedName</code>).
68          * 
69          * @return <code>true</code> if this is a qualified name, and 
70          *    <code>false</code> otherwise
71          */
72         public final boolean isQualifiedName() {
73                 return (this instanceof QualifiedName);
74         }
75
76         /**
77          * Resolves and returns the binding for the entity referred to by this name.
78          * <p>
79          * Note that bindings are generally unavailable unless requested when the
80          * AST is being built.
81          * </p>
82          * 
83          * @return the binding, or <code>null</code> if the binding cannot be 
84          *    resolved
85          */     
86         public final IBinding resolveBinding() {
87                 return this.ast.getBindingResolver().resolveName(this);
88         }
89         
90         /**
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
95          * identifier.
96          * 
97          * @return the fully qualified name
98          * @since 3.0
99          */
100         public final String getFullyQualifiedName() {
101                 if (isSimpleName()) {
102                         // avoid creating garbage for common case
103                         return ((SimpleName) this).getIdentifier();
104                 } else {
105                         StringBuffer buffer = new StringBuffer(50);
106                         appendName(buffer);
107                         return new String(buffer);
108                 }
109         }
110
111         /**
112          * Appends the standard representation of this name to the given string
113          * buffer.
114          * 
115          * @param buffer the buffer
116          * @since 3.0
117          */
118         abstract void appendName(StringBuffer buffer);  
119 }