void (@NotNull final Project project, final Editor editor, final PsiFile file, @Nullable final DataContext dataContext) { if (editor == null || file == null) return; final SelectionModel selectionModel = editor.getSelectionModel(); if (!selectionModel.hasSelection()) { final int offset = editor.getCaretModel().getOffset(); final List<GrExpression> expressions = GrIntroduceHandlerBase.collectExpressions(file, editor, offset, false); if (expressions.isEmpty()) { GrIntroduceHandlerBase.updateSelectionForVariable(editor, file, selectionModel, offset); } else if (expressions.size() == 1 || ApplicationManager.getApplication().isUnitTestMode()) { final TextRange textRange = expressions.get(0).getTextRange(); selectionModel.setSelection(textRange.getStartOffset(), textRange.getEndOffset()); } else { IntroduceTargetChooser.showChooser(editor, expressions, new Pass<>() { @Override public void pass(final GrExpression selectedValue) { invoke(project, editor, file, selectedValue.getTextRange().getStartOffset(), selectedValue.getTextRange().getEndOffset()); } }, grExpression -> grExpression.getText() ); return; } } invoke(project, editor, file, selectionModel.getSelectionStart(), selectionModel.getSelectionEnd()); }