RC2 compatibility
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / core / ImportContainer.java
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
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpdt.internal.core;
12
13 import net.sourceforge.phpdt.core.IImportContainer;
14 import net.sourceforge.phpdt.core.IImportDeclaration;
15 import net.sourceforge.phpdt.core.IJavaElement;
16 import net.sourceforge.phpdt.core.IParent;
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;
21
22 /**
23  * @see IImportContainer
24  */
25 public class ImportContainer extends SourceRefElement implements IImportContainer {
26 protected ImportContainer(CompilationUnit parent) {
27         super(parent, ""); //$NON-NLS-1$
28 }
29 public boolean equals(Object o) {
30         if (!(o instanceof ImportContainer)) return false;
31         return super.equals(o);
32 }
33 /**
34  * @see IJavaElement
35  */
36 public int getElementType() {
37         return IMPORT_CONTAINER;
38 }
39 /*
40  * @see JavaElement
41  */
42 //public IJavaElement getHandleFromMemento(String token, MementoTokenizer memento, WorkingCopyOwner workingCopyOwner) {
43 //      switch (token.charAt(0)) {
44 //              case JEM_COUNT:
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);
51 //                      } else {
52 //                              return this;
53 //                      }
54 //      }
55 //      return null;
56 //}
57 /**
58  * @see JavaElement#getHandleMemento()
59  */
60 protected char getHandleMementoDelimiter() {
61         return JavaElement.JEM_IMPORTDECLARATION;
62 }
63 /**
64  * @see IImportContainer
65  */
66 public IImportDeclaration getImport(String importName) {
67         return new ImportDeclaration(this, importName);
68 }
69 /*
70  * @see JavaElement#getPrimaryElement(boolean)
71  */
72 public IJavaElement getPrimaryElement(boolean checkOwner) {
73         CompilationUnit cu = (CompilationUnit)this.parent;
74         if (checkOwner && cu.isPrimary()) return this;
75         return cu.getImportContainer();
76 }
77 /**
78  * @see ISourceReference
79  */
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());
85         return range;
86 }
87 /**
88  * Import containers only exist if they have children.
89  * @see IParent
90  */
91 public boolean hasChildren() {
92         return true;
93 }
94 /**
95  */
96 public String readableName() {
97
98         return null;
99 }
100 /**
101  * @private Debugging purposes
102  */
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);
110         }
111 }
112 /**
113  *  Debugging purposes
114  */
115 protected void toStringInfo(int tab, StringBuffer buffer, Object info) {
116         buffer.append(this.tabString(tab));
117         buffer.append("<import container>"); //$NON-NLS-1$
118         if (info == null) {
119                 buffer.append(" (not open)"); //$NON-NLS-1$
120         }
121 }
122 }