private void doSwitch(final @NotNull Editor editor, @NotNull Caret caret, @NotNull Project project) {
    if (editor.isViewer() || !EditorModificationUtil.requestWriting(editor)) return;

    PsiDocumentManager.getInstance(project).commitAllDocuments();
    PsiElement exprList = getExpressionList(editor, caret.getOffset(), project);
    if (!(exprList instanceof PsiExpressionList)) return;
    PsiElement call = exprList.getParent();
    if (!(call instanceof PsiCall methodCall)) return;
    int lbraceOffset = exprList.getTextRange().getStartOffset();
    ParameterInfoControllerBase controller = ParameterInfoControllerBase.findControllerAtOffset(editor, lbraceOffset);
    if (controller == null || !controller.isHintShown(false)) return;

    Object[] objects = controller.getObjects();
    Object highlighted = controller.getHighlighted();
    if (objects == null || objects.length <= 1) return;

    Map<String, String> enteredParameters = exprList.getUserData(ENTERED_PARAMETERS);
    if (enteredParameters == null) {
      exprList.putUserData(ENTERED_PARAMETERS, enteredParameters = new HashMap<>());
    }
    boolean virtualComma = Registry.is("editor.completion.hints.virtual.comma");
    int currentIndex;
    if (highlighted == null) {
      currentIndex = mySwitchUp ? objects.length : -1;
    }
    else {
      currentIndex = Arrays.asList(objects).indexOf(highlighted);
      if (currentIndex < 0) return;

      PsiMethod currentMethod = MethodParameterInfoHandler.getMethodFromCandidate(objects[currentIndex]);
      int currentMethodParameterCount = currentMethod.getParameterList().getParametersCount();
      PsiExpression[] enteredExpressions = ((PsiExpressionList)exprList).getExpressions();
      int enteredCount = enteredExpressions.length;
      if (currentMethodParameterCount != enteredCount && !(enteredCount == 0 && currentMethodParameterCount == 1) &&
          (!virtualComma || !currentMethod.isVarArgs() && enteredCount > currentMethodParameterCount)) {
        // when parameter list has been edited, but popup wasn't updated for some reason
        return;
      }

      for (int i = 0; i < enteredExpressions.length; i++) {
        PsiExpression expression = enteredExpressions[i];
        String value = expression.getText().trim();
        if (!value.isEmpty()) {
          String key = getParameterKey(currentMethod, i);
          enteredParameters.put(key, value);
        }
      }
    }

    final PsiMethod targetMethod =
      MethodParameterInfoHandler.getMethodFromCandidate(objects[(currentIndex + (mySwitchUp ? -1 : 1) + objects.length) % objects.length]);

    updateParameterValues(editor, caret, targetMethod, exprList, lbraceOffset, enteredParameters, virtualComma);

    JavaMethodCallElement.setCompletionModeIfNotSet(methodCall, controller);

    PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument());
    CompletionMemory.registerChosenMethod(targetMethod, methodCall);
    controller.setPreservedOnHintHidden(true);
    ParameterHintsPass.asyncUpdate(call, editor);
    controller.showHint(false, false);
  }
private void doSwitch(final @NotNull Editor editor, @NotNull Caret caret, @NotNull Project project)