boolean (PsiStatement statement, PsiLoopStatement loop) { if(statement == null || statement == loop) return false; for (PsiStatement sibling = statement; sibling != null; sibling = nextExecutedStatement(sibling)) { if(sibling instanceof PsiContinueStatement continueStatement) { PsiStatement continueTarget = continueStatement.findContinuedStatement(); return PsiTreeUtil.isAncestor(continueTarget, loop, true); } if(sibling instanceof PsiThrowStatement || sibling instanceof PsiReturnStatement) return true; if(sibling instanceof PsiBreakStatement breakStatement) { PsiStatement exitedStatement = breakStatement.findExitedStatement(); if(exitedStatement == loop) return true; return flowBreaksLoop(nextExecutedStatement(exitedStatement), loop); } if (sibling instanceof PsiIfStatement || sibling instanceof PsiSwitchStatement) { if (!PsiTreeUtil.collectElementsOfType(sibling, PsiContinueStatement.class).isEmpty()) return false; } if (sibling instanceof PsiLoopStatement) { if (PsiTreeUtil.collectElements(sibling, e -> e instanceof PsiContinueStatement continueStatement && continueStatement.getLabelIdentifier() != null).length > 0) { return false; } } } return false; }