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.*;
14 import net.sourceforge.phpdt.core.IImportDeclaration;
15 import net.sourceforge.phpdt.core.JavaModelException;
16 import net.sourceforge.phpdt.core.jdom.*;
19 * Handle for an import declaration. Info object is a ImportDeclarationElementInfo.
20 * @see IImportDeclaration
23 /* package */ class ImportDeclaration extends SourceRefElement implements IImportDeclaration {
27 * Constructs an ImportDeclaration in the given import container
28 * with the given name.
30 protected ImportDeclaration(ImportContainer parent, String name) {
33 public boolean equals(Object o) {
34 if (!(o instanceof ImportDeclaration)) return false;
35 return super.equals(o);
38 * @see JavaElement#equalsDOMNode
39 * @deprecated JDOM is obsolete
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());
48 public int getElementType() {
49 return IMPORT_DECLARATION;
52 * @see org.eclipse.jdt.core.IImportDeclaration#getFlags()
54 public int getFlags() throws JavaModelException {
55 ImportDeclarationElementInfo info = (ImportDeclarationElementInfo)getElementInfo();
56 return info.getModifiers();
59 * @see JavaElement#getHandleMemento()
60 * For import declarations, the handle delimiter is associated to the import container already
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);
69 // return buff.toString();
72 * @see JavaElement#getHandleMemento()
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$
80 * @see JavaElement#getPrimaryElement(boolean)
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);
88 * Returns true if the import is on-demand (ends with ".*")
90 public boolean isOnDemand() {
91 return this.name.endsWith(".*"); //$NON-NLS-1$
95 public String readableName() {
100 * @private Debugging purposes
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);
107 buffer.append(" (not open)"); //$NON-NLS-1$