TextRange (PsiFile file, TextRange selectedRange, boolean hasSelection) { if (!hasSelection) { int startOffset = selectedRange.getStartOffset(); int endOffset = selectedRange.getEndOffset(); if (CodeInsightUtil.findStatementsInRange(file, startOffset, endOffset).length == 0) { PsiElement elementAtLineStart = findNonWhiteSpaceElement(file, startOffset); PsiElement statement = PsiTreeUtil.getParentOfType(elementAtLineStart, PsiStatement.class, false); if (statement != null && statement.getTextRange().getStartOffset() == elementAtLineStart.getTextRange().getStartOffset()) { return statement.getTextRange(); } } } return selectedRange; }