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.internal.core.Assert;
14 import net.sourceforge.phpdt.internal.core.JavaElement;
16 import net.sourceforge.phpdt.core.IImportDeclaration;
17 import net.sourceforge.phpdt.core.IJavaElement;
18 import net.sourceforge.phpdt.core.JavaModelException;
19 import net.sourceforge.phpdt.core.jdom.IDOMNode;
22 * Handle for an import declaration. Info object is a ImportDeclarationElementInfo.
23 * @see IImportDeclaration
26 /* package */ class ImportDeclaration extends SourceRefElement implements IImportDeclaration {
30 * Constructs an ImportDeclaration in the given import container
31 * with the given name.
33 protected ImportDeclaration(ImportContainer parent, String name) {
36 public boolean equals(Object o) {
37 if (!(o instanceof ImportDeclaration)) return false;
38 return super.equals(o);
41 * @see JavaElement#equalsDOMNode
42 * @deprecated JDOM is obsolete
44 // TODO - JDOM - remove once model ported off of JDOM
45 protected boolean equalsDOMNode(IDOMNode node) {
46 return (node.getNodeType() == IDOMNode.IMPORT) && getElementName().equals(node.getName());
51 public int getElementType() {
52 return IMPORT_DECLARATION;
55 * @see net.sourceforge.phpdt.core.IImportDeclaration#getFlags()
57 public int getFlags() throws JavaModelException {
58 ImportDeclarationElementInfo info = (ImportDeclarationElementInfo)getElementInfo();
59 return info.getModifiers();
62 * @see JavaElement#getHandleMemento()
63 * For import declarations, the handle delimiter is associated to the import container already
65 public String getHandleMemento(){
66 StringBuffer buff= new StringBuffer(((JavaElement)getParent()).getHandleMemento());
67 escapeMementoName(buff, getElementName());
68 if (this.occurrenceCount > 1) {
69 buff.append(JEM_COUNT);
70 buff.append(this.occurrenceCount);
72 return buff.toString();
75 * @see JavaElement#getHandleMemento()
77 protected char getHandleMementoDelimiter() {
78 // For import declarations, the handle delimiter is associated to the import container already
79 Assert.isTrue(false, "Should not be called"); //$NON-NLS-1$
84 * @see JavaElement#getPrimaryElement(boolean)
86 public IJavaElement getPrimaryElement(boolean checkOwner) {
87 CompilationUnit cu = (CompilationUnit)this.parent.getParent();
88 if (checkOwner && cu.isPrimary()) return this;
89 return cu.getImport(this.name);
92 * Returns true if the import is on-demand (ends with ".*")
94 public boolean isOnDemand() {
95 return this.name.endsWith(".*"); //$NON-NLS-1$
99 public String readableName() {
104 * @private Debugging purposes
106 protected void toStringInfo(int tab, StringBuffer buffer, Object info) {
107 buffer.append(this.tabString(tab));
108 buffer.append("include "); //$NON-NLS-1$
109 toStringName(buffer);
111 buffer.append(" (not open)"); //$NON-NLS-1$