|
Lines 10-15
Link Here
|
| 10 |
*******************************************************************************/ |
10 |
*******************************************************************************/ |
| 11 |
package org.eclipse.jdt.internal.ui.fix; |
11 |
package org.eclipse.jdt.internal.ui.fix; |
| 12 |
|
12 |
|
|
|
13 |
import java.util.ArrayList; |
| 14 |
import java.util.List; |
| 15 |
|
| 13 |
import org.eclipse.core.resources.ResourcesPlugin; |
16 |
import org.eclipse.core.resources.ResourcesPlugin; |
| 14 |
|
17 |
|
| 15 |
import org.eclipse.swt.SWT; |
18 |
import org.eclipse.swt.SWT; |
|
Lines 30-41
Link Here
|
| 30 |
|
33 |
|
| 31 |
import org.eclipse.ui.dialogs.ContainerCheckedTreeViewer; |
34 |
import org.eclipse.ui.dialogs.ContainerCheckedTreeViewer; |
| 32 |
|
35 |
|
|
|
36 |
import org.eclipse.ltk.internal.ui.refactoring.RefactoringUIPlugin; |
| 33 |
import org.eclipse.ltk.ui.refactoring.RefactoringWizard; |
37 |
import org.eclipse.ltk.ui.refactoring.RefactoringWizard; |
| 34 |
import org.eclipse.ltk.ui.refactoring.UserInputWizardPage; |
38 |
import org.eclipse.ltk.ui.refactoring.UserInputWizardPage; |
| 35 |
|
39 |
|
| 36 |
import org.eclipse.jdt.core.ICompilationUnit; |
40 |
import org.eclipse.jdt.core.ICompilationUnit; |
| 37 |
import org.eclipse.jdt.core.IJavaElement; |
41 |
import org.eclipse.jdt.core.IJavaElement; |
| 38 |
import org.eclipse.jdt.core.IJavaModel; |
42 |
import org.eclipse.jdt.core.IJavaModel; |
|
|
43 |
import org.eclipse.jdt.core.IPackageFragment; |
| 39 |
import org.eclipse.jdt.core.JavaCore; |
44 |
import org.eclipse.jdt.core.JavaCore; |
| 40 |
|
45 |
|
| 41 |
import org.eclipse.jdt.internal.corext.fix.CleanUpRefactoring; |
46 |
import org.eclipse.jdt.internal.corext.fix.CleanUpRefactoring; |
|
Lines 124-130
Link Here
|
| 124 |
treeViewer.expandToLevel(compilationUnit, 0); |
129 |
treeViewer.expandToLevel(compilationUnit, 0); |
| 125 |
treeViewer.setChecked(compilationUnit, true); |
130 |
treeViewer.setChecked(compilationUnit, true); |
| 126 |
} |
131 |
} |
| 127 |
treeViewer.setSelection(new StructuredSelection(compilationUnits), true); |
132 |
treeViewer.setSelection(new StructuredSelection(smallestCommonParents(compilationUnits)), true); |
|
|
133 |
} |
| 134 |
|
| 135 |
private IJavaElement[] smallestCommonParents(IJavaElement[] elements) { |
| 136 |
if (elements.length == 1) { |
| 137 |
return elements; |
| 138 |
} else { |
| 139 |
List parents= new ArrayList(); |
| 140 |
boolean hasParents= false; |
| 141 |
|
| 142 |
IJavaElement parent= getParent(elements[0]); |
| 143 |
if (parent == null) { |
| 144 |
parent= elements[0]; |
| 145 |
} else { |
| 146 |
hasParents= true; |
| 147 |
} |
| 148 |
parents.add(parent); |
| 149 |
|
| 150 |
for (int i= 1; i < elements.length; i++) { |
| 151 |
parent= getParent(elements[i]); |
| 152 |
if (getParent(elements[i - 1]) != parent) { |
| 153 |
if (parent == null) { |
| 154 |
parent= elements[i]; |
| 155 |
} else { |
| 156 |
hasParents= true; |
| 157 |
} |
| 158 |
if (!parents.contains(parent)) { |
| 159 |
parents.add(parent); |
| 160 |
} |
| 161 |
} |
| 162 |
} |
| 163 |
|
| 164 |
IJavaElement[] parentsArray= (IJavaElement[])parents.toArray(new IJavaElement[parents.size()]); |
| 165 |
if (hasParents) { |
| 166 |
return smallestCommonParents(parentsArray); |
| 167 |
} |
| 168 |
return parentsArray; |
| 169 |
} |
| 170 |
} |
| 171 |
|
| 172 |
private IJavaElement getParent(IJavaElement element) { |
| 173 |
if (element instanceof ICompilationUnit) { |
| 174 |
return element.getParent(); |
| 175 |
} else if (element instanceof IPackageFragment){ |
| 176 |
return element.getParent().getParent(); |
| 177 |
} else { |
| 178 |
return element.getParent(); |
| 179 |
} |
| 128 |
} |
180 |
} |
| 129 |
|
181 |
|
| 130 |
protected boolean performFinish() { |
182 |
protected boolean performFinish() { |
|
Lines 146-154
Link Here
|
| 146 |
refactoring.addCompilationUnit((ICompilationUnit)checkedElements[i]); |
198 |
refactoring.addCompilationUnit((ICompilationUnit)checkedElements[i]); |
| 147 |
} |
199 |
} |
| 148 |
if (!refactoring.hasMultiFix()) { |
200 |
if (!refactoring.hasMultiFix()) { |
| 149 |
NameFixTuple[] multiFixes= getMultiFixes(); |
201 |
IMultiFix[] multiFixes= createAllMultiFixes(); |
| 150 |
for (int i= 0; i < multiFixes.length; i++) { |
202 |
for (int i= 0; i < multiFixes.length; i++) { |
| 151 |
refactoring.addMultiFix(multiFixes[i].getFix()); |
203 |
refactoring.addMultiFix(multiFixes[i]); |
| 152 |
} |
204 |
} |
| 153 |
} |
205 |
} |
| 154 |
} |
206 |
} |
|
Lines 156-161
Link Here
|
| 156 |
|
208 |
|
| 157 |
private class SelectFixesPage extends UserInputWizardPage { |
209 |
private class SelectFixesPage extends UserInputWizardPage { |
| 158 |
|
210 |
|
|
|
211 |
private NameFixTuple[] fMultiFixes; |
| 212 |
|
| 159 |
public SelectFixesPage(String name) { |
213 |
public SelectFixesPage(String name) { |
| 160 |
super(name); |
214 |
super(name); |
| 161 |
} |
215 |
} |
|
Lines 207-212
Link Here
|
| 207 |
storeSettings(); |
261 |
storeSettings(); |
| 208 |
return super.getNextPage(); |
262 |
return super.getNextPage(); |
| 209 |
} |
263 |
} |
|
|
264 |
|
| 265 |
private void storeSettings() { |
| 266 |
IDialogSettings settings= getCleanUpWizardSettings(); |
| 267 |
NameFixTuple[] fixes= getMultiFixes(); |
| 268 |
for (int i= 0; i < fixes.length; i++) { |
| 269 |
fixes[i].getFix().saveSettings(settings); |
| 270 |
} |
| 271 |
} |
| 210 |
|
272 |
|
| 211 |
private void initializeRefactoring() { |
273 |
private void initializeRefactoring() { |
| 212 |
CleanUpRefactoring refactoring= (CleanUpRefactoring)getRefactoring(); |
274 |
CleanUpRefactoring refactoring= (CleanUpRefactoring)getRefactoring(); |
|
Lines 216-226
Link Here
|
| 216 |
refactoring.addMultiFix(multiFixes[i].getFix()); |
278 |
refactoring.addMultiFix(multiFixes[i].getFix()); |
| 217 |
} |
279 |
} |
| 218 |
} |
280 |
} |
|
|
281 |
|
| 282 |
private NameFixTuple[] getMultiFixes() { |
| 283 |
if (fMultiFixes == null) { |
| 284 |
IMultiFix[] fixes= createAllMultiFixes(); |
| 285 |
fMultiFixes= new NameFixTuple[4]; |
| 286 |
fMultiFixes[0]= new NameFixTuple(MultiFixMessages.CleanUpRefactoringWizard_CodeStyleSection_description, fixes[0]); |
| 287 |
fMultiFixes[1]= new NameFixTuple(MultiFixMessages.CleanUpRefactoringWizard_UnusedCodeSection_description, fixes[1]); |
| 288 |
fMultiFixes[2]= new NameFixTuple(MultiFixMessages.CleanUpRefactoringWizard_J2SE50Section_description, fixes[2]); |
| 289 |
fMultiFixes[3]= new NameFixTuple(MultiFixMessages.CleanUpRefactoringWizard_StringExternalization_description, fixes[3]); |
| 290 |
} |
| 291 |
return fMultiFixes; |
| 292 |
} |
| 219 |
} |
293 |
} |
| 220 |
|
294 |
|
| 221 |
private final boolean fShowCUPage; |
295 |
private final boolean fShowCUPage; |
| 222 |
private final boolean fShowCleanUpPage; |
296 |
private final boolean fShowCleanUpPage; |
| 223 |
private NameFixTuple[] fMultiFixes; |
|
|
| 224 |
|
297 |
|
| 225 |
public CleanUpRefactoringWizard(CleanUpRefactoring refactoring, int flags, boolean showCUPage, boolean showCleanUpPage) { |
298 |
public CleanUpRefactoringWizard(CleanUpRefactoring refactoring, int flags, boolean showCUPage, boolean showCleanUpPage) { |
| 226 |
super(refactoring, flags); |
299 |
super(refactoring, flags); |
|
Lines 247-281
Link Here
|
| 247 |
addPage(selectSolverPage); |
320 |
addPage(selectSolverPage); |
| 248 |
} |
321 |
} |
| 249 |
} |
322 |
} |
|
|
323 |
|
| 324 |
public static IMultiFix[] createAllMultiFixes() { |
| 325 |
IDialogSettings section= getCleanUpWizardSettings(); |
| 250 |
|
326 |
|
| 251 |
private NameFixTuple[] getMultiFixes() { |
327 |
IMultiFix[] result= new IMultiFix[4]; |
| 252 |
if (fMultiFixes == null) { |
328 |
result[0]= new CodeStyleMultiFix(section); |
| 253 |
IDialogSettings settings= CleanUpRefactoringWizard.this.getDialogSettings(); |
329 |
result[1]= new UnusedCodeMultiFix(section); |
| 254 |
IDialogSettings section= settings.getSection(CLEAN_UP_WIZARD_SETTINGS_SECTION_ID); |
330 |
result[2]= new Java50MultiFix(section); |
| 255 |
fMultiFixes= new NameFixTuple[4]; |
331 |
result[3]= new StringMultiFix(section); |
| 256 |
if (section == null) { |
332 |
|
| 257 |
section= settings.addNewSection(CLEAN_UP_WIZARD_SETTINGS_SECTION_ID); |
333 |
return result; |
| 258 |
fMultiFixes[0]= new NameFixTuple(MultiFixMessages.CleanUpRefactoringWizard_CodeStyleSection_description, new CodeStyleMultiFix(false, true, false, false)); |
|
|
| 259 |
fMultiFixes[1]= new NameFixTuple(MultiFixMessages.CleanUpRefactoringWizard_UnusedCodeSection_description, new UnusedCodeMultiFix(true, true, true, false, true, false)); |
| 260 |
fMultiFixes[2]= new NameFixTuple(MultiFixMessages.CleanUpRefactoringWizard_J2SE50Section_description, new Java50MultiFix(true, true)); |
| 261 |
fMultiFixes[3]= new NameFixTuple(MultiFixMessages.CleanUpRefactoringWizard_StringExternalization_description, new StringMultiFix(false, true)); |
| 262 |
storeSettings(); |
| 263 |
} else { |
| 264 |
fMultiFixes[0]= new NameFixTuple(MultiFixMessages.CleanUpRefactoringWizard_CodeStyleSection_description, new CodeStyleMultiFix(section)); |
| 265 |
fMultiFixes[1]= new NameFixTuple(MultiFixMessages.CleanUpRefactoringWizard_UnusedCodeSection_description, new UnusedCodeMultiFix(section)); |
| 266 |
fMultiFixes[2]= new NameFixTuple(MultiFixMessages.CleanUpRefactoringWizard_J2SE50Section_description, new Java50MultiFix(section)); |
| 267 |
fMultiFixes[3]= new NameFixTuple(MultiFixMessages.CleanUpRefactoringWizard_StringExternalization_description, new StringMultiFix(section)); |
| 268 |
} |
| 269 |
} |
| 270 |
return fMultiFixes; |
| 271 |
} |
334 |
} |
| 272 |
|
335 |
|
| 273 |
private void storeSettings() { |
336 |
private static IDialogSettings getCleanUpWizardSettings() { |
| 274 |
IDialogSettings settings= CleanUpRefactoringWizard.this.getDialogSettings().getSection(CLEAN_UP_WIZARD_SETTINGS_SECTION_ID); |
337 |
IDialogSettings settings= RefactoringUIPlugin.getDefault().getDialogSettings(); |
| 275 |
NameFixTuple[] fixes= getMultiFixes(); |
338 |
IDialogSettings section= settings.getSection(CLEAN_UP_WIZARD_SETTINGS_SECTION_ID); |
| 276 |
for (int i= 0; i < fixes.length; i++) { |
339 |
if (section == null) { |
| 277 |
fixes[i].getFix().saveSettings(settings); |
340 |
section= settings.addNewSection(CLEAN_UP_WIZARD_SETTINGS_SECTION_ID); |
| 278 |
} |
341 |
} |
|
|
342 |
return section; |
| 279 |
} |
343 |
} |
| 280 |
|
344 |
|
| 281 |
} |
345 |
} |