fixed PY-8946 Classmethod docstring creation

This commit is contained in:
Ekaterina Tuzova
2013-09-19 20:27:18 +04:00
parent b1b5450771
commit 8a059733eb
3 changed files with 12 additions and 6 deletions
@@ -328,6 +328,7 @@ public class PyNames {
// canonical names, not forced by interpreter
public static final String CANONICAL_SELF = "self";
public static final String CANONICAL_CLS = "cls";
public static final String BASESTRING = "basestring";
/**
@@ -534,8 +534,11 @@ public class PythonDocumentationProvider extends AbstractDocumentationProvider i
}
String docContent = ws + generateDocumentationContentStub(function, ws, true);
PyExpressionStatement string = elementGenerator.createDocstring("\"\"\"" + docContent + "\"\"\"");
if (insertPlace.getStatements().length != 0) {
insertPlace.addBefore(string, insertPlace.getStatements()[0]);
if (insertPlace != null) {
final PyStatement[] statements = insertPlace.getStatements();
if (statements.length != 0) {
insertPlace.addBefore(string, statements[0]);
}
}
PyStringLiteralExpression docstring = function.getDocStringExpression();
if (editor != null && docstring != null) {
@@ -563,12 +566,14 @@ public class PythonDocumentationProvider extends AbstractDocumentationProvider i
final StringBuilder builder = new StringBuilder(offset);
final TypeEvalContext context = TypeEvalContext.userInitiated(function.getContainingFile());
PySignature signature = PySignatureCacheManager.getInstance(function.getProject()).findSignature(function);
final PyDecoratorList decoratorList = function.getDecoratorList();
final PyDecorator classMethod = decoratorList == null ? null : decoratorList.findDecorator(PyNames.CLASSMETHOD);
for (PyParameter p : PyUtil.getParameters(function, context)) {
final String parameterName = p.getName();
if (p.getText().equals(PyNames.CANONICAL_SELF) || parameterName == null) {
continue;
}
if (classMethod != null && parameterName.equals(PyNames.CANONICAL_CLS)) continue;
String argType = signature == null ? null : signature.getArgTypeQualifiedName(parameterName);
if (argType == null) {
@@ -583,7 +588,7 @@ public class PythonDocumentationProvider extends AbstractDocumentationProvider i
builder.append("type ");
builder.append(parameterName);
builder.append(": ");
if (signature != null) {
if (signature != null && argType != null) {
builder.append(PySignatureUtil.getShortestImportableName(function, argType));
}
builder.append(offset);
@@ -230,13 +230,13 @@ public class PythonEnterHandler extends EnterHandlerDelegateAdapter {
if (fun != null) {
String docStub = provider.generateDocumentationContentStub(fun, false);
docStub += element.getParent().getText().substring(0,3);
if (docStub != null && docStub.length() != 0) {
if (docStub.length() != 0) {
editor.getDocument().insertString(editor.getCaretModel().getOffset(), docStub);
return;
}
}
PyElement klass = PsiTreeUtil.getParentOfType(element, PyClass.class, PyFile.class);
if (klass != null) {
if (klass != null && element != null) {
editor.getDocument().insertString(editor.getCaretModel().getOffset(),
PythonDocCommentUtil.generateDocForClass(klass, element.getParent().getText().substring(0, 3)));
}