diff --git a/java/java-impl/src/com/intellij/refactoring/extractMethod/ExtractMethodProcessor.java b/java/java-impl/src/com/intellij/refactoring/extractMethod/ExtractMethodProcessor.java index f1a0966c1dc6..123463734811 100644 --- a/java/java-impl/src/com/intellij/refactoring/extractMethod/ExtractMethodProcessor.java +++ b/java/java-impl/src/com/intellij/refactoring/extractMethod/ExtractMethodProcessor.java @@ -509,6 +509,11 @@ public class ExtractMethodProcessor implements MatchProvider { myVariableDatum[i] = myInputVariables.getInputVariables().get(i); } } + + @TestOnly + public void doNotPassParameter(int i) { + myVariableDatum[i].passAsParameter = false; + } /** * Invoked in command and in atomic action @@ -760,6 +765,7 @@ public class ExtractMethodProcessor implements MatchProvider { for (int i = 0, length = myVariableDatum.length; i < length; i++) { ParameterTablePanel.VariableData data = myVariableDatum[i]; + if (!data.passAsParameter) continue; final PsiVariable variable = data.variable; final PsiParameter psiParameter = newMethod.getParameterList().getParameters()[i]; if (!TypeConversionUtil.isAssignable(variable.getType(), psiParameter.getType())) { diff --git a/java/java-tests/testData/refactoring/extractMethod/DisabledParam.java b/java/java-tests/testData/refactoring/extractMethod/DisabledParam.java new file mode 100644 index 000000000000..64406a7febeb --- /dev/null +++ b/java/java-tests/testData/refactoring/extractMethod/DisabledParam.java @@ -0,0 +1,6 @@ +class Fest { + public static void main(String[] args) { + String f = ""; + System.out.println(f); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/refactoring/extractMethod/DisabledParam_after.java b/java/java-tests/testData/refactoring/extractMethod/DisabledParam_after.java new file mode 100644 index 000000000000..c25ade46e4d5 --- /dev/null +++ b/java/java-tests/testData/refactoring/extractMethod/DisabledParam_after.java @@ -0,0 +1,11 @@ +class Fest { + public static void main(String[] args) { + String f = ""; + newMethod(); + } + + private static void newMethod() { + String f = ; + System.out.println(f); + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/refactoring/ExtractMethodTest.java b/java/java-tests/testSrc/com/intellij/refactoring/ExtractMethodTest.java index cf4e75003a50..dd534625c829 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/ExtractMethodTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/ExtractMethodTest.java @@ -9,6 +9,7 @@ import com.intellij.psi.PsiExpression; import com.intellij.psi.PsiFile; import com.intellij.psi.codeStyle.CodeStyleSettings; import com.intellij.psi.codeStyle.CodeStyleSettingsManager; +import com.intellij.refactoring.extractMethod.ExtractMethodHandler; import com.intellij.refactoring.extractMethod.ExtractMethodProcessor; import com.intellij.refactoring.extractMethod.PrepareFailedException; import com.intellij.refactoring.introduceVariable.IntroduceVariableBase; @@ -500,6 +501,16 @@ public class ExtractMethodTest extends LightCodeInsightTestCase { public void testRedundantCast() throws Exception { doTest(); } + + public void testDisabledParam() throws Exception { + final CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()); + settings.ELSE_ON_NEW_LINE = true; + settings.CATCH_ON_NEW_LINE = myCatchOnNewLine; + configureByFile(BASE_PATH + getTestName(false) + ".java"); + boolean success = performExtractMethod(true, true, getEditor(), getFile(), getProject(), false, 0); + assertTrue(success); + checkResultByFile(BASE_PATH + getTestName(false) + "_after.java"); + } private void doPrepareErrorTest(final String expectedMessage) throws Exception { String expectedError = null; @@ -545,6 +556,17 @@ public class ExtractMethodTest extends LightCodeInsightTestCase { public static boolean performExtractMethod(boolean doRefactor, boolean replaceAllDuplicates, Editor editor, PsiFile file, Project project, final boolean extractChainedConstructor) throws PrepareFailedException, IncorrectOperationException { + return performExtractMethod(doRefactor, replaceAllDuplicates, editor, file, project, extractChainedConstructor, null); + } + + public static boolean performExtractMethod(boolean doRefactor, + boolean replaceAllDuplicates, + Editor editor, + PsiFile file, + Project project, + final boolean extractChainedConstructor, + int... disabledParams) + throws PrepareFailedException, IncorrectOperationException { int startOffset = editor.getSelectionModel().getSelectionStart(); int endOffset = editor.getSelectionModel().getSelectionEnd(); @@ -574,7 +596,13 @@ public class ExtractMethodTest extends LightCodeInsightTestCase { } if (doRefactor) { - processor.testRun(); + processor.testPrepare(); + if (disabledParams != null) { + for (int param : disabledParams) { + processor.doNotPassParameter(param); + } + } + ExtractMethodHandler.run(project, editor, processor); } if (replaceAllDuplicates) {