From f0ea1406aa5841a40ae777938c7827edd5d91120 Mon Sep 17 00:00:00 2001 From: Maxim Medvedev Date: Tue, 4 Oct 2011 23:11:38 +0400 Subject: [PATCH] IDEA-74933 Groovy: Introduce Closure Parameter with "Delegate via overloading" and "Remove parameter" options doesn't remove parameter no longer used --- .../parameter/GrIntroduceClosureParameterProcessor.java | 6 ++++-- .../introduce/parameter/GrIntroduceParameterDialog.java | 3 ++- .../GrIntroduceParameterInClosureTest.java | 4 ++++ .../DelegateRemoveUnusedParam.groovy | 3 +++ .../DelegateRemoveUnusedParam_after.groovy | 6 ++++++ 5 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 plugins/groovy/testdata/refactoring/introduceParameterInClosure/DelegateRemoveUnusedParam.groovy create mode 100644 plugins/groovy/testdata/refactoring/introduceParameterInClosure/DelegateRemoveUnusedParam_after.groovy diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduce/parameter/GrIntroduceClosureParameterProcessor.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduce/parameter/GrIntroduceClosureParameterProcessor.java index d9c636a877dc..588ac03e74bd 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduce/parameter/GrIntroduceClosureParameterProcessor.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduce/parameter/GrIntroduceClosureParameterProcessor.java @@ -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(")"); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduce/parameter/GrIntroduceParameterDialog.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduce/parameter/GrIntroduceParameterDialog.java index 5ab54ed23831..4e1123d512df 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduce/parameter/GrIntroduceParameterDialog.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduce/parameter/GrIntroduceParameterDialog.java @@ -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); diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/introduceParameter/GrIntroduceParameterInClosureTest.java b/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/introduceParameter/GrIntroduceParameterInClosureTest.java index 8ef6db72d81a..c817c7e2d2b9 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/introduceParameter/GrIntroduceParameterInClosureTest.java +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/introduceParameter/GrIntroduceParameterInClosureTest.java @@ -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); + } } diff --git a/plugins/groovy/testdata/refactoring/introduceParameterInClosure/DelegateRemoveUnusedParam.groovy b/plugins/groovy/testdata/refactoring/introduceParameterInClosure/DelegateRemoveUnusedParam.groovy new file mode 100644 index 000000000000..079c0cd9522d --- /dev/null +++ b/plugins/groovy/testdata/refactoring/introduceParameterInClosure/DelegateRemoveUnusedParam.groovy @@ -0,0 +1,3 @@ +def clos = { int i -> + println "test" +} \ No newline at end of file diff --git a/plugins/groovy/testdata/refactoring/introduceParameterInClosure/DelegateRemoveUnusedParam_after.groovy b/plugins/groovy/testdata/refactoring/introduceParameterInClosure/DelegateRemoveUnusedParam_after.groovy new file mode 100644 index 000000000000..e3f54601bc76 --- /dev/null +++ b/plugins/groovy/testdata/refactoring/introduceParameterInClosure/DelegateRemoveUnusedParam_after.groovy @@ -0,0 +1,6 @@ +def closDelegate = { String anObject -> + println anObject +} +def clos = {int i -> + closDelegate("test") +} \ No newline at end of file