1 11 package org.eclipse.jdt.internal.core; 12 13 import org.eclipse.jdt.core.*; 14 import org.eclipse.jdt.core.IImportContainer; 15 import org.eclipse.jdt.core.IImportDeclaration; 16 import org.eclipse.jdt.core.IJavaElement; 17 import org.eclipse.jdt.core.ISourceRange; 18 import org.eclipse.jdt.core.ISourceReference; 19 import org.eclipse.jdt.core.JavaModelException; 20 import org.eclipse.jdt.internal.core.util.MementoTokenizer; 21 22 25 public class ImportContainer extends SourceRefElement implements IImportContainer { 26 protected ImportContainer(CompilationUnit parent) { 27 super(parent); 28 } 29 public boolean equals(Object o) { 30 if (!(o instanceof ImportContainer)) return false; 31 return super.equals(o); 32 } 33 36 public int getElementType() { 37 return IMPORT_CONTAINER; 38 } 39 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 60 protected char getHandleMementoDelimiter() { 61 return JavaElement.JEM_IMPORTDECLARATION; 62 } 63 66 public IImportDeclaration getImport(String importName) { 67 int index = importName.indexOf(".*"); boolean isOnDemand = index != -1; 69 if (isOnDemand) 70 importName = new String (importName.substring(0, index)); 72 return new ImportDeclaration(this, importName, isOnDemand); 73 } 74 77 public IJavaElement getPrimaryElement(boolean checkOwner) { 78 CompilationUnit cu = (CompilationUnit)this.parent; 79 if (checkOwner && cu.isPrimary()) return this; 80 return cu.getImportContainer(); 81 } 82 85 public ISourceRange getSourceRange() throws JavaModelException { 86 IJavaElement[] imports= getChildren(); 87 ISourceRange firstRange= ((ISourceReference)imports[0]).getSourceRange(); 88 ISourceRange lastRange= ((ISourceReference)imports[imports.length - 1]).getSourceRange(); 89 SourceRange range= new SourceRange(firstRange.getOffset(), lastRange.getOffset() + lastRange.getLength() - firstRange.getOffset()); 90 return range; 91 } 92 94 public String readableName() { 95 96 return null; 97 } 98 101 protected void toString(int tab, StringBuffer buffer) { 102 Object info = JavaModelManager.getJavaModelManager().peekAtInfo(this); 103 if (info == null || !(info instanceof JavaElementInfo)) return; 104 IJavaElement[] children = ((JavaElementInfo)info).getChildren(); 105 for (int i = 0; i < children.length; i++) { 106 if (i > 0) buffer.append("\n"); ((JavaElement)children[i]).toString(tab, buffer); 108 } 109 } 110 113 protected void toStringInfo(int tab, StringBuffer buffer, Object info, boolean showResolvedInfo) { 114 buffer.append(this.tabString(tab)); 115 buffer.append("<import container>"); if (info == null) { 117 buffer.append(" (not open)"); } 119 } 120 } 121 | Popular Tags |