@Nullable
 private static PsiParameter getAnchorParameter(PsiMethod methodToReplaceIn) {
   PsiParameterList parameterList = methodToReplaceIn.getParameterList();
   final PsiParameter anchorParameter;
   final PsiParameter[] parameters = parameterList.getParameters();
   final int length = parameters.length;
   if (!methodToReplaceIn.isVarArgs()) {
     anchorParameter = length > 0 ? parameters[length - 1] : null;
   } else {
     LOG.assertTrue(length > 0);
     LOG.assertTrue(parameters[length - 1].isVarArgs());
     anchorParameter = length > 1 ? parameters[length - 2] : null;
   }
   return anchorParameter;
 }
  private void processChangedMethodCall(PsiElement element) throws IncorrectOperationException {
    if (element.getParent() instanceof PsiMethodCallExpression) {
      PsiMethodCallExpression methodCall = (PsiMethodCallExpression) element.getParent();

      if (myMethodToReplaceIn == myMethodToSearchFor
          && PsiTreeUtil.isAncestor(methodCall, myParameterInitializer, false)) return;

      PsiElementFactory factory =
          JavaPsiFacade.getInstance(methodCall.getProject()).getElementFactory();
      PsiExpression expression = factory.createExpressionFromText(myParameterName, null);
      final PsiExpressionList argList = methodCall.getArgumentList();
      final PsiExpression[] exprs = argList.getExpressions();

      boolean first = false;
      PsiElement anchor = null;
      if (myMethodToSearchFor.isVarArgs()) {
        final int oldParamCount = myMethodToSearchFor.getParameterList().getParametersCount() - 1;
        if (exprs.length >= oldParamCount) {
          if (oldParamCount > 1) {
            anchor = exprs[oldParamCount - 2];
          } else {
            first = true;
            anchor = null;
          }
        } else {
          anchor = exprs[exprs.length - 1];
        }
      } else if (exprs.length > 0) {
        anchor = exprs[exprs.length - 1];
      }

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

      removeParametersFromCall(argList);
    } else {
      LOG.error(element.getParent());
    }
  }