private static int getElementHierarchyIndex(@NotNull PsiElement element) {
    TextRange range = element.getTextRange();
    int index = 0;
    for (PsiElement e = element.getParent(); e != null && range.equals(e.getTextRange()); e = e.getParent()) {
      index++;
    }
    return index;
  }
private static int getElementHierarchyIndex(@NotNull PsiElement element)