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;
19 * Handle for an import declaration. Info object is a
20 * ImportDeclarationElementInfo.
22 * @see IImportDeclaration
25 /* package */class ImportDeclaration extends SourceRefElement implements
29 * Constructs an ImportDeclaration in the given import container with the
32 protected ImportDeclaration(ImportContainer parent, String name) {
36 public boolean equals(Object o) {
37 if (!(o instanceof ImportDeclaration))
39 return super.equals(o);
43 * @see JavaElement#equalsDOMNode
44 * @deprecated JDOM is obsolete
46 // TODO - JDOM - remove once model ported off of JDOM
47 protected boolean equalsDOMNode(IDOMNode node) {
48 return (node.getNodeType() == IDOMNode.IMPORT)
49 && getElementName().equals(node.getName());
55 public int getElementType() {
56 return IMPORT_DECLARATION;
60 * @see net.sourceforge.phpdt.core.IImportDeclaration#getFlags()
62 public int getFlags() throws JavaModelException {
63 ImportDeclarationElementInfo info = (ImportDeclarationElementInfo) getElementInfo();
64 return info.getModifiers();
68 * @see JavaElement#getHandleMemento() For import declarations, the handle
69 * delimiter is associated to the import container already
71 public String getHandleMemento() {
72 StringBuffer buff = new StringBuffer(((JavaElement) getParent())
74 escapeMementoName(buff, getElementName());
75 if (this.occurrenceCount > 1) {
76 buff.append(JEM_COUNT);
77 buff.append(this.occurrenceCount);
79 return buff.toString();
83 * @see JavaElement#getHandleMemento()
85 protected char getHandleMementoDelimiter() {
86 // For import declarations, the handle delimiter is associated to the
87 // import container already
88 Assert.isTrue(false, "Should not be called"); //$NON-NLS-1$
93 * @see JavaElement#getPrimaryElement(boolean)
95 public IJavaElement getPrimaryElement(boolean checkOwner) {
96 CompilationUnit cu = (CompilationUnit) this.parent.getParent();
97 if (checkOwner && cu.isPrimary())
99 return cu.getImport(this.name);
103 * Returns true if the import is on-demand (ends with ".*")
105 public boolean isOnDemand() {
106 return this.name.endsWith(".*"); //$NON-NLS-1$
111 public String readableName() {
117 * @private Debugging purposes
119 protected void toStringInfo(int tab, StringBuffer buffer, Object info) {
120 buffer.append(this.tabString(tab));
121 buffer.append("include "); //$NON-NLS-1$
122 toStringName(buffer);
124 buffer.append(" (not open)"); //$NON-NLS-1$