void (UsageInfo @NotNull [] usages) { PsiMethod patternMethod = createMethodToAdd(); final List<PsiReference> docRefs = new ArrayList<>(); for (UsageInfo usage : usages) { if (usage instanceof InheritorUsageInfo) { final PsiClass inheritor = ((InheritorUsageInfo)usage).getInheritor(); addMethodToClass(inheritor, patternMethod, true); } else if (usage instanceof MethodCallUsageInfo && !((MethodCallUsageInfo)usage).isInternal()) { final PsiElement expression = ((MethodCallUsageInfo)usage).getMethodCallExpression(); if (expression instanceof PsiMethodCallExpression) { correctMethodCall((PsiMethodCallExpression)expression, false); } else if (expression instanceof PsiMethodReferenceExpression methodReferenceExpression) { PsiExpression qualifierExpression = methodReferenceExpression.getQualifierExpression(); if (myTargetVariable instanceof PsiParameter && shouldBeExpandedToLambda(methodReferenceExpression, myMethod.getParameterList().getParameterIndex((PsiParameter)myTargetVariable))) { PsiLambdaExpression lambdaExpression = LambdaRefactoringUtil.convertMethodReferenceToLambda(methodReferenceExpression, false, true); if (lambdaExpression != null) { List<PsiExpression> returnExpressions = LambdaUtil.getReturnExpressions(lambdaExpression); if (!returnExpressions.isEmpty()) { correctMethodCall((PsiMethodCallExpression)returnExpressions.get(0), false); } } } else { String exprText; if (myTargetVariable instanceof PsiParameter || qualifierExpression instanceof PsiReferenceExpression && ((PsiReferenceExpression)qualifierExpression).resolve() == myMethod.getContainingClass()) { exprText = myTargetVariable.getType().getCanonicalText(); } else if (qualifierExpression instanceof PsiReferenceExpression) { exprText = qualifierExpression.getText() + "." + myTargetVariable.getName(); } else { exprText = myTargetVariable.getName(); } PsiExpression newQualifier = JavaPsiFacade.getElementFactory(myProject).createExpressionFromText(exprText, null); ((PsiMethodReferenceExpression)expression).setQualifierExpression(newQualifier); JavaCodeStyleManager.getInstance(myProject).shortenClassReferences(expression); } } } else if (usage instanceof JavadocUsageInfo) { docRefs.add(usage.getElement().getReference()); } } try { final PsiModifierList modifierList = patternMethod.getModifierList(); if (myTargetClass.isInterface()) { if (!PsiUtil.isLanguageLevel8OrHigher(myTargetClass)) { patternMethod.getBody().delete(); modifierList.setModifierProperty(PsiModifier.DEFAULT, false); } else { modifierList.setModifierProperty(PsiModifier.DEFAULT, true); } RefactoringUtil.makeMethodAbstract(myTargetClass, patternMethod); } else if (myMethod.hasModifierProperty(PsiModifier.DEFAULT)) { modifierList.setModifierProperty(PsiModifier.DEFAULT, false); VisibilityUtil.setVisibility(modifierList, PsiModifier.PUBLIC); } final PsiMethod method = addMethodToClass(myTargetClass, patternMethod, false); myMethod.delete(); for (PsiReference reference : docRefs) { reference.bindToElement(method); } VisibilityUtil.fixVisibility(UsageViewUtil.toElements(usages), method, myNewVisibility); if (myOpenInEditor) { EditorHelper.openInEditor(method); } } catch (IncorrectOperationException e) { LOG.error(e); } }