void (@NotNull Project project, Editor editor, @NotNull JavaReplaceChoice choice, @Nullable PsiElement targetContainer, @NotNull ExpressionOccurrenceManager occurrenceManager, @NotNull PsiType originalType, @NotNull Consumer<? super JavaReplaceChoice> dialogIntroduce) { boolean inFinalContext = occurrenceManager.isInFinalContext(); PsiExpression expr = occurrenceManager.getMainOccurence(); PsiExpression[] selectedOccurrences = choice.filter(occurrenceManager); final InputValidator validator = new InputValidator(this, project, occurrenceManager); final TypeSelectorManagerImpl typeSelectorManager = new TypeSelectorManagerImpl(project, originalType, expr, selectedOccurrences); typeSelectorManager.setAllOccurrences(true); boolean hasWriteAccess = ContainerUtil.exists(selectedOccurrences, occ -> PsiUtil.isAccessedForWriting(occ)); final PsiElement chosenAnchor = getAnchor(selectedOccurrences); final IntroduceVariableSettings settings = getSettings(project, editor, expr, selectedOccurrences, typeSelectorManager, inFinalContext, hasWriteAccess, validator, chosenAnchor, choice); if (choice.isChain()) { myInplaceIntroducer = new ChainCallInplaceIntroducer(project, settings, chosenAnchor, editor, expr, selectedOccurrences, typeSelectorManager, getRefactoringName()); if (!myInplaceIntroducer.startInplaceIntroduceTemplate()) { dialogIntroduce.accept(choice); } } else { final boolean cantChangeFinalModifier = hasWriteAccess || inFinalContext && choice.isAll() || chosenAnchor instanceof PsiSwitchLabelStatementBase; Consumer<? super PsiElement> callback = container-> { PsiElement anchor = container instanceof PsiLambdaExpression ? getAnchor(container) : container; if (checkAnchorStatement(project, editor, anchor) == null) { return; } myInplaceIntroducer = new JavaVariableInplaceIntroducer(project, settings, anchor, editor, expr, cantChangeFinalModifier, selectedOccurrences, typeSelectorManager, getRefactoringName()); if (!myInplaceIntroducer.startInplaceIntroduceTemplate()) { dialogIntroduce.accept(choice); } }; if (targetContainer != null) { callback.accept(targetContainer); } else { IntroduceVariableTargetBlockChooser.chooseTargetAndPerform(editor, chosenAnchor, expr, callback); } } }