boolean (PsiReturnStatement returnStatement, PsiCodeBlock block) { PsiElement parent = returnStatement.getParent(); while (parent instanceof PsiCodeBlock) { PsiElement grandParent = parent.getParent(); if (grandParent instanceof PsiBlockStatement) { parent = grandParent.getParent(); continue; } if (grandParent instanceof PsiCatchSection) { parent = grandParent.getParent(); break; } if (grandParent instanceof PsiStatement) { parent = grandParent; break; } return parent != block; } if (!(parent instanceof PsiStatement currentContext)) return true; PsiStatement loopOrSwitch = PsiTreeUtil.getNonStrictParentOfType(currentContext, PsiLoopStatement.class, PsiSwitchStatement.class); if (loopOrSwitch != null && PsiTreeUtil.isAncestor(block, loopOrSwitch, true)) { currentContext = loopOrSwitch; } else { while (currentContext instanceof PsiIfStatement) { PsiElement ifParent = currentContext.getParent(); if (ifParent instanceof PsiIfStatement) { currentContext = (PsiStatement)ifParent; } else if (ifParent instanceof PsiCodeBlock) { if (!(ifParent.getParent() instanceof PsiStatement)) { return ifParent != block; } currentContext = (PsiStatement)ifParent.getParent(); if (!(currentContext instanceof PsiBlockStatement) || !(currentContext.getParent() instanceof PsiIfStatement) || ControlFlowUtils.codeBlockMayCompleteNormally((PsiCodeBlock)ifParent)) { break; } currentContext = (PsiStatement)currentContext.getParent(); } } } while (true) { PsiElement contextParent = currentContext.getParent(); if (contextParent instanceof PsiCodeBlock) { PsiStatement[] contextStatements = ((PsiCodeBlock)contextParent).getStatements(); int pos = ArrayUtil.indexOf(contextStatements, currentContext); assert pos >= 0; if (pos < contextStatements.length - 1) return true; if (contextParent == block) return false; if (!(contextParent.getParent() instanceof PsiStatement)) return true; currentContext = (PsiStatement)contextParent.getParent(); } else if (contextParent instanceof PsiIfStatement || contextParent instanceof PsiLabeledStatement) { currentContext = (PsiStatement)contextParent; } else { return true; } } }