@NotNull
  public static Pair<TextRange, List<PsiExpression>> getExpressionsAndSelectionRange(@NotNull final Project project,
                                                                                     final Editor editor,
                                                                                     final PsiFile file,
                                                                                     int offset) {
    final PsiElement[] statementsInRange = IntroduceVariableUtil.findStatementsAtOffset(editor, file, offset);

    Document document = editor.getDocument();
    int line = document.getLineNumber(offset);
    TextRange lineRange =
      TextRange.create(document.getLineStartOffset(line), Math.min(document.getLineEndOffset(line) + 1, document.getTextLength()));

    //try line selection
    if (statementsInRange.length == 1 && IntroduceVariableUtil.selectLineAtCaret(offset, statementsInRange)) {
      final PsiExpression expressionInRange =
        findExpressionInRange(project, file, lineRange.getStartOffset(), lineRange.getEndOffset());
      if (expressionInRange != null && IntroduceVariableUtil.getErrorMessage(expressionInRange) == null) {
        return Pair.create(lineRange, Collections.singletonList(expressionInRange));
      }
    }

    final List<PsiExpression> expressions = ContainerUtil
      .filter(CommonJavaRefactoringUtil.collectExpressions(file, editor, offset), expression ->
        CommonJavaRefactoringUtil.getParentStatement(expression, false) != null ||
        PsiTreeUtil.getParentOfType(expression, PsiField.class, true, PsiStatement.class) != null);
    if (expressions.isEmpty()) {
      return Pair.create(lineRange, Collections.emptyList());
    }
    else if (!IntroduceVariableUtil.isChooserNeeded(expressions)) {
      return Pair.create(expressions.get(0).getTextRange(), expressions);
    }
    else {
      return Pair.create(null, expressions);
    }
  }
@NotNull
  public static Pair<TextRange, List<PsiExpression>> getExpressionsAndSelectionRange(@NotNull final Project project,
                                                                                     final Editor editor,
                                                                                     final PsiFile file,
                                                                                     int offset)