boolean (@NotNull Project project, final Editor editor, @NotNull PsiFile file, final PsiElement @NotNull [] elements) { if (elements.length > 0) { final AbstractInplaceIntroducer inplaceIntroducer = AbstractInplaceIntroducer.getActiveIntroducer(editor); if (inplaceIntroducer instanceof InplaceIntroduceParameterPopup) { return false; } final PsiMethod containingMethod = Util.getContainingMethod(elements[0]); if (containingMethod == null) { return false; } final List<PsiMethod> enclosingMethods = CommonJavaRefactoringUtil.getEnclosingMethods(containingMethod); if (enclosingMethods.isEmpty()) { return false; } final PsiElement[] elementsCopy = getElementsInCopy(project, file, elements); final PsiMethod containingMethodCopy = Util.getContainingMethod(elementsCopy[0]); LOG.assertTrue(containingMethodCopy != null); final List<PsiMethod> enclosingMethodsInCopy = CommonJavaRefactoringUtil.getEnclosingMethods(containingMethodCopy); final MyExtractMethodProcessor processor = new MyExtractMethodProcessor(project, editor, elementsCopy, enclosingMethodsInCopy.get(enclosingMethodsInCopy.size() - 1)); try { if (!processor.prepare()) return false; processor.showDialog(); //provide context for generated method to check exceptions compatibility final PsiMethod emptyMethod = processor.generateEmptyMethod("name", elements[0]); final Collection<? extends PsiType> types = FunctionalInterfaceSuggester.suggestFunctionalInterfaces(emptyMethod); if (types.isEmpty()) { return false; } if (types.size() == 1 || ApplicationManager.getApplication().isUnitTestMode()) { final PsiType next = types.iterator().next(); functionalInterfaceSelected(next, enclosingMethods, 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(); LOG.assertTrue(returnType != null); final String title = RefactoringBundle.message("refactoring.introduce.parameter.interface.chooser.popup.title", methodSignature, returnType.getPresentableText()); new PsiTargetNavigator<>(psiClasses).createPopup(project, title, new PsiElementProcessor<>() { @Override public boolean execute(@NotNull PsiClass psiClass) { functionalInterfaceSelected(classes.get(psiClass), enclosingMethods, project, editor, processor, elements); return true; } }).showInBestPositionFor(editor); return true; } return true; } catch (IncorrectOperationException | PrepareFailedException ignore) {} } return false; }