73a103f390e98fd0d727196a3d3c2b11c16fdd72
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / core / ImportDeclaration.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpdt.internal.core;
12
13 import net.sourceforge.phpdt.core.IImportDeclaration;
14 import net.sourceforge.phpdt.core.IJavaElement;
15 import net.sourceforge.phpdt.core.JavaModelException;
16 import net.sourceforge.phpdt.core.jdom.IDOMNode;
17
18 /**
19  * Handle for an import declaration. Info object is a
20  * ImportDeclarationElementInfo.
21  * 
22  * @see IImportDeclaration
23  */
24
25 /* package */class ImportDeclaration extends SourceRefElement implements
26                 IImportDeclaration {
27
28         /**
29          * Constructs an ImportDeclaration in the given import container with the
30          * given name.
31          */
32         protected ImportDeclaration(ImportContainer parent, String name) {
33                 super(parent, name);
34         }
35
36         public boolean equals(Object o) {
37                 if (!(o instanceof ImportDeclaration))
38                         return false;
39                 return super.equals(o);
40         }
41
42         /**
43          * @see JavaElement#equalsDOMNode
44          * @deprecated JDOM is obsolete
45          */
46         // TODO - JDOM - remove once model ported off of JDOM
47         protected boolean equalsDOMNode(IDOMNode node) {
48                 return (node.getNodeType() == IDOMNode.IMPORT)
49                                 && getElementName().equals(node.getName());
50         }
51
52         /**
53          * @see IJavaElement
54          */
55         public int getElementType() {
56                 return IMPORT_DECLARATION;
57         }
58
59         /**
60          * @see net.sourceforge.phpdt.core.IImportDeclaration#getFlags()
61          */
62         public int getFlags() throws JavaModelException {
63                 ImportDeclarationElementInfo info = (ImportDeclarationElementInfo) getElementInfo();
64                 return info.getModifiers();
65         }
66
67         /**
68          * @see JavaElement#getHandleMemento() For import declarations, the handle
69          *      delimiter is associated to the import container already
70          */
71         public String getHandleMemento() {
72                 StringBuffer buff = new StringBuffer(((JavaElement) getParent())
73                                 .getHandleMemento());
74                 escapeMementoName(buff, getElementName());
75                 if (this.occurrenceCount > 1) {
76                         buff.append(JEM_COUNT);
77                         buff.append(this.occurrenceCount);
78                 }
79                 return buff.toString();
80         }
81
82         /**
83          * @see JavaElement#getHandleMemento()
84          */
85         protected char getHandleMementoDelimiter() {
86                 // For import declarations, the handle delimiter is associated to the
87                 // import container already
88                 Assert.isTrue(false, "Should not be called"); //$NON-NLS-1$
89                 return 0;
90         }
91
92         /*
93          * @see JavaElement#getPrimaryElement(boolean)
94          */
95         public IJavaElement getPrimaryElement(boolean checkOwner) {
96                 CompilationUnit cu = (CompilationUnit) this.parent.getParent();
97                 if (checkOwner && cu.isPrimary())
98                         return this;
99                 return cu.getImport(this.name);
100         }
101
102         /**
103          * Returns true if the import is on-demand (ends with ".*")
104          */
105         public boolean isOnDemand() {
106                 return this.name.endsWith(".*"); //$NON-NLS-1$
107         }
108
109         /**
110          */
111         public String readableName() {
112
113                 return null;
114         }
115
116         /**
117          * @private Debugging purposes
118          */
119         protected void toStringInfo(int tab, StringBuffer buffer, Object info) {
120                 buffer.append(this.tabString(tab));
121                 buffer.append("include "); //$NON-NLS-1$
122                 toStringName(buffer);
123                 if (info == null) {
124                         buffer.append(" (not open)"); //$NON-NLS-1$
125                 }
126         }
127 }