int (@NotNull PsiElement element) { int i = 0; for (PsiElement sibling : element.getParent().getChildren()) { if (element.equals(sibling)) { return i; } if (isBlockElement(sibling)) { i++; } } throw new RuntimeException("Malformed PSI"); }