PY-1086 False positive for "Cannot perform refactoring when execution flow is interrupted"

This commit is contained in:
Oleg Shpynov
2010-06-16 18:23:58 +04:00
parent ddd37b8d59
commit 5a1588251f
@@ -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);