From 5a1588251f5f2bf40956138d4bf6a4e327dd8d2e Mon Sep 17 00:00:00 2001 From: Oleg Shpynov Date: Wed, 16 Jun 2010 17:02:54 +0400 Subject: [PATCH] PY-1086 False positive for "Cannot perform refactoring when execution flow is interrupted" --- .../codeFragment/PyCodeFragmentUtil.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/python/src/com/jetbrains/python/codeInsight/codeFragment/PyCodeFragmentUtil.java b/python/src/com/jetbrains/python/codeInsight/codeFragment/PyCodeFragmentUtil.java index ca1c502f430b..883a62326091 100644 --- a/python/src/com/jetbrains/python/codeInsight/codeFragment/PyCodeFragmentUtil.java +++ b/python/src/com/jetbrains/python/codeInsight/codeFragment/PyCodeFragmentUtil.java @@ -92,9 +92,23 @@ public class PyCodeFragmentUtil { } // If we see more than 1 outer instruction, controlflow is interrupted - if (outerInstructions.size() > 1){ + if (outerInstructions.size() > 2){ throw new CannotCreateCodeFragmentException(PyBundle.message("refactoring.extract.method.error.cannot.perform.refactoring.when.execution.flow.is.interrupted")); } + if (outerInstructions.size() == 2){ + boolean errorFound = true; + for (Instruction outerInstruction : outerInstructions) { + // Here we check control flow when for statement content is beeing extracted + if (outerInstruction instanceof ReadWriteInstruction && + PyForStatementNavigator.getPyForStatementByIterable(outerInstruction.getElement())!=null){ + errorFound = false; + break; + } + } + if (errorFound){ + throw new CannotCreateCodeFragmentException(PyBundle.message("refactoring.extract.method.error.cannot.perform.refactoring.when.execution.flow.is.interrupted")); + } + } // Building code fragment final PyCodeFragmentBuilder builder = new PyCodeFragmentBuilder(owner, start, end);