public static PsiElement[] getElements(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) {
    final SelectionModel selectionModel = editor.getSelectionModel();
    if (selectionModel.hasSelection()) {
      int startOffset = selectionModel.getSelectionStart();
      int endOffset = selectionModel.getSelectionEnd();


      PsiElement[] elements;
      PsiExpression expr = CodeInsightUtil.findExpressionInRange(file, startOffset, endOffset);
      if (expr != null) {
        elements = new PsiElement[]{expr};
      }
      else {
        elements = CodeInsightUtil.findStatementsInRange(file, startOffset, endOffset);
        if (elements.length == 0) {
          final PsiExpression expression = IntroduceVariableUtil.getSelectedExpression(project, file, startOffset, endOffset);
          if (expression != null && IntroduceVariableUtil.getErrorMessage(expression) == null) {
            final PsiType originalType = CommonJavaRefactoringUtil.getTypeByExpressionWithExpectedType(expression);
            if (originalType != null) {
              elements = new PsiElement[]{expression};
            }
          }
        }
      }
      return elements;
    }

    final List<PsiExpression> expressions = CommonJavaRefactoringUtil.collectExpressions(file, editor, editor.getCaretModel().getOffset());
    return expressions.toArray(PsiElement.EMPTY_ARRAY);
  }
public static PsiElement[] getElements(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file)