public static PsiElement getNamedElement(@Nullable PsiElement element, int offsetInElement) {
    if (element == null) return null;

    PsiUtilCore.ensureValid(element);

    final List<PomTarget> targets = new ArrayList<>();
    final Consumer<PomTarget> consumer = target -> {
      if (target instanceof PsiDeclaredTarget declaredTarget) {
        final PsiElement navigationElement = declaredTarget.getNavigationElement();
        final TextRange range = declaredTarget.getNameIdentifierRange();
        if (range != null && !range.shiftRight(navigationElement.getTextRange().getStartOffset())
          .contains(element.getTextRange().getStartOffset() + offsetInElement)) {
          return;
        }
      }
      targets.add(target);
    };

    PsiElement parent = element;

    int offset = offsetInElement;
    while (parent != null && !(parent instanceof PsiFileSystemItem)) {
      for (PomDeclarationSearcher searcher : PomDeclarationSearcher.EP_NAME.getExtensions()) {
        searcher.findDeclarationsAt(parent, offset, consumer);
        if (!targets.isEmpty()) {
          final PomTarget target = targets.get(0);
          return target == null ? null : PomService.convertToPsi(element.getProject(), target);
        }
      }
      offset += parent.getStartOffsetInParent();
      parent = parent.getParent();
    }

    return getNamedElement(element);
  }
public static PsiElement getNamedElement(@Nullable PsiElement element, int offsetInElement)