KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > core > dom > Name


1 /*******************************************************************************
2  * Copyright (c) 2000, 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
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.jdt.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  */

28 public abstract class Name extends Expression implements IDocElement {
29     
30     /**
31      * Approximate base size of an expression node instance in bytes,
32      * including object header and instance fields.
33      */

34     static final int BASE_NAME_NODE_SIZE = BASE_NODE_SIZE + 1 * 4;
35     
36     /**
37      * This index represents the position inside a qualified name.
38      */

39     int index;
40     
41     /**
42      * Creates a new AST node for a name owned by the given AST.
43      * <p>
44      * N.B. This constructor is package-private.
45      * </p>
46      *
47      * @param ast the AST that is to own this node
48      */

49     Name(AST ast) {
50         super(ast);
51     }
52     
53     /**
54      * Returns whether this name is a simple name
55      * (<code>SimpleName</code>).
56      *
57      * @return <code>true</code> if this is a simple name, and
58      * <code>false</code> otherwise
59      */

60     public final boolean isSimpleName() {
61         return (this instanceof SimpleName);
62     }
63         
64     /**
65      * Returns whether this name is a qualified name
66      * (<code>QualifiedName</code>).
67      *
68      * @return <code>true</code> if this is a qualified name, and
69      * <code>false</code> otherwise
70      */

71     public final boolean isQualifiedName() {
72         return (this instanceof QualifiedName);
73     }
74
75     /**
76      * Resolves and returns the binding for the entity referred to by this name.
77      * <p>
78      * Note that bindings are generally unavailable unless requested when the
79      * AST is being built.
80      * </p>
81      *
82      * @return the binding, or <code>null</code> if the binding cannot be
83      * resolved
84      */

85     public final IBinding resolveBinding() {
86         return this.ast.getBindingResolver().resolveName(this);
87     }
88     
89     /**
90      * Returns the standard dot-separated representation of this name.
91      * If the name is a simple name, the result is the name's identifier.
92      * If the name is a qualified name, the result is the name of the qualifier
93      * (as computed by this method) followed by "." followed by the name's
94      * identifier.
95      *
96      * @return the fully qualified name
97      * @since 3.0
98      */

99     public final String JavaDoc getFullyQualifiedName() {
100         if (isSimpleName()) {
101             // avoid creating garbage for common case
102
return ((SimpleName) this).getIdentifier();
103         } else {
104             StringBuffer JavaDoc buffer = new StringBuffer JavaDoc(50);
105             appendName(buffer);
106             return new String JavaDoc(buffer);
107         }
108     }
109
110     /**
111      * Appends the standard representation of this name to the given string
112      * buffer.
113      *
114      * @param buffer the buffer
115      * @since 3.0
116      */

117     abstract void appendName(StringBuffer JavaDoc buffer);
118 }
119
Popular Tags