in src/org/jetbrains/r/refactoring/extractmethod/RCodeFragment.kt [70:99]
fun validateExits(): Boolean {
if (!validateLoopExits()) return false
var fail = false
var haveEdgeToExit = false
var haveEdgeToNext = false
val lastInstruction = controlFlow.getInstructionByElement(expressions.last()) ?: return false
ControlFlowUtil.iterate(entryPoint.num(), controlFlow.instructions, {
if (!instructionsInside[it.num()]) {
if (it.element == null) {
haveEdgeToExit = true
}
else {
haveEdgeToNext = true
}
ControlFlowUtil.Operation.CONTINUE
}
else {
if (it != lastInstruction && it.allSucc().any { next -> !instructionsInside[next.num()] && next.element != null }) {
fail = true
ControlFlowUtil.Operation.BREAK
}
else {
ControlFlowUtil.Operation.NEXT
}
}
}, false)
if (fail) return false
if (haveEdgeToNext && haveEdgeToExit) return false
return true
}