@Override
  public void apply(@NotNull Editor editor, @NotNull GroovySmartEnterProcessor processor, @NotNull PsiElement psiElement) {
    final GrArgumentList argList = psiElement instanceof GrCall ? ((GrCall)psiElement).getArgumentList() : null;
    if (argList == null || argList instanceof GrCommandArgumentList) return;

    GrCall call = (GrCall)psiElement;

    PsiElement parenth = argList.getLastChild();

    if (parenth != null && ")".equals(parenth.getText()) || call.hasClosureArguments()) return;

    int endOffset = -1;

    for (PsiElement child = argList.getFirstChild(); child != null; child = child.getNextSibling()) {
      if (!(child instanceof PsiErrorElement errorElement)) continue;

      if (errorElement.getErrorDescription().contains("')'")) {
        endOffset = errorElement.getTextRange().getStartOffset();
        break;
      }
    }

    if (endOffset == -1) {
      endOffset = argList.getTextRange().getEndOffset();
    }

    final GrExpression[] params = argList.getExpressionArguments();
    if (params.length > 0 && GrForBodyFixer.startLine(editor.getDocument(), argList) !=
                             GrForBodyFixer.startLine(editor.getDocument(), params[0])) {
      endOffset = argList.getTextRange().getStartOffset() + 1;
    }

    endOffset = CharArrayUtil.shiftBackward(editor.getDocument().getCharsSequence(), endOffset - 1, " \t\n") + 1;
    editor.getDocument().insertString(endOffset, ")");
  }
@Override
  public void apply(@NotNull Editor editor, @NotNull GroovySmartEnterProcessor processor, @NotNull PsiElement psiElement)