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.IImportContainer;
15 import net.sourceforge.phpdt.core.IImportDeclaration;
16 import net.sourceforge.phpdt.core.IJavaElement;
17 import net.sourceforge.phpdt.core.ISourceRange;
18 import net.sourceforge.phpdt.core.ISourceReference;
19 import net.sourceforge.phpdt.core.JavaModelException;
20 //import net.sourceforge.phpdt.internal.core.util.MementoTokenizer;
23 * @see IImportContainer
25 public class ImportContainer extends SourceRefElement implements IImportContainer {
26 protected ImportContainer(CompilationUnit parent) {
27 super(parent, ""); //$NON-NLS-1$
29 public boolean equals(Object o) {
30 if (!(o instanceof ImportContainer)) return false;
31 return super.equals(o);
36 public int getElementType() {
37 return IMPORT_CONTAINER;
42 //public IJavaElement getHandleFromMemento(String token, MementoTokenizer memento, WorkingCopyOwner workingCopyOwner) {
43 // switch (token.charAt(0)) {
45 // return getHandleUpdatingCountFromMemento(memento, workingCopyOwner);
46 // case JEM_IMPORTDECLARATION:
47 // if (memento.hasMoreTokens()) {
48 // String importName = memento.nextToken();
49 // JavaElement importDecl = (JavaElement)getImport(importName);
50 // return importDecl.getHandleFromMemento(memento, workingCopyOwner);
58 * @see JavaElement#getHandleMemento()
60 protected char getHandleMementoDelimiter() {
61 return JavaElement.JEM_IMPORTDECLARATION;
64 * @see IImportContainer
66 public IImportDeclaration getImport(String importName) {
67 return new ImportDeclaration(this, importName);
70 * @see JavaElement#getPrimaryElement(boolean)
72 public IJavaElement getPrimaryElement(boolean checkOwner) {
73 CompilationUnit cu = (CompilationUnit)this.parent;
74 if (checkOwner && cu.isPrimary()) return this;
75 return cu.getImportContainer();
78 * @see ISourceReference
80 public ISourceRange getSourceRange() throws JavaModelException {
81 IJavaElement[] imports= getChildren();
82 ISourceRange firstRange= ((ISourceReference)imports[0]).getSourceRange();
83 ISourceRange lastRange= ((ISourceReference)imports[imports.length - 1]).getSourceRange();
84 SourceRange range= new SourceRange(firstRange.getOffset(), lastRange.getOffset() + lastRange.getLength() - firstRange.getOffset());
88 * Import containers only exist if they have children.
91 public boolean hasChildren() {
96 public String readableName() {
101 * @private Debugging purposes
103 protected void toString(int tab, StringBuffer buffer) {
104 Object info = JavaModelManager.getJavaModelManager().peekAtInfo(this);
105 if (info == null || !(info instanceof JavaElementInfo)) return;
106 IJavaElement[] children = ((JavaElementInfo)info).getChildren();
107 for (int i = 0; i < children.length; i++) {
108 if (i > 0) buffer.append("\n"); //$NON-NLS-1$
109 ((JavaElement)children[i]).toString(tab, buffer);
115 protected void toStringInfo(int tab, StringBuffer buffer, Object info) {
116 buffer.append(this.tabString(tab));
117 buffer.append("<import container>"); //$NON-NLS-1$
119 buffer.append(" (not open)"); //$NON-NLS-1$