boolean (@NotNull PsiStatement statement) { final PsiElement parent = statement.getParent(); if (parent instanceof PsiIfStatement ifStatement) { if (ifStatement.getThenBranch() == statement && ifStatement.getElseBranch() != null) { return true; } return hasPotentialDanglingElse(ifStatement); } if (parent instanceof PsiLabeledStatement || parent instanceof PsiWhileStatement || parent instanceof PsiForStatement || parent instanceof PsiForeachStatement) { return hasPotentialDanglingElse((PsiStatement)parent); } return false; }