private static @Nullable PsiJavaCodeReferenceElement getTopLevelRef(@NotNull PsiElement element, @NotNull PsiReferenceList referenceList) {
    while (element.getParent() != referenceList) {
      element = element.getParent();
      if (element == null) return null;
    }
    return ObjectUtils.tryCast(element, PsiJavaCodeReferenceElement.class);
  }
private static @Nullable PsiJavaCodeReferenceElement getTopLevelRef(@NotNull PsiElement element, @NotNull PsiReferenceList referenceList)