void (@NotNull final Project project, @NotNull final Editor editor, @NotNull final PsiFile file, @NotNull Consumer<? super PsiElement[]> callback) { editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE); if (!editor.getSelectionModel().hasSelection()) { final int offset = editor.getCaretModel().getOffset(); final List<PsiExpression> expressions = CommonJavaRefactoringUtil.collectExpressions(file, editor, offset, true); if (expressions.isEmpty()) { editor.getSelectionModel().selectLineAtCaret(); } else if (expressions.size() == 1) { callback.accept(new PsiElement[]{expressions.get(0)}); return; } else { IntroduceTargetChooser.showChooser(editor, expressions, new Pass<>() { @Override public void pass(PsiExpression psiExpression) { callback.accept(new PsiElement[]{psiExpression}); } }, new PsiExpressionTrimRenderer.RenderFunction()); return; } } PsiDocumentManager.getInstance(project).commitAllDocuments(); callback.accept(getElements(project, editor, file)); }