void (Editor editor, PsiElement element, DocstringState state) { PyDocStringOwner docOwner = PsiTreeUtil.getParentOfType(element, PyDocStringOwner.class); if (docOwner != null) { final int caretOffset = editor.getCaretModel().getOffset(); final Document document = editor.getDocument(); final String quotes = document.getText(TextRange.from(caretOffset - 3, 3)); final String docString = PyDocstringGenerator.forDocStringOwner(docOwner) .withInferredParameters(true) .withQuotes(quotes) .forceNewMode() .buildDocString(); if (state == DocstringState.INCOMPLETE) { document.insertString(caretOffset, docString.substring(3)); } else if (state == DocstringState.EMPTY) { document.replaceString(caretOffset, caretOffset + 3, docString.substring(3)); } } }