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