protected static <T extends PsiNamedElement> int getChildIndex(T element, @NotNull PsiElement parent, String name, Class<? extends T> hisClass) {
    PsiFile file = parent.getContainingFile();
    Set<PsiElement> cache = file == null ? null :
      CachedValuesManager.getCachedValue(file, () -> new CachedValueProvider.Result<>(ContainerUtil.createWeakSet(), file));
    if (cache != null && cache.contains(parent)) return -1;
    PsiElement[] children = parent.getChildren();
    if (children.length > CHILDREN_COUNT_LIMIT) {
      if (cache != null) cache.add(parent);
      return -1;
    }

    int index = 0;

    for (PsiElement child : children) {
      if (ReflectionUtil.isAssignable(hisClass, child.getClass())) {
        T namedChild = hisClass.cast(child);
        final String childName = namedChild.getName();

        if (Objects.equals(name, childName)) {
          if (namedChild.equals(element)) {
            return index;
          }
          index++;
        }
      }
    }

    return index;
  }
protected static <T extends PsiNamedElement> int getChildIndex(T element, @NotNull PsiElement parent, String name, Class<? extends T> hisClass)