TextRange (@Nullable TextRange range, @Nullable PsiFile file, int line) { if (range != null && file != null) { Document document = file.getViewProvider().getDocument(); if (document != null) { TextRange lineRange = DocumentUtil.getLineTextRange(document, line); TextRange res = range.intersection(lineRange); return lineRange.equals(res) ? null : res; } } return range; }