void (UsageInfo @NotNull [] usages) { try { PsiElementFactory factory = JavaPsiFacade.getElementFactory(myManager.getProject()); PsiType initializerType = getInitializerType(myForcedType, myParameterInitializer, myLocalVariable); setForcedType(initializerType); // Converting myParameterInitializer if (myParameterInitializer == null) { LOG.assertTrue(myLocalVariable != null); myParameterInitializer = factory.createExpressionFromText(myLocalVariable.getName(), myLocalVariable); } else if (myParameterInitializer instanceof PsiArrayInitializerExpression){ final PsiExpression newExprArrayInitializer = CommonJavaRefactoringUtil.createNewExpressionFromArrayInitializer((PsiArrayInitializerExpression)myParameterInitializer, initializerType); myParameterInitializer = (PsiExpression)myParameterInitializer.replace(newExprArrayInitializer); } else { if (myReplaceWithLambda) { PsiExpression lambda = AnonymousCanBeLambdaInspection.replaceAnonymousWithLambda(myParameterInitializer, initializerType); if (lambda != null) { if (lambda instanceof PsiLambdaExpression) { lambda = LambdaCanBeMethodReferenceInspection.replaceLambdaWithMethodReference((PsiLambdaExpression)lambda); } myParameterInitializer = lambda; } } } myInitializerWrapper = new JavaExpressionWrapper(myParameterInitializer); // Changing external occurrences (the tricky part) IntroduceParameterUtil.processUsages(usages, this); if (myGenerateDelegate) { generateDelegate(myMethodToReplaceIn); if (myMethodToReplaceIn != myMethodToSearchFor) { final PsiMethod method = generateDelegate(myMethodToSearchFor); if (method.getContainingClass().isInterface()) { final PsiCodeBlock block = method.getBody(); if (block != null) { block.delete(); } } } } // Changing signature of initial method // (signature of myMethodToReplaceIn will be either changed now or have already been changed) LOG.assertTrue(initializerType.isValid()); final FieldConflictsResolver fieldConflictsResolver = new FieldConflictsResolver(myParameterName, myMethodToReplaceIn.getBody()); IntroduceParameterUtil.changeMethodSignatureAndResolveFieldConflicts(new UsageInfo(myMethodToReplaceIn), usages, this); if (myMethodToSearchFor != myMethodToReplaceIn) { IntroduceParameterUtil.changeMethodSignatureAndResolveFieldConflicts(new UsageInfo(myMethodToSearchFor), usages, this); } else if (myGenerateDelegate && myMethodToReplaceIn.findSuperMethods().length == 0) { final PsiAnnotation annotation = AnnotationUtil.findAnnotation(myMethodToReplaceIn, true, Override.class.getName()); if (annotation != null) { annotation.delete(); } } ChangeContextUtil.clearContextInfo(myParameterInitializer); // Replacing expression occurrences for (UsageInfo usage : usages) { if (usage instanceof ChangedMethodCallInfo) { PsiElement element = usage.getElement(); processChangedMethodCall(element); } else if (usage instanceof InternalUsageInfo) { PsiElement element = usage.getElement(); if (element instanceof PsiExpression) { element = CommonJavaRefactoringUtil.outermostParenthesizedExpression((PsiExpression)element); } if (element != null) { if (element.getParent() instanceof PsiExpressionStatement) { element.getParent().delete(); } else { PsiExpression newExpr = factory.createExpressionFromText(myParameterName, element); IntroduceVariableUtil.replace((PsiExpression)element, newExpr, myProject); } } } } if(myLocalVariable != null && myRemoveLocalVariable) { myLocalVariable.normalizeDeclaration(); myLocalVariable.getParent().delete(); } fieldConflictsResolver.fix(); } catch (IncorrectOperationException ex) { LOG.error(ex); } if (isReplaceDuplicates()) { ApplicationManager.getApplication().invokeLater(() -> processMethodsDuplicates(), myProject.getDisposed()); } }