diff --git a/python/src/com/jetbrains/python/codeInsight/intentions/PyGenerateDocstringIntention.java b/python/src/com/jetbrains/python/codeInsight/intentions/PyGenerateDocstringIntention.java index 475b6f110739..d0cdeb8b370a 100644 --- a/python/src/com/jetbrains/python/codeInsight/intentions/PyGenerateDocstringIntention.java +++ b/python/src/com/jetbrains/python/codeInsight/intentions/PyGenerateDocstringIntention.java @@ -67,7 +67,7 @@ public class PyGenerateDocstringIntention extends BaseIntentionAction { private boolean isAvailableForFunction(PyFunction function) { if (function.getDocStringValue() != null) { - final PyDocstringGenerator docstringGenerator = new PyDocstringGenerator(function).withDefaultParameters(); + final PyDocstringGenerator docstringGenerator = new PyDocstringGenerator(function); if (docstringGenerator.hasParametersToAdd()) { myText = PyBundle.message("INTN.add.parameters.to.docstring"); return true; @@ -106,7 +106,6 @@ public class PyGenerateDocstringIntention extends BaseIntentionAction { docstringGenerator .useTypesFromDebuggerSignature(true) .addReturn() - .withDefaultParameters() .addFirstEmptyLine(); if (docStringOwner.getDocStringValue() == null) { diff --git a/python/src/com/jetbrains/python/documentation/PyDocstringGenerator.java b/python/src/com/jetbrains/python/documentation/PyDocstringGenerator.java index dbfa0ed576cb..124d7753dcc2 100644 --- a/python/src/com/jetbrains/python/documentation/PyDocstringGenerator.java +++ b/python/src/com/jetbrains/python/documentation/PyDocstringGenerator.java @@ -45,15 +45,16 @@ import java.util.List; public class PyDocstringGenerator { private final List myParams = Lists.newArrayList(); - private boolean myGenerateReturn; - // Updated after buildAndInsert @NotNull private PyDocStringOwner myDocStringOwner; - private String myQuotes = "\"\"\""; + private boolean myUseTypesFromDebuggerSignature = false; - private boolean myNewMode = false; + private boolean myNewMode = false; // true - generate new string, false - update existing private boolean myAddFirstEmptyLine = false; + private boolean myParametersPrepared = false; + private boolean myGenerateReturn; + private String myQuotes = "\"\"\""; public PyDocstringGenerator(@NotNull PyDocStringOwner docStringOwner) { myDocStringOwner = docStringOwner; @@ -108,10 +109,9 @@ public class PyDocstringGenerator { return this; } - @NotNull - public PyDocstringGenerator withDefaultParameters() { - // Populate parameters lift if no one was specified explicitly - if (myParams.isEmpty()) { + private void prepareParameters() { + // Populate parameter list, if no one was specified explicitly + if (!myParametersPrepared && myParams.isEmpty()) { if (myDocStringOwner instanceof PyFunction) { PySignature signature = null; if (myUseTypesFromDebuggerSignature) { @@ -149,12 +149,12 @@ public class PyDocstringGenerator { } } } - } - return this; + myParametersPrepared = true; } public boolean hasParametersToAdd() { + prepareParameters(); return !myParams.isEmpty(); } @@ -260,6 +260,7 @@ public class PyDocstringGenerator { @NotNull public String buildDocString() { + prepareParameters(); if (isNewMode()) { return createDocString(); } diff --git a/python/src/com/jetbrains/python/editor/PythonEnterHandler.java b/python/src/com/jetbrains/python/editor/PythonEnterHandler.java index 6fe09413b01a..0df65ab46730 100644 --- a/python/src/com/jetbrains/python/editor/PythonEnterHandler.java +++ b/python/src/com/jetbrains/python/editor/PythonEnterHandler.java @@ -264,7 +264,6 @@ public class PythonEnterHandler extends EnterHandlerDelegateAdapter { final String docString = new PyDocstringGenerator(docOwner) .addReturn() .useTypesFromDebuggerSignature(true) - .withDefaultParameters() .withQuotes(quotes) .forceNewMode() .buildDocString();