1 11 package org.eclipse.jdt.internal.ui.fix; 12 13 import java.util.Map ; 14 15 import org.eclipse.core.runtime.CoreException; 16 import org.eclipse.core.runtime.IProgressMonitor; 17 18 import org.eclipse.ltk.core.refactoring.RefactoringStatus; 19 20 import org.eclipse.jdt.core.ICompilationUnit; 21 import org.eclipse.jdt.core.IJavaProject; 22 import org.eclipse.jdt.core.dom.CompilationUnit; 23 24 import org.eclipse.jdt.internal.corext.codemanipulation.CodeGenerationSettings; 25 import org.eclipse.jdt.internal.corext.fix.CleanUpConstants; 26 import org.eclipse.jdt.internal.corext.fix.IFix; 27 import org.eclipse.jdt.internal.corext.fix.ImportsFix; 28 29 import org.eclipse.jdt.ui.text.java.IProblemLocation; 30 31 import org.eclipse.jdt.internal.ui.preferences.JavaPreferencesSettings; 32 33 public class ImportsCleanUp extends AbstractCleanUp { 34 35 private CodeGenerationSettings fCodeGeneratorSettings; 36 private RefactoringStatus fStatus; 37 38 public ImportsCleanUp(Map options) { 39 super(options); 40 } 41 42 public ImportsCleanUp() { 43 super(); 44 } 45 46 49 public boolean requireAST(ICompilationUnit unit) throws CoreException { 50 return isEnabled(CleanUpConstants.ORGANIZE_IMPORTS); 51 } 52 53 56 public IFix createFix(final CompilationUnit compilationUnit) throws CoreException { 57 return ImportsFix.createCleanUp(compilationUnit, fCodeGeneratorSettings, 58 isEnabled(CleanUpConstants.ORGANIZE_IMPORTS), fStatus); 59 } 60 61 64 public IFix createFix(CompilationUnit compilationUnit, IProblemLocation[] problems) throws CoreException { 65 return null; 66 } 67 68 71 public RefactoringStatus checkPreConditions(IJavaProject project, ICompilationUnit[] compilationUnits, IProgressMonitor monitor) throws CoreException { 72 RefactoringStatus result= super.checkPreConditions(project, compilationUnits, monitor); 73 74 if (isEnabled(CleanUpConstants.ORGANIZE_IMPORTS)) { 75 fCodeGeneratorSettings= JavaPreferencesSettings.getCodeGenerationSettings(project); 76 fStatus= new RefactoringStatus(); 77 } 78 79 return result; 80 } 81 82 85 public RefactoringStatus checkPostConditions(IProgressMonitor monitor) throws CoreException { 86 fCodeGeneratorSettings= null; 87 if (fStatus == null || fStatus.isOK()) { 88 return super.checkPostConditions(monitor); 89 } else { 90 return fStatus; 91 } 92 } 93 94 97 public String [] getDescriptions() { 98 if (isEnabled(CleanUpConstants.ORGANIZE_IMPORTS)) 99 return new String [] {MultiFixMessages.ImportsCleanUp_OrganizeImports_Description}; 100 101 return null; 102 } 103 104 107 public String getPreview() { 108 StringBuffer buf= new StringBuffer (); 109 110 if (isEnabled(CleanUpConstants.ORGANIZE_IMPORTS)) { 111 buf.append("import org.model.Engine;\n"); } else { 113 buf.append("import org.model.*;\n"); } 115 116 return buf.toString(); 117 } 118 119 122 public Map getRequiredOptions() { 123 return null; 124 } 125 126 129 public int maximalNumberOfFixes(CompilationUnit compilationUnit) { 130 return -1; 131 } 132 133 136 public boolean needsFreshAST(CompilationUnit compilationUnit) { 137 if (isEnabled(CleanUpConstants.ORGANIZE_IMPORTS)) 138 return true; 139 140 return super.needsFreshAST(compilationUnit); 141 } 142 143 146 public boolean canFix(CompilationUnit compilationUnit, IProblemLocation problem) throws CoreException { 147 return false; 148 } 149 150 } 151 | Popular Tags |