LineRange (@NotNull Document document, @NotNull PsiElement startElement, @NotNull PsiElement endElement) { CharSequence text = document.getImmutableCharSequence(); int startOffset = startElement.getTextRange().getStartOffset(); int startLine = document.getLineNumber(startOffset); if (!CharArrayUtil.isEmptyOrSpaces(text, document.getLineStartOffset(startLine), startOffset)) { return null; } int endOffset = endElement.getTextRange().getEndOffset(); int endLine = document.getLineNumber(endOffset); if (!CharArrayUtil.isEmptyOrSpaces(text, endOffset, document.getLineEndOffset(endLine))) { return null; } return new LineRange(startLine, endLine + 1); }