PY-29717 Move message about copied docstring to sections

This commit is contained in:
Mikhail Golubev
2018-06-09 15:59:36 +03:00
parent 065ce992dc
commit bf2ee59a28
6 changed files with 19 additions and 36 deletions
@@ -797,13 +797,11 @@ PARSE.expected.@.or.def='@' or 'def' expected
PARSE.expected.formal.param.name=formal parameter name expected
### qiuck doc generator
QDOC.copied.from.$0.$1=<i>Documentation is missing.</i> The following is copied from <code>{0}.{1}</code>.
QDOC.copied.from.builtin=<small>(copied from built-in description)</small>
QDOC.copied.from.class.$0=<i>Documentation is missing.</i> The following is copied from class <code>{0}</code>.
QDOC.module.path.unknown=(Module path is unknown)
QDOC.epydoc.python2.sdk.not.found=You need configured Python 2 SDK to render <a href='http://epydoc.sourceforge.net/'>Epydoc</a> docstrings
QDOC.local.sdk.not.found=You need a configured local Python SDK to render docstrings.
QDOC.assigned.to=Assigned to
QDOC.assigned.to=Assigned to:
QDOC.documentation.is.copied.from=Documentation is copied from:
runcfg.tests.cant_rerun=Can't rerun tests since test IDs can't be resolved. Try to delete run configuration, and create new one using right click.
@@ -301,9 +301,8 @@ public class PyDocumentationBuilder {
PyClass pyClass = null;
final PyFunction pyFunction;
final PyStringLiteralExpression docStringExpression = getEffectiveDocStringExpression(elementDefinition);
ChainIterable<String> content = new ChainIterable<>();
if (docStringExpression != null) {
content = formatDocString(myElement, docStringExpression.getStringValue());
myContent.add(formatDocString(myElement, docStringExpression.getStringValue()));
}
final TypeEvalContext context = TypeEvalContext.userInitiated(elementDefinition.getProject(), elementDefinition.getContainingFile());
@@ -328,7 +327,7 @@ public class PyDocumentationBuilder {
myBody.add(PythonDocumentationProvider.describeDecorators(pyFunction, WRAP_IN_ITALIC, ESCAPE_AND_SAVE_NEW_LINES_AND_SPACES, BR, BR));
myBody.add(PythonDocumentationProvider.describeFunction(pyFunction, WRAP_IN_BOLD, ESCAPE_AND_SAVE_NEW_LINES_AND_SPACES, context));
if (docStringExpression == null) {
content = addInheritedDocString(pyFunction, pyClass);
addInheritedDocString(pyFunction, pyClass);
}
}
else if (elementDefinition instanceof PyFile) {
@@ -347,10 +346,6 @@ public class PyDocumentationBuilder {
}
myBody.add(PythonDocumentationProvider.describeTarget(target, context));
}
if (content != null && !content.isEmpty()) {
myContent.add(content);
}
}
private boolean isAttribute() {
@@ -380,11 +375,10 @@ public class PyDocumentationBuilder {
return resolveResult.isImplicit() ? null : resolveResult.getElement();
}
@Nullable
private static ChainIterable<String> addInheritedDocString(@NotNull final PyFunction pyFunction, @Nullable final PyClass pyClass) {
private void addInheritedDocString(@NotNull final PyFunction pyFunction, @Nullable final PyClass pyClass) {
final String methodName = pyFunction.getName();
if (pyClass == null || methodName == null) {
return null;
return;
}
final boolean isConstructor = PyNames.INIT.equals(methodName);
Iterable<PyClass> classes = pyClass.getAncestorClasses(null);
@@ -409,8 +403,6 @@ public class PyDocumentationBuilder {
if (docstringElement != null) {
final String inheritedDoc = docstringElement.getStringValue();
if (inheritedDoc.length() > 1) {
ChainIterable<String> result = new ChainIterable<>();
result.addItem(BR).addItem(BR);
final String ancestorName = ancestor.getName();
final String ancestorQualifiedName = ancestor.getQualifiedName();
final TypeEvalContext context = TypeEvalContext.userInitiated(pyFunction.getProject(), pyFunction.getContainingFile());
@@ -420,15 +412,12 @@ public class PyDocumentationBuilder {
: ancestorName != null && ancestorQualifiedName != null
? PyDocumentationLink.toPossibleClass(ancestorName, ancestorQualifiedName, pyClass, context)
: null;
if (isFromClass) {
result.addItem(PyBundle.message("QDOC.copied.from.class.$0", ancestorLink));
if (ancestorLink != null) {
final ChainIterable<String> link = mySectionsMap.get(PyBundle.message("QDOC.documentation.is.copied.from"));
link.addWith(TagCode, isFromClass ? $(ancestorLink) : $(ancestorLink).addItem("." + methodName));
}
else {
result.addItem(PyBundle.message("QDOC.copied.from.$0.$1", ancestorLink, methodName));
}
result.addItem(BR).addItem(BR);
result.add(formatDocString(pyFunction, inheritedDoc));
return result;
myContent.add(formatDocString(pyFunction, inheritedDoc));
return;
}
}
}
@@ -437,13 +426,11 @@ public class PyDocumentationBuilder {
// for well-known methods, copy built-in doc string.
// TODO: also handle predefined __xxx__ that are not part of 'object'.
if (PyNames.UNDERSCORED_ATTRIBUTES.contains(methodName)) {
return addPredefinedMethodDoc(pyFunction, methodName);
addPredefinedMethodDoc(pyFunction, methodName);
}
return null;
}
@Nullable
private static ChainIterable<String> addPredefinedMethodDoc(@NotNull PyFunction fun, @NotNull String methodName) {
private void addPredefinedMethodDoc(@NotNull PyFunction fun, @NotNull String methodName) {
final PyClassType objectType = PyBuiltinCache.getInstance(fun).getObjectType(); // old- and new-style classes share the __xxx__ stuff
if (objectType != null) {
final PyClass objectClass = objectType.getPyClass();
@@ -452,13 +439,11 @@ public class PyDocumentationBuilder {
final PyStringLiteralExpression predefinedDocstring = getEffectiveDocStringExpression(predefinedMethod);
final String predefinedDoc = predefinedDocstring != null ? predefinedDocstring.getStringValue() : null;
if (predefinedDoc != null && predefinedDoc.length() > 1) { // only a real-looking doc string counts
ChainIterable<String> result = formatDocString(fun, predefinedDoc);
result.addItem(BR).addItem(BR).addItem(PyBundle.message("QDOC.copied.from.builtin"));
return result;
mySectionsMap.get(PyBundle.message("QDOC.documentation.is.copied.from")).addItem("built-in description");
myContent.add(formatDocString(fun, predefinedDoc));
}
}
}
return null;
}
@NotNull
@@ -1 +1 @@
<html><body><div class='definition'><pre><small>class <a href="psi_element://#class#">Foo</a>(<a href="psi_element://#typename#object">object</a>)</small><br><br>def&nbsp;<b>__init__</b>(self:&nbsp;<a href="psi_element://#typename#Foo">Foo</a>)&nbsp;-&gt;&nbsp;None</pre></div><div class='content'><br><br><i>Documentation is missing.</i> The following is copied from class <code><a href="psi_element://#class#">Foo</a></code>.<br><br>Doc&nbsp;of&nbsp;Foo.</div></body></html>
<html><body><div class='definition'><pre><small>class <a href="psi_element://#class#">Foo</a>(<a href="psi_element://#typename#object">object</a>)</small><br><br>def&nbsp;<b>__init__</b>(self:&nbsp;<a href="psi_element://#typename#Foo">Foo</a>)&nbsp;-&gt;&nbsp;None</pre></div><div class='content'>Doc&nbsp;of&nbsp;Foo.</div><table class='sections'><tr><td valign='top' class='section'><p>Documentation is copied from:</td><td valign='top'><code><a href="psi_element://#class#">Foo</a></code></td></table></body></html>
@@ -1 +1 @@
<html><body><div class='definition'><pre><small>class <a href="psi_element://#class#">Foo</a>(<a href="psi_element://#typename#ClassUndocumentedEmptyConstructor.Moo">Moo</a>)</small><br><br>def&nbsp;<b>__init__</b>(self:&nbsp;<a href="psi_element://#typename#Foo">Foo</a>)&nbsp;-&gt;&nbsp;None</pre></div><div class='content'><br><br><i>Documentation is missing.</i> The following is copied from <code><a href="psi_element://#typename#ClassUndocumentedEmptyConstructor.Moo">Moo</a>.__init__</code>.<br><br>Doc&nbsp;of&nbsp;Moo()</div></body></html>
<html><body><div class='definition'><pre><small>class <a href="psi_element://#class#">Foo</a>(<a href="psi_element://#typename#ClassUndocumentedEmptyConstructor.Moo">Moo</a>)</small><br><br>def&nbsp;<b>__init__</b>(self:&nbsp;<a href="psi_element://#typename#Foo">Foo</a>)&nbsp;-&gt;&nbsp;None</pre></div><div class='content'>Doc&nbsp;of&nbsp;Moo()</div><table class='sections'><tr><td valign='top' class='section'><p>Documentation is copied from:</td><td valign='top'><code><a href="psi_element://#typename#ClassUndocumentedEmptyConstructor.Moo">Moo</a>.__init__</code></td></table></body></html>
@@ -1 +1 @@
<html><body><div class='definition'><pre><small>class <a href="psi_element://#class#">B</a>(<a href="psi_element://#typename#InheritedMethod.A">A</a>)</small><br><br>def&nbsp;<b>foo</b>(self:&nbsp;<a href="psi_element://#typename#B">B</a>)&nbsp;-&gt;&nbsp;None</pre></div><div class='content'><br><br><i>Documentation is missing.</i> The following is copied from <code><a href="psi_element://#typename#InheritedMethod.A">A</a>.foo</code>.<br><br>Doc&nbsp;from&nbsp;A.foo.</div></body></html>
<html><body><div class='definition'><pre><small>class <a href="psi_element://#class#">B</a>(<a href="psi_element://#typename#InheritedMethod.A">A</a>)</small><br><br>def&nbsp;<b>foo</b>(self:&nbsp;<a href="psi_element://#typename#B">B</a>)&nbsp;-&gt;&nbsp;None</pre></div><div class='content'>Doc&nbsp;from&nbsp;A.foo.</div><table class='sections'><tr><td valign='top' class='section'><p>Documentation is copied from:</td><td valign='top'><code><a href="psi_element://#typename#InheritedMethod.A">A</a>.foo</code></td></table></body></html>
@@ -1 +1 @@
<html><body><div class='definition'><pre><small>class <a href="psi_element://#class#">list</a>(<a href="psi_element://#typename#typing.MutableSequence">MutableSequence</a>[_T], Generic[_T])</small><br><br>def&nbsp;<b>count</b>(self:&nbsp;<a href="psi_element://#typename#list">list</a>,&nbsp;object:&nbsp;_T)&nbsp;-&gt;&nbsp;<a href="psi_element://#typename#int">int</a></pre></div><div class='content'>L.count(value)&nbsp;-&gt;&nbsp;integer&nbsp;--&nbsp;return&nbsp;number&nbsp;of&nbsp;occurrences&nbsp;of&nbsp;value&nbsp;</div><table class='sections'><tr><td valign='top' class='section'><p>Assigned to</td><td valign='top'><code>c1</code></td></table></body></html>
<html><body><div class='definition'><pre><small>class <a href="psi_element://#class#">list</a>(<a href="psi_element://#typename#typing.MutableSequence">MutableSequence</a>[_T], Generic[_T])</small><br><br>def&nbsp;<b>count</b>(self:&nbsp;<a href="psi_element://#typename#list">list</a>,&nbsp;object:&nbsp;_T)&nbsp;-&gt;&nbsp;<a href="psi_element://#typename#int">int</a></pre></div><div class='content'>L.count(value)&nbsp;-&gt;&nbsp;integer&nbsp;--&nbsp;return&nbsp;number&nbsp;of&nbsp;occurrences&nbsp;of&nbsp;value&nbsp;</div><table class='sections'><tr><td valign='top' class='section'><p>Assigned to:</td><td valign='top'><code>c1</code></td></table></body></html>