@NotNull
  private PsiMethod doRefactoring(UsageInfo[] usages) {
    myTypeParameterReplacements = buildTypeParameterReplacements();
    List<PsiClass> inheritors = new ArrayList<>();

    CommonRefactoringUtil.sortDepthFirstRightLeftOrder(usages);

    // Process usages
    for (final UsageInfo usage : usages) {
      if (usage instanceof MethodCallUsageInfo) {
        processMethodCall(((MethodCallUsageInfo)usage).getMethodCall());
      }
      else if (usage instanceof ParameterUsageInfo && !myParameterIsReassigned) {
        processParameterUsage((ParameterUsageInfo)usage);
      }
      else if (usage instanceof ImplementingClassUsageInfo) {
        inheritors.add(((ImplementingClassUsageInfo)usage).getPsiClass());
      }
      else if (usage instanceof MethodReferenceUsageInfo) {
        processMethodReference((MethodReferenceUsageInfo)usage);
      }
    }

    prepareTypeParameterReplacement();
    if (myTargetParameter != null) {
      if (myParameterIsReassigned) {
        PsiDeclarationStatement statement =
          JavaPsiFacade.getElementFactory(myProject).createVariableDeclarationStatement(myTargetParameter.getName(),
                                                                                        myTargetParameter.getType(),
                                                                                        createThisExpression());
        PsiCodeBlock body = myMethod.getBody();
        assert body != null;
        PsiElement first = body.getFirstBodyElement();
        assert first != null;
        first.getParent().addBefore(statement, first);
      }
      myTargetParameter.delete();
    }
    ChangeContextUtil.encodeContextInfo(myMethod, true);
    PsiMethod result;
    if (!myTargetClass.isInterface()) {
      result = addMethodToClass(myTargetClass);
      fixVisibility(result, usages);
    }
    else {
      result = addMethodToClass(myTargetClass);
      final PsiModifierList modifierList = result.getModifierList();
      final boolean markAsDefault = PsiUtil.isAvailable(JavaFeature.EXTENSION_METHODS, myTargetClass);
      if (markAsDefault) {
        modifierList.setModifierProperty(PsiModifier.DEFAULT, true);
      }
      RefactoringUtil.makeMethodAbstract(myTargetClass, result);

      if (!markAsDefault) {
        for (final PsiClass psiClass : inheritors) {
          final PsiMethod newMethod = addMethodToClass(psiClass);
          String modifier = myNewVisibility != null && !myNewVisibility.equals(VisibilityUtil.ESCALATE_VISIBILITY)
                            ? myNewVisibility
                            : PsiModifier.PUBLIC;
          PsiUtil.setModifierProperty(newMethod, modifier, true);
        }
      }
    }
    return result;
  }
@NotNull
  private PsiMethod doRefactoring(UsageInfo[] usages)