PsiStatement (PsiIfStatement statement) { while (true) { final PsiElement parent = statement.getParent(); if (parent instanceof PsiIfStatement parentIfStatement) { final PsiStatement elseBranch = parentIfStatement.getElseBranch(); if (elseBranch == statement) { statement = parentIfStatement; continue; } } return PsiTreeUtil.getNextSiblingOfType(statement, PsiStatement.class); } }