Organized imports
[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 net.sourceforge.phpdt.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 /*
81  * @see JavaElement#getPrimaryElement(boolean)
82  */
83 public IJavaElement getPrimaryElement(boolean checkOwner) {
84         CompilationUnit cu = (CompilationUnit)this.parent.getParent();
85         if (checkOwner && cu.isPrimary()) return this;
86         return cu.getImport(this.name);
87 }
88 /**
89  * Returns true if the import is on-demand (ends with ".*")
90  */
91 public boolean isOnDemand() {
92         return this.name.endsWith(".*"); //$NON-NLS-1$
93 }
94 /**
95  */
96 public String readableName() {
97
98         return null;
99 }
100 /**
101  * @private Debugging purposes
102  */
103 protected void toStringInfo(int tab, StringBuffer buffer, Object info) {
104         buffer.append(this.tabString(tab));
105         buffer.append("include "); //$NON-NLS-1$
106         toStringName(buffer);
107         if (info == null) {
108                 buffer.append(" (not open)"); //$NON-NLS-1$
109         }
110 }
111 }