PsiElement (PsiElement statement) { if (!(statement instanceof PsiStatement)) return statement; while (true) { PsiElement parent = statement.getParent(); if (parent instanceof PsiDoWhileStatement || parent instanceof PsiLabeledStatement) { statement = parent; continue; } if (parent instanceof PsiCodeBlock && PsiTreeUtil.getPrevSiblingOfType(statement, PsiStatement.class) == null) { PsiElement grandParent = parent.getParent(); if (grandParent instanceof PsiBlockStatement) { statement = grandParent; continue; } } return statement; } }