boolean (IntroduceVariableBase.JavaReplaceChoice replaceAllOccurrences, int replaceFieldsWithGetters, @NonNls String parameterName, boolean searchForSuper, boolean declareFinal, boolean removeUnusedParameters, boolean generateDelegate, int enclosingLevel, final boolean replaceDuplicates) { final ElementToWorkOn[] elementToWorkOn = new ElementToWorkOn[1]; ElementToWorkOn.processElementToWorkOn(getEditor(), getFile(), "INtr param", HelpID.INTRODUCE_PARAMETER, getProject(), new ElementToWorkOn.ElementsProcessor<>() { @Override public boolean accept(ElementToWorkOn el) { return true; } @Override public void pass(final ElementToWorkOn e) { if (e != null) { elementToWorkOn[0] = e; } } }); final PsiExpression expr = elementToWorkOn[0].getExpression(); final PsiLocalVariable localVar = elementToWorkOn[0].getLocalVariable(); PsiElement context = expr == null ? localVar : expr; PsiMethod method = Util.getContainingMethod(context); if (method == null) return false; final List<PsiMethod> methods = CommonJavaRefactoringUtil.getEnclosingMethods(method); assertTrue(methods.size() > enclosingLevel); method = methods.get(enclosingLevel); final PsiMethod methodToSearchFor; if (searchForSuper) { methodToSearchFor = method.findDeepestSuperMethods()[0]; } else { methodToSearchFor = method; } PsiExpression[] occurrences; PsiExpression initializer; if (expr == null) { initializer = localVar.getInitializer(); assertNotNull(initializer); occurrences = CodeInsightUtil.findReferenceExpressions(method, localVar); } else { initializer = expr; occurrences = new ExpressionOccurrenceManager(expr, method, null).findExpressionOccurrences(); } IntArrayList parametersToRemove = removeUnusedParameters ? new IntArrayList(Util.findParametersToRemove(method, initializer, occurrences)) : new IntArrayList(); IntroduceParameterProcessor processor = new IntroduceParameterProcessor( getProject(), method, methodToSearchFor, initializer, expr, localVar, true, parameterName, replaceAllOccurrences, replaceFieldsWithGetters, declareFinal, generateDelegate, false, null, parametersToRemove ) { @Override protected boolean isReplaceDuplicates() { return replaceDuplicates; } }; PsiType initializerType = initializer.getType(); if (initializerType != null && initializerType != PsiTypes.nullType()) { PsiExpression lambda = AnonymousCanBeLambdaInspection.replaceAnonymousWithLambda(initializer, initializerType); if (lambda != null) { processor.setParameterInitializer(lambda); } } processor.run(); getEditor().getSelectionModel().removeSelection(); return true; }