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