@Override
  protected void changeExternalUsage(UsageInfo usage, PsiElementFactory factory)
          throws IncorrectOperationException {
    final PsiElement element = usage.getElement();
    if (!(element instanceof PsiReferenceExpression ref)) return;

    if (ref instanceof PsiMethodReferenceExpression methodRef && needLambdaConversion(methodRef)) {
      PsiMethodCallExpression expression = getMethodCallExpression(methodRef);
      if (expression == null) return;
      ref = expression.getMethodExpression();
    }
    PsiElement parent = ref.getParent();

    PsiExpression instanceRef;

    instanceRef = ref.getQualifierExpression();
    PsiElement newQualifier;

    final PsiClass memberClass = myMember.getContainingClass();
    if (instanceRef == null || instanceRef instanceof PsiSuperExpression) {
      PsiClass contextClass = PsiTreeUtil.getParentOfType(ref, PsiClass.class);
      String qualifier = "";
      if (memberClass != null && !InheritanceUtil.isInheritorOrSelf(contextClass, memberClass, true)) {
        String name = memberClass.getQualifiedName();
        if (name != null) {
          qualifier = name + ".";
        }
      }
      instanceRef = factory.createExpressionFromText(qualifier + "this", null);
      newQualifier = null;
    }
    else {
      newQualifier = memberClass == null || memberClass instanceof PsiAnonymousClass ? null : factory.createReferenceExpression(memberClass);
    }

    if (mySettings.getNewParametersNumber() > 1) {
      int copyingSafetyLevel = RefactoringUtil.verifySafeCopyExpression(instanceRef);
      if (copyingSafetyLevel == RefactoringUtil.EXPR_COPY_PROHIBITED) {
        String tempVar = RefactoringUtil.createTempVar(instanceRef, parent, true);
        instanceRef = factory.createExpressionFromText(tempVar, null);
      }
    }


    PsiElement anchor = null;
    PsiExpressionList argList = null;
    PsiExpression[] exprs = PsiExpression.EMPTY_ARRAY;
    if (parent instanceof PsiMethodCallExpression) {
      argList = ((PsiMethodCallExpression)parent).getArgumentList();
      exprs = argList.getExpressions();
      if (mySettings.isMakeClassParameter()) {
        if (exprs.length > 0) {
          anchor = argList.addBefore(instanceRef, exprs[0]);
        }
        else {
          anchor = argList.add(instanceRef);
        }
      }
    }


    if (mySettings.isMakeFieldParameters()) {
      List<Settings.FieldParameter> parameters = mySettings.getParameterOrderList();

      for (Settings.FieldParameter fieldParameter : parameters) {
        PsiReferenceExpression fieldRef;
        if (newQualifier != null) {
          fieldRef = (PsiReferenceExpression)factory.createExpressionFromText(
            "a." + fieldParameter.field.getName(), null);
          fieldRef.getQualifierExpression().replace(instanceRef);
        }
        else {
          fieldRef = (PsiReferenceExpression)factory.createExpressionFromText(fieldParameter.field.getName(), null);
        }

        if (anchor != null) {
          anchor = argList.addAfter(fieldRef, anchor);
        }
        else if (argList != null) {
          if (exprs.length > 0) {
            anchor = argList.addBefore(fieldRef, exprs[0]);
          }
          else {
            anchor = argList.add(fieldRef);
          }
        }
      }
    }

    if (newQualifier != null) {
      ref.getQualifierExpression().replace(newQualifier);
    }
  }
@Override
  protected void changeExternalUsage(UsageInfo usage, PsiElementFactory factory)