public static int getActualLineNumber(Project project, @Nullable XSourcePosition position) {
    if (position == null) {
      return -1;
    }
    final PsiElement element = findContextElement(project, position);
    if (element == null) {
      return -1;
    }

    if (element instanceof XmlToken) {
      final IElementType tokenType = ((XmlToken)element).getTokenType();
      if (tokenType == XmlTokenType.XML_START_TAG_START || tokenType == XmlTokenType.XML_NAME) {
        final PsiManager psiManager = PsiManager.getInstance(project);
        final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
        final PsiFile psiFile = psiManager.findFile(position.getFile());
        if (psiFile == null) {
          return -1;
        }

        final Document document = documentManager.getDocument(psiFile);
        if (document == null) {
          return -1;
        }

        if (document.getLineNumber(element.getTextRange().getStartOffset()) == position.getLine()) {
          final XmlTag tag = PsiTreeUtil.getParentOfType(element, XmlTag.class, false);
          if (tag != null) {
            final ASTNode node = tag.getNode();
            assert node != null;
            // TODO: re-check if/when Xalan is supported
            final ASTNode end = XmlChildRole.START_TAG_END_FINDER.findChild(node);
            if (end != null) {
              return document.getLineNumber(end.getTextRange().getEndOffset()) + 1;
            } else {
              final ASTNode end2 = XmlChildRole.EMPTY_TAG_END_FINDER.findChild(node);
              if (end2 != null) {
                return document.getLineNumber(end2.getTextRange().getEndOffset()) + 1;
              }
            }
          }
        }
      }
    }
    return -1;
  }
public static int getActualLineNumber(Project project, @Nullable XSourcePosition position)