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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.internal.core;
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;
18 //import net.sourceforge.phpdt.internal.corext.Assert;
19 import org.eclipse.core.runtime.Assert;
22 * Handle for an import declaration. Info object is a
23 * ImportDeclarationElementInfo.
25 * @see IImportDeclaration
28 /* package */class ImportDeclaration extends SourceRefElement implements
32 * Constructs an ImportDeclaration in the given import container with the
35 protected ImportDeclaration(ImportContainer parent, String name) {
39 public boolean equals(Object o) {
40 if (!(o instanceof ImportDeclaration))
42 return super.equals(o);
46 * @see JavaElement#equalsDOMNode
47 * @deprecated JDOM is obsolete
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());
58 public int getElementType() {
59 return IMPORT_DECLARATION;
63 * @see net.sourceforge.phpdt.core.IImportDeclaration#getFlags()
65 public int getFlags() throws JavaModelException {
66 ImportDeclarationElementInfo info = (ImportDeclarationElementInfo) getElementInfo();
67 return info.getModifiers();
71 * @see JavaElement#getHandleMemento() For import declarations, the handle
72 * delimiter is associated to the import container already
74 public String getHandleMemento() {
75 StringBuffer buff = new StringBuffer(((JavaElement) getParent())
77 escapeMementoName(buff, getElementName());
78 if (this.occurrenceCount > 1) {
79 buff.append(JEM_COUNT);
80 buff.append(this.occurrenceCount);
82 return buff.toString();
86 * @see JavaElement#getHandleMemento()
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$
96 * @see JavaElement#getPrimaryElement(boolean)
98 public IJavaElement getPrimaryElement(boolean checkOwner) {
99 CompilationUnit cu = (CompilationUnit) this.parent.getParent();
100 if (checkOwner && cu.isPrimary())
102 return cu.getImport(this.name);
106 * Returns true if the import is on-demand (ends with ".*")
108 public boolean isOnDemand() {
109 return this.name.endsWith(".*"); //$NON-NLS-1$
114 public String readableName() {
120 * @private Debugging purposes
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);
127 buffer.append(" (not open)"); //$NON-NLS-1$