@Override
  protected void doApply(@NotNull Editor editor, @NotNull PySmartEnterProcessor processor, @NotNull PyCaseClause element) {
    PyPattern pattern = element.getPattern();
    PsiElement ifKeyword = PyPsiUtils.getFirstChildOfType(element, PyTokenTypes.IF_KEYWORD);
    PyExpression condition = element.getGuardCondition();
    PsiElement colon = PyPsiUtils.getFirstChildOfType(element, PyTokenTypes.COLON);
    Document document = editor.getDocument();
    int colonOffset;
    if (colon == null) {
      String colonSuffix;
      if (condition != null) {
        colonSuffix = ":";
        colonOffset = condition.getTextRange().getEndOffset();
      }
      else if (ifKeyword != null) {
        colonSuffix = " :";
        colonOffset = ifKeyword.getTextRange().getEndOffset() + 1;
      }
      else if (pattern != null) {
        colonSuffix = ":";
        colonOffset = pattern.getTextRange().getEndOffset();
      }
      else {
        colonSuffix = " :";
        colonOffset = element.getFirstChild().getTextRange().getEndOffset() + 1;
      }
      document.insertString(colonOffset - (colonSuffix.length() - 1), colonSuffix);
    }
    else {
      colonOffset = colon.getTextOffset();
    }
    
    if (pattern == null) {
      if (ifKeyword != null) {
        int ifOffset = ifKeyword.getTextOffset();
        PsiWhiteSpace prevWhitespace = as(ifKeyword.getPrevSibling(), PsiWhiteSpace.class);
        if (prevWhitespace != null && prevWhitespace.getTextLength() < 2) {
          document.insertString(ifOffset, " ");
        }
        processor.registerUnresolvedError(ifOffset);
      }
      else {
        processor.registerUnresolvedError(colonOffset);
      }
    }
    else if (ifKeyword != null && condition == null) {
      if (ifKeyword.getTextRange().getEndOffset() == colonOffset) {
        document.insertString(colonOffset, " ");
        processor.registerUnresolvedError(colonOffset + 1);
      }
      else {
        processor.registerUnresolvedError(colonOffset);
      }
    }
  }
@Override
  protected void doApply(@NotNull Editor editor, @NotNull PySmartEnterProcessor processor, @NotNull PyCaseClause element)