private static @Nullable PsiTypeElement getRootTypeElement(@NotNull PsiJavaCodeReferenceElement ref) {
    PsiElement root = SyntaxTraverser.psiApi()
      .parents(ref.getParent())
      .takeWhile(it -> it instanceof PsiTypeElement || it instanceof PsiReferenceParameterList || it instanceof PsiJavaCodeReferenceElement)
      .last();
    return ObjectUtils.tryCast(root, PsiTypeElement.class);
  }
private static @Nullable PsiTypeElement getRootTypeElement(@NotNull PsiJavaCodeReferenceElement ref)