mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fixed PY-8946 Classmethod docstring creation
This commit is contained in:
@@ -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)));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user