private static @Nullable PsiElement doFindTargetElement(@NotNull Editor editor, int flags, int offset) {
    Project project = editor.getProject();
    if (project == null) return null;

    Document document = editor.getDocument();
    PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(document);
    if (file == null) return null;

    int adjusted = adjustOffset(file, document, offset);

    PsiElement element = file.findElementAt(adjusted);
    if (BitUtil.isSet(flags, REFERENCED_ELEMENT_ACCEPTED)) {
      final PsiElement referencedElement = getReferencedElement(file, offset, flags, editor, element);
      if (referencedElement != null) {
        return referencedElement;
      }
    }

    if (element == null) return null;

    if (BitUtil.isSet(flags, ELEMENT_NAME_ACCEPTED)) {
      if (element instanceof PsiNamedElement) return element;
      return getNamedElement(element, adjusted - element.getTextRange().getStartOffset());
    }
    return null;
  }
private static @Nullable PsiElement doFindTargetElement(@NotNull Editor editor, int flags, int offset)