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;
docstringGenerator
.useTypesFromDebuggerSignature(true)
.addReturn()
- .withDefaultParameters()
.addFirstEmptyLine();
if (docStringOwner.getDocStringValue() == null) {
public class PyDocstringGenerator {
private final List<DocstringParam> 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;
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) {
}
}
}
-
}
- return this;
+ myParametersPrepared = true;
}
public boolean hasParametersToAdd() {
+ prepareParameters();
return !myParams.isEmpty();
}
@NotNull
public String buildDocString() {
+ prepareParameters();
if (isNewMode()) {
return createDocString();
}