Result (char c, @NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) { CodeInsightSettings codeInsightSettings = CodeInsightSettings.getInstance(); if (c == ' ' && codeInsightSettings.JAVADOC_STUB_ON_ENTER) { int offset = editor.getCaretModel().getOffset(); PsiElement element = file.findElementAt(offset); if (element == null && offset > 1) { element = file.findElementAt(offset - 2); } if (element == null) return Result.CONTINUE; int expectedStringStart = offset - 4; // """ or ''' plus space char final Document document = editor.getDocument(); if (PythonEnterHandler.canGenerateDocstring(element, expectedStringStart, document) == DocstringState.INCOMPLETE) { final PyDocStringOwner docOwner = PsiTreeUtil.getParentOfType(element, PyDocStringOwner.class); if (docOwner != null) { final String quotes = document.getText(TextRange.from(expectedStringStart, 3)); final String docString = PyDocstringGenerator.forDocStringOwner(docOwner) .forceNewMode() .withInferredParameters(true) .withQuotes(quotes) .buildDocString(); document.insertString(offset, docString.substring(3)); if (!StringUtil.isEmptyOrSpaces(docString.substring(3, docString.length() - 3))) { editor.getCaretModel().moveCaretRelatively(100, 1, false, false, false); } return Result.STOP; } } } return Result.CONTINUE; }