diff --git a/python/src/com/jetbrains/python/PyBundle.properties b/python/src/com/jetbrains/python/PyBundle.properties index c117d0f04428..fbd9d64acd91 100644 --- a/python/src/com/jetbrains/python/PyBundle.properties +++ b/python/src/com/jetbrains/python/PyBundle.properties @@ -593,15 +593,18 @@ refactoring.push.down.error.cannot.perform.refactoring.not.inside.class=Cannot p refactoring.inline.local.multiassignment=Definition is in multi-assign # extract method -refactoring.extract.method.error.cannot.perform.refactoring.when.class.declaration.inside=Cannot perform refactoring with class declaration inside code block -refactoring.extract.method.error.cannot.perform.refactoring.when.function.declaration.inside=Cannot perform refactoring with function declaration inside code block -refactoring.extract.method.error.cannot.perform.refactoring.no.corresponding.loop.for.break=No corresponding loop for break statement inside code fragment -refactoring.extract.method.error.cannot.perform.refactoring.no.corresponding.loop.for.continue=No corresponding loop for continue statement inside code fragment -refactoring.extract.method.error.cannot.perform.refactoring.when.execution.flow.is.interrupted=Cannot perform refactoring when execution flow is interrupted -refactoring.extract.method.error.cannot.perform.refactoring.when.from.import.inside=Cannot perform refactoring with from import statement inside code block -refactoring.extract.method.error.cannot.perform.refactoring.using.selected.elements=Cannot perform extract method using selected element(s) +refactoring.extract.method=Extract method +refactoring.extract.method.error.interrupted.execution.flow=Cannot perform refactoring when execution flow is interrupted +refactoring.extract.method.error.star.import=Cannot perform refactoring with star import statement inside code block +refactoring.extract.method.error.bad.selection=Cannot perform extract method using selected element(s) refactoring.extract.method.error.name.clash=Method name clashes with already existing name -refactoring.extract.method.error.cannot.perform.refactoring.with.local=Cannot perform refactoring from expression with local variables modifications and return instructions inside code fragment +refactoring.extract.method.error.returns=Cannot extract method with return instructions inside code fragment +refactoring.extract.method.error.local.variable.modifications=Cannot perform refactoring from expression with local variable modifications inside code fragment +refactoring.extract.method.error.local.variable.modifications.and.returns=Cannot perform refactoring from expression with local variables modifications and return instructions inside code fragment +refactoring.extract.method.error.empty.fragment=Cannot perform refactoring from empty code fragment +refactoring.extract.method.error.undetermined.execution.flow=Cannot determine execution flow for the code fragment +refactoring.extract.method.error.yield=Cannot perform refactoring with 'yield' statement inside code block + # extract superclass refactoring.extract.super.target.path.outside.roots=Target directory is outside the project. Must be within content roots diff --git a/python/src/com/jetbrains/python/codeInsight/codeFragment/PyCodeFragmentUtil.java b/python/src/com/jetbrains/python/codeInsight/codeFragment/PyCodeFragmentUtil.java index b0a8783c2d8e..ca97e7b4e213 100644 --- a/python/src/com/jetbrains/python/codeInsight/codeFragment/PyCodeFragmentUtil.java +++ b/python/src/com/jetbrains/python/codeInsight/codeFragment/PyCodeFragmentUtil.java @@ -56,7 +56,7 @@ public class PyCodeFragmentUtil { final int end = endInScope.getTextOffset() + endInScope.getTextLength(); final ControlFlow flow = ControlFlowCache.getControlFlow(owner); if (flow == null) { - throw new CannotCreateCodeFragmentException("Cannot determine execution flow for the code fragment"); + throw new CannotCreateCodeFragmentException(PyBundle.message("refactoring.extract.method.error.undetermined.execution.flow")); } final List graph = Arrays.asList(flow.getInstructions()); final List subGraph = getFragmentSubGraph(graph, start, end); @@ -64,12 +64,10 @@ public class PyCodeFragmentUtil { if ((subGraphAnalysis.regularExits > 0 && subGraphAnalysis.returns > 0) || subGraphAnalysis.targetInstructions > 1 || subGraphAnalysis.outerLoopBreaks > 0) { - throw new CannotCreateCodeFragmentException( - PyBundle.message("refactoring.extract.method.error.cannot.perform.refactoring.when.execution.flow.is.interrupted")); + throw new CannotCreateCodeFragmentException(PyBundle.message("refactoring.extract.method.error.interrupted.execution.flow")); } if (subGraphAnalysis.starImports > 0) { - throw new CannotCreateCodeFragmentException( - PyBundle.message("refactoring.extract.method.error.cannot.perform.refactoring.when.from.import.inside")); + throw new CannotCreateCodeFragmentException(PyBundle.message("refactoring.extract.method.error.star.import")); } final Set globalWrites = getGlobalWrites(subGraph, owner); @@ -104,7 +102,7 @@ public class PyCodeFragmentUtil { final boolean yieldsFound = subGraphAnalysis.yieldExpressions > 0; if (yieldsFound && LanguageLevel.forElement(owner).isOlderThan(LanguageLevel.PYTHON33)) { - throw new CannotCreateCodeFragmentException("Cannot perform refactoring with 'yield' statement inside code block"); + throw new CannotCreateCodeFragmentException(PyBundle.message("refactoring.extract.method.error.yield")); } return new PyCodeFragment(inputNames, outputNames, globalWrites, nonlocalWrites, subGraphAnalysis.returns > 0, yieldsFound); diff --git a/python/src/com/jetbrains/python/refactoring/extractmethod/PyExtractMethodHandler.java b/python/src/com/jetbrains/python/refactoring/extractmethod/PyExtractMethodHandler.java index 0af213341578..708a27700fb6 100644 --- a/python/src/com/jetbrains/python/refactoring/extractmethod/PyExtractMethodHandler.java +++ b/python/src/com/jetbrains/python/refactoring/extractmethod/PyExtractMethodHandler.java @@ -78,7 +78,7 @@ public class PyExtractMethodHandler implements RefactoringActionHandler { element2 = PyPsiUtils.getSignificantToTheLeft(element2, false); if (element1 == null || element2 == null) { CommonRefactoringUtil.showErrorHint(project, editor, - PyBundle.message("refactoring.extract.method.error.cannot.perform.refactoring.using.selected.elements"), + PyBundle.message("refactoring.extract.method.error.bad.selection"), RefactoringBundle.message("extract.method.title"), "refactoring.extractMethod"); return; } @@ -122,7 +122,7 @@ public class PyExtractMethodHandler implements RefactoringActionHandler { } CommonRefactoringUtil.showErrorHint(project, editor, - PyBundle.message("refactoring.extract.method.error.cannot.perform.refactoring.using.selected.elements"), + PyBundle.message("refactoring.extract.method.error.bad.selection"), RefactoringBundle.message("extract.method.title"), "refactoring.extractMethod"); } diff --git a/python/src/com/jetbrains/python/refactoring/extractmethod/PyExtractMethodUtil.java b/python/src/com/jetbrains/python/refactoring/extractmethod/PyExtractMethodUtil.java index 59a2db24cb93..a0dfa168c14c 100644 --- a/python/src/com/jetbrains/python/refactoring/extractmethod/PyExtractMethodUtil.java +++ b/python/src/com/jetbrains/python/refactoring/extractmethod/PyExtractMethodUtil.java @@ -78,7 +78,7 @@ public class PyExtractMethodUtil { @NotNull final PsiElement statement2) { if (!fragment.getOutputVariables().isEmpty() && fragment.isReturnInstructionInside()) { CommonRefactoringUtil.showErrorHint(project, editor, - PyBundle.message("refactoring.extract.method.error.cannot.perform.refactoring.with.local"), + PyBundle.message("refactoring.extract.method.error.local.variable.modifications.and.returns"), RefactoringBundle.message("error.title"), "refactoring.extractMethod"); return; } @@ -92,7 +92,7 @@ public class PyExtractMethodUtil { final List elementsRange = PyPsiUtils.collectElements(statement1, statement2); if (elementsRange.isEmpty()) { CommonRefactoringUtil.showErrorHint(project, editor, - "Cannot perform refactoring from empty code fragment", + PyBundle.message("refactoring.extract.method.error.empty.fragment"), RefactoringBundle.message("extract.method.title"), "refactoring.extractMethod"); return; } @@ -181,7 +181,7 @@ public class PyExtractMethodUtil { } }); } - }, "Extract method", null); + }, PyBundle.message("refactoring.extract.method"), null); } private static void processDuplicates(@NotNull final PsiElement callElement, @@ -273,14 +273,14 @@ public class PyExtractMethodUtil { @NotNull final PsiElement expression) { if (!fragment.getOutputVariables().isEmpty()) { CommonRefactoringUtil.showErrorHint(project, editor, - "Cannot perform refactoring from expression with local variables modifications inside code fragment", + PyBundle.message("refactoring.extract.method.error.local.variable.modifications"), RefactoringBundle.message("error.title"), "refactoring.extractMethod"); return; } if (fragment.isReturnInstructionInside()) { CommonRefactoringUtil.showErrorHint(project, editor, - "Cannot extract method with return instructions inside code fragment", + PyBundle.message("refactoring.extract.method.error.returns"), RefactoringBundle.message("error.title"), "refactoring.extractMethod"); return; } @@ -350,7 +350,7 @@ public class PyExtractMethodUtil { } }); } - }, "Extract method", null); + }, PyBundle.message("refactoring.extract.method"), null); } } diff --git a/python/testSrc/com/jetbrains/python/refactoring/PyExtractMethodTest.java b/python/testSrc/com/jetbrains/python/refactoring/PyExtractMethodTest.java index 6a54d277c705..759d53157dfb 100644 --- a/python/testSrc/com/jetbrains/python/refactoring/PyExtractMethodTest.java +++ b/python/testSrc/com/jetbrains/python/refactoring/PyExtractMethodTest.java @@ -147,7 +147,7 @@ public class PyExtractMethodTest extends LightMarkedTestCase { } public void testWrongSelectionFromImportStar() { - doFail("bar", "Cannot perform refactoring with from import statement inside code block"); + doFail("bar", "Cannot perform refactoring with star import statement inside code block"); } public void testPy479() {