@Override
  public void apply(Editor editor, AbstractBasicJavaSmartEnterProcessor processor, @NotNull ASTNode astNode) throws IncorrectOperationException {
    PsiElement psiElement = BasicJavaAstTreeUtil.toPsi(astNode);
    PsiExpressionList argList = null;
    if (psiElement instanceof PsiMethodCallExpression && !(psiElement instanceof JspMethodCall)) {
      argList = ((PsiMethodCallExpression)psiElement).getArgumentList();
    }
    else if (psiElement instanceof PsiNewExpression) {
      argList = ((PsiNewExpression)psiElement).getArgumentList();
    }

    int caret = editor.getCaretModel().getOffset();
    if (argList != null && !hasRParenth(argList)) {
      PsiCallExpression innermostCall =
        PsiTreeUtil.findElementOfClassAtOffset(psiElement.getContainingFile(), caret - 1, PsiCallExpression.class, false);

      while (innermostCall != null && innermostCall != psiElement && hasRParenth(innermostCall.getArgumentList())
             && innermostCall.resolveMethodGenerics().isValidResult()) {
        innermostCall = PsiTreeUtil.getParentOfType(innermostCall, PsiCallExpression.class);
      }
      if (innermostCall == null) return;

      argList = innermostCall.getArgumentList();
      if (argList == null) return;

      int endOffset = getMissingParenthesisOffset(argList);

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

      PsiExpression[] args = argList.getExpressions();
      if (args.length > 0 &&
          startLine(editor, argList) != startLine(editor, args[0]) &&
          caret < args[0].getTextRange().getStartOffset()) {
        endOffset = argListRange.getStartOffset() + 1;
      }

      if (args.length > 0 && !DumbService.isDumb(argList.getProject())) {
        int caretArg = getCaretArgIndex(caret, argListRange, args);

        LongRangeSet innerCounts = getPossibleParameterCounts(innermostCall).meet(LongRangeSet.range(caretArg, args.length));
        if (!innerCounts.isEmpty()) {
          innerCounts = tryFilterByOuterCall(innermostCall, args, innerCounts);
          int minArg = (int)innerCounts.min();
          if (minArg > 0) {
            endOffset = Math.min(endOffset, args[minArg - 1].getTextRange().getEndOffset());
          }
        }
      }

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