private static @Nullable PsiElement getReferencedElement(@NotNull PsiFile file,
                                                           int offset,
                                                           int flags,
                                                           @NotNull Editor editor,
                                                           @Nullable PsiElement leafElement) {
    final PsiElement referenceOrReferencedElement = getReferenceOrReferencedElement(file, editor, flags, offset);
    if (isAcceptableReferencedElement(leafElement, referenceOrReferencedElement)) {
      return referenceOrReferencedElement;
    }
    return null;
  }
private static @Nullable PsiElement getReferencedElement(@NotNull PsiFile file,
                                                           int offset,
                                                           int flags,
                                                           @NotNull Editor editor,
                                                           @Nullable PsiElement leafElement)