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