@Override
  public void doApply(@NotNull Editor editor, @NotNull PySmartEnterProcessor processor, @NotNull PyWithStatement withStatement) throws IncorrectOperationException {
    final PsiElement withToken = PyPsiUtils.getFirstChildOfType(withStatement, PyTokenTypes.WITH_KEYWORD);
    assert withToken != null;
    final Document document = editor.getDocument();
    final PsiElement colonToken = PyPsiUtils.getFirstChildOfType(withStatement, PyTokenTypes.COLON);
    if (colonToken == null) {
      PsiElement closingParenthesis = PyPsiUtils.getFirstChildOfType(withStatement, PyTokenTypes.RPAR);
      PyWithItem lastWithItem = ArrayUtil.getLastElement(withStatement.getWithItems());
      PsiElement rightmostElement = closingParenthesis != null ? closingParenthesis :
                                    lastWithItem != null ? lastWithItem :
                                    withToken;
      document.insertString(rightmostElement.getTextRange().getEndOffset(), ":");
    }

    if (withStatement.getWithItems().length != 0) {
      for (PyWithItem withItem : withStatement.getWithItems()) {
        final PsiElement asToken = PyPsiUtils.getFirstChildOfType(withItem, PyTokenTypes.AS_KEYWORD);
        if (asToken != null && withItem.getTarget() == null) {
          int asKeywordEndOffset = asToken.getTextRange().getEndOffset();
          if (!(PsiTreeUtil.nextLeaf(asToken, true) instanceof PsiWhiteSpace)) {
            document.insertString(asKeywordEndOffset," ");
          }
          processor.registerUnresolvedError(asKeywordEndOffset + 1);
          break;
        }
      }
    }
    else {
      int withKeywordEndOffset = withToken.getTextRange().getEndOffset();
      if (!(PsiTreeUtil.nextLeaf(withToken, true) instanceof PsiWhiteSpace)) {
        document.insertString(withKeywordEndOffset, " ");
        processor.registerUnresolvedError(withKeywordEndOffset + 1);
      }
    }
  }
@Override
  public void doApply(@NotNull Editor editor, @NotNull PySmartEnterProcessor processor, @NotNull PyWithStatement withStatement)