public static <T extends DomElement> DomAnchor<T> createAnchor(@NotNull T t, boolean usePsi) {
    DomInvocationHandler handler = DomManagerImpl.getNotNullHandler(t);
    if (handler.getStub() != null) {
      return new StubAnchor<>(handler);
    }

    if (usePsi) {
      final XmlElement element = t.getXmlElement();
      if (element != null) {
        return new PsiBasedDomAnchor<>(PsiAnchor.create(element), element.getProject());
      }
    }


    final DomElement parent = t.getParent();
    if (parent == null) {
      LOG.error("Parent null: " + t);
    }

    if (parent instanceof DomFileElementImpl fileElement) {
      //noinspection unchecked
      return new RootAnchor<>(fileElement.getFile(), fileElement.getRootElementClass());
    }

    final DomAnchor<DomElement> parentAnchor = createAnchor(parent);
    final String name = t.getGenericInfo().getElementName(t);
    final AbstractDomChildrenDescription description = t.getChildDescription();
    final List<? extends DomElement> values = description.getValues(parent);
    if (name != null) {
      int i = 0;
      for (DomElement value : values) {
        if (value.equals(t)) {
          return new NamedAnchor<>(parentAnchor, description, name, i);
        }
        if (name.equals(value.getGenericInfo().getElementName(value))) {
          i++;
        }
      }
    }

    final int index = values.indexOf(t);
    if (index < 0) {
      diagnoseNegativeIndex2(t, parent, description, values);
    }
    return new IndexedAnchor<>(parentAnchor, description, index);
  }
public static <T extends DomElement> DomAnchor<T> createAnchor(@NotNull T t, boolean usePsi)