boolean (@NotNull PsiCodeBlock body, @NotNull PsiStatement statement) { PsiElement statementToCheck = statement; while (true) { final PsiElement container = getContainingStatementOrBlock(statementToCheck); if (container == null || container instanceof PsiLoopStatement) { return false; } if (container instanceof PsiCodeBlock) { if (!statementIsLastInBlock((PsiCodeBlock)container, (PsiStatement)statementToCheck)) { return false; } if (container.equals(body)) { return true; } statementToCheck = PsiTreeUtil.getParentOfType(container, PsiStatement.class); } else { statementToCheck = container; if (statementToCheck instanceof PsiSwitchLabeledRuleStatement) { statementToCheck = PsiTreeUtil.getParentOfType(statementToCheck, PsiStatement.class); } } } }