public static int calcStubIndex(@NotNull StubBasedPsiElement<?> psi) {
    if (psi instanceof PsiFile) {
      return 0;
    }

    StubElement<?> liveStub = psi instanceof StubBasedPsiElementBase ? ((StubBasedPsiElementBase<?>)psi).getGreenStub() : psi.getStub();
    if (liveStub != null) {
      return ((StubBase<?>)liveStub).getStubId();
    }

    return ((PsiFileImpl)psi.getContainingFile()).calcTreeElement().getStubbedSpine().getStubIndex(psi);
  }
public static int calcStubIndex(@NotNull StubBasedPsiElement<?> psi)