void (@NotNull final Project project, final Editor editor, final PsiFile file, DataContext dataContext) { ExtractMethodHandler.selectAndPass(project, editor, file, elements-> { if (elements.length == 0) { String message = RefactoringBundle .getCannotRefactorMessage(RefactoringBundle.message("selected.block.should.represent.a.set.of.statements.or.an.expression")); showErrorMessage(project, editor, message); return; } PsiElement anchorStatement = elements[0] instanceof PsiComment ? elements[0] : CommonJavaRefactoringUtil.getParentStatement(elements[0], false); PsiElement tempContainer = checkAnchorStatement(project, editor, anchorStatement); if (tempContainer == null) return; PsiElement[] elementsInCopy = IntroduceParameterHandler.getElementsInCopy(project, file, elements); MyExtractMethodProcessor processor = new MyExtractMethodProcessor(project, editor, elementsInCopy, null, IntroduceFunctionalVariableAction.getRefactoringName(), null, HelpID.INTRODUCE_VARIABLE); processor.setShowErrorDialogs(false); try { if (!processor.prepare()) { showErrorMessage(project, editor); return; } } catch (PrepareFailedException e) { showErrorMessage(project, editor, e.getMessage()); return; } if (!processor.showDialog()) return; final PsiMethod emptyMethod = processor.generateEmptyMethod("name", elements[0]); Collection<? extends PsiType> types = FunctionalInterfaceSuggester.suggestFunctionalInterfaces(emptyMethod); if (types.isEmpty()) { types = FunctionalInterfaceSuggester.suggestFunctionalInterfaces(emptyMethod, true); } if (types.isEmpty()) { showErrorMessage(project, editor, JavaBundle.message("introduce.functional.variable.nothing.found.message")); return; } if (types.size() == 1 || ApplicationManager.getApplication().isUnitTestMode()) { functionalInterfaceSelected(ContainerUtil.getFirstItem(types), project, editor, processor, elements); } else { final Map<PsiClass, PsiType> classes = new LinkedHashMap<>(); for (PsiType type : types) { classes.put(PsiUtil.resolveClassInType(type), type); } final PsiClass[] psiClasses = classes.keySet().toArray(PsiClass.EMPTY_ARRAY); final String methodSignature = PsiFormatUtil.formatMethod(emptyMethod, PsiSubstitutor.EMPTY, PsiFormatUtilBase.SHOW_PARAMETERS, PsiFormatUtilBase.SHOW_TYPE); final PsiType returnType = emptyMethod.getReturnType(); assert returnType != null; final String title = JavaBundle.message("introduce.functional.variable.interface.chooser.title", methodSignature, returnType.getPresentableText()); new PsiTargetNavigator<>(psiClasses).createPopup(project, title, psiClass -> { functionalInterfaceSelected(classes.get(psiClass), project, editor, processor, elements); return true; }).showInBestPositionFor(editor); } } ); }