IDEA-74933 Groovy: Introduce Closure Parameter with "Delegate via overloading" and "Remove parameter" options doesn't remove parameter no longer used

This commit is contained in:
Maxim Medvedev
2011-10-04 23:11:38 +04:00
parent 9b3b37a76d
commit f0ea1406aa
5 changed files with 19 additions and 3 deletions
@@ -485,8 +485,10 @@ public class GrIntroduceClosureParameterProcessor extends BaseRefactoringProcess
call.append(newName).append('(');
final GrParameter[] parameters = result.getParameters();
for (GrParameter parameter : parameters) {
call.append(parameter.getName()).append(", ");
for (int i = 0; i < parameters.length; i++) {
if (!mySettings.parametersToRemove().contains(i)) {
call.append(parameters[i].getName()).append(", ");
}
}
call.append(myParameterInitializer.getText());
call.append(")");
@@ -99,6 +99,7 @@ public class GrIntroduceParameterDialog extends RefactoringDialog implements GrI
myDeclareFinalCheckBox.setSelected(hasFinalModifier());
myChangeVarUsages.setVisible(context.toReplaceIn instanceof GrClosableBlock && context.toSearchFor instanceof GrVariable);
myChangeVarUsages.setSelected(true);
setTitle(RefactoringBundle.message("introduce.parameter.title"));
init();
@@ -176,7 +177,7 @@ public class GrIntroduceParameterDialog extends RefactoringDialog implements GrI
@Override
protected JComponent createCenterPanel() {
final GridBag c = new GridBag().setDefaultAnchor(GridBagConstraints.WEST).setLine(3);
final GridBag c = new GridBag().setDefaultAnchor(GridBagConstraints.WEST).setLine(4);
for (Object o : toRemoveCBs.keys()) {
c.nextLine();
myCheckBoxContainer.add(((JCheckBox)o), c);
@@ -92,4 +92,8 @@ public class GrIntroduceParameterInClosureTest extends LightCodeInsightFixtureTe
public void testCorrectOccurrencesForLocalVar() {
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, false, false, null, false);
}
public void testDelegateRemoveUnusedParam() {
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, true, false, null, true);
}
}
@@ -0,0 +1,3 @@
def clos = { int i ->
println <selection>"test"</selection>
}
@@ -0,0 +1,6 @@
def closDelegate = { String anObject ->
println anObject
}
def clos = {int i ->
closDelegate("test")
}