improved PHP parser
[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.internal.core.Assert;
14 import net.sourceforge.phpdt.internal.core.JavaElement;
15
16 import net.sourceforge.phpdt.core.IImportDeclaration;
17 import net.sourceforge.phpdt.core.IJavaElement;
18 import net.sourceforge.phpdt.core.JavaModelException;
19 import net.sourceforge.phpdt.core.jdom.IDOMNode;
20
21 /**
22  * Handle for an import declaration. Info object is a ImportDeclarationElementInfo.
23  * @see IImportDeclaration
24  */
25
26 /* package */ class ImportDeclaration extends SourceRefElement implements IImportDeclaration {
27
28
29 /**
30  * Constructs an ImportDeclaration in the given import container
31  * with the given name.
32  */
33 protected ImportDeclaration(ImportContainer parent, String name) {
34         super(parent, name);
35 }
36 public boolean equals(Object o) {
37         if (!(o instanceof ImportDeclaration)) return false;
38         return super.equals(o);
39 }
40 /**
41  * @see JavaElement#equalsDOMNode
42  * @deprecated JDOM is obsolete
43  */
44 // TODO - JDOM - remove once model ported off of JDOM
45 protected boolean equalsDOMNode(IDOMNode node) {
46         return (node.getNodeType() == IDOMNode.IMPORT) && getElementName().equals(node.getName());
47 }
48 /**
49  * @see IJavaElement
50  */
51 public int getElementType() {
52         return IMPORT_DECLARATION;
53 }
54 /**
55  * @see net.sourceforge.phpdt.core.IImportDeclaration#getFlags()
56  */
57 public int getFlags() throws JavaModelException {
58         ImportDeclarationElementInfo info = (ImportDeclarationElementInfo)getElementInfo();
59         return info.getModifiers();
60 }
61 /**
62  * @see JavaElement#getHandleMemento()
63  * For import declarations, the handle delimiter is associated to the import container already
64  */
65 public String getHandleMemento(){
66         StringBuffer buff= new StringBuffer(((JavaElement)getParent()).getHandleMemento());
67         escapeMementoName(buff, getElementName());
68         if (this.occurrenceCount > 1) {
69                 buff.append(JEM_COUNT);
70                 buff.append(this.occurrenceCount);
71         }
72         return buff.toString();
73 }
74 /**
75  * @see JavaElement#getHandleMemento()
76  */
77 protected char getHandleMementoDelimiter() {
78         // For import declarations, the handle delimiter is associated to the import container already
79         Assert.isTrue(false, "Should not be called"); //$NON-NLS-1$
80         return 0;
81 }
82
83 /*
84  * @see JavaElement#getPrimaryElement(boolean)
85  */
86 public IJavaElement getPrimaryElement(boolean checkOwner) {
87         CompilationUnit cu = (CompilationUnit)this.parent.getParent();
88         if (checkOwner && cu.isPrimary()) return this;
89         return cu.getImport(this.name);
90 }
91 /**
92  * Returns true if the import is on-demand (ends with ".*")
93  */
94 public boolean isOnDemand() {
95         return this.name.endsWith(".*"); //$NON-NLS-1$
96 }
97 /**
98  */
99 public String readableName() {
100
101         return null;
102 }
103 /**
104  * @private Debugging purposes
105  */
106 protected void toStringInfo(int tab, StringBuffer buffer, Object info) {
107         buffer.append(this.tabString(tab));
108         buffer.append("include "); //$NON-NLS-1$
109         toStringName(buffer);
110         if (info == null) {
111                 buffer.append(" (not open)"); //$NON-NLS-1$
112         }
113 }
114 }