1 11 package org.eclipse.jdt.internal.corext.codemanipulation; 12 13 import org.eclipse.text.edits.TextEdit; 14 15 import org.eclipse.core.runtime.CoreException; 16 import org.eclipse.core.runtime.IProgressMonitor; 17 import org.eclipse.core.runtime.IStatus; 18 19 import org.eclipse.jface.text.BadLocationException; 20 import org.eclipse.jface.text.IDocument; 21 22 import org.eclipse.jdt.core.ICompilationUnit; 23 import org.eclipse.jdt.core.dom.AST; 24 import org.eclipse.jdt.core.dom.IBinding; 25 import org.eclipse.jdt.core.dom.ITypeBinding; 26 import org.eclipse.jdt.core.dom.Type; 27 28 import org.eclipse.jdt.internal.corext.Assert; 29 30 import org.eclipse.jdt.internal.ui.JavaUIStatus; 31 import org.eclipse.jdt.internal.ui.preferences.JavaPreferencesSettings; 32 33 37 public final class ImportRewrite { 38 39 private ImportsStructure fImportsStructure; 40 41 private ImportRewrite(ICompilationUnit cu, String [] preferenceOrder, int importThreshold) throws CoreException { 42 Assert.isNotNull(cu); 43 Assert.isNotNull(preferenceOrder); 44 fImportsStructure= new ImportsStructure(cu, preferenceOrder, importThreshold, true); 45 } 46 47 52 public ImportRewrite(ICompilationUnit cunit) throws CoreException { 53 this(cunit, JavaPreferencesSettings.getImportOrderPreference(cunit.getJavaProject()), JavaPreferencesSettings.getImportNumberThreshold(cunit.getJavaProject())); 54 } 55 56 59 public final TextEdit createEdit(IDocument document) throws CoreException { 60 return createEdit(document, null); 61 } 62 63 public final TextEdit createEdit(IDocument document, IProgressMonitor monitor) throws CoreException { 64 try { 65 return fImportsStructure.getResultingEdits(document, monitor); 66 } catch (BadLocationException e) { 67 throw new CoreException(JavaUIStatus.createError(IStatus.ERROR, e)); 68 } 69 } 70 71 public ICompilationUnit getCompilationUnit() { 72 return fImportsStructure.getCompilationUnit(); 73 } 74 75 78 public void setFilterImplicitImports(boolean filterImplicitImports) { 79 fImportsStructure.setFilterImplicitImports(filterImplicitImports); 80 } 81 82 85 public void setFindAmbiguosImports(boolean findAmbiguosImports) { 86 fImportsStructure.setFindAmbiguousImports(findAmbiguosImports); 87 } 88 89 98 public String addImport(String qualifiedTypeName) { 99 return fImportsStructure.addImport(qualifiedTypeName); 100 } 101 102 111 public String addStaticImport(String qualifiedName, String selector, boolean isField) { 112 return fImportsStructure.addStaticImport(qualifiedName, selector, isField); 113 } 114 115 122 public String addStaticImport(IBinding binding) { 123 return fImportsStructure.addStaticImport(binding); 124 } 125 126 138 public String addImport(ITypeBinding binding) { 139 return fImportsStructure.addImport(binding); 140 } 141 142 143 156 public Type addImport(ITypeBinding binding, AST ast) { 157 return fImportsStructure.addImport(binding, ast); 158 } 159 160 173 public Type addImportFromSignature(String typeSig, AST ast) { 174 return fImportsStructure.addImportFromSignature(typeSig, ast); 175 } 176 177 182 public String findImport(String simpleName) { 183 return fImportsStructure.findImport(simpleName); 184 } 185 186 187 192 public boolean removeImport(ITypeBinding binding) { 193 return fImportsStructure.removeImport(binding); 194 } 195 196 201 public boolean removeImport(String qualifiedTypeName) { 202 return fImportsStructure.removeImport(qualifiedTypeName); 203 } 204 205 210 public boolean removeStaticImport(String qualifiedName) { 211 return fImportsStructure.removeStaticImport(qualifiedName); 212 } 213 214 221 public boolean isEmpty() { 222 return !fImportsStructure.hasChanges(); 223 } 224 225 public String [] getCreatedImports() { 226 return fImportsStructure.getCreatedImports(); 227 } 228 229 public String [] getCreatedStaticImports() { 230 return fImportsStructure.getCreatedStaticImports(); 231 } 232 } 233 | Popular Tags |