boolean (@NotNull GrBlockStatement body, @NotNull GrStatement statement) { GrStatement statementToCheck = statement; while (true) { if (statementToCheck == null) { return false; } final PsiElement container = statementToCheck.getParent(); if (container == null) { return false; } if (container instanceof GrLoopStatement) { return false; } else if (container instanceof GrCaseSection caseSection) { if (!statementIsLastInBlock(caseSection, statementToCheck)) return false; final PsiElement parent = container.getParent(); assert parent instanceof GrSwitchStatement; final GrSwitchStatement switchStatement = (GrSwitchStatement)parent; final GrCaseSection[] sections = switchStatement.getCaseSections(); if (ArrayUtil.getLastElement(sections) != caseSection) { return false; } } else if (container instanceof GrOpenBlock block) { if (!statementIsLastInBlock(block, statementToCheck)) return false; final PsiElement parent = block.getParent(); if (parent instanceof GrBlockStatement blockStatement) { if (blockStatement == body) return true; } } else if (container instanceof GrClosableBlock) { return false; } statementToCheck = getContainingStatement(statementToCheck); } }