Remove separate document link type for super class. Use link type for class instead.

This commit is contained in:
Semyon Proshev
2017-09-22 15:52:15 +03:00
parent adddb531d8
commit 952582abc5
16 changed files with 32 additions and 38 deletions
@@ -392,8 +392,14 @@ public class PyDocumentationBuilder {
if (inheritedDoc.length() > 1) {
myEpilog.addItem(BR).addItem(BR);
final String ancestorName = ancestor.getName();
final String ancestorLink =
pyClass == ancestor ? PyDocumentationLink.toContainingClass(ancestorName) : PyDocumentationLink.toAncestorOfContainingClass(ancestorName);
final String ancestorQualifiedName = ancestor.getQualifiedName();
final TypeEvalContext context = TypeEvalContext.userInitiated(pyFunction.getProject(), pyFunction.getContainingFile());
final String ancestorLink = pyClass == ancestor
? PyDocumentationLink.toContainingClass(ancestorName)
: ancestorName != null && ancestorQualifiedName != null
? PyDocumentationLink.toPossibleClass(ancestorName, ancestorQualifiedName, pyClass, context)
: null;
if (isFromClass) {
myEpilog.addItem(PyBundle.message("QDOC.copied.from.class.$0", ancestorLink));
}
@@ -28,7 +28,6 @@ import com.jetbrains.python.psi.types.TypeEvalContext
object PyDocumentationLink {
private const val LINK_TYPE_CLASS = "#class#"
private const val LINK_TYPE_PARENT = "#parent#"
private const val LINK_TYPE_PARAM = "#param#"
private const val LINK_TYPE_TYPENAME = "#typename#"
@@ -37,11 +36,6 @@ object PyDocumentationLink {
return "<a href=\"${DocumentationManagerProtocol.PSI_ELEMENT_PROTOCOL}$LINK_TYPE_CLASS\">$content</a>"
}
@JvmStatic
fun toAncestorOfContainingClass(ancestor: String?): String {
return "<a href=\"${DocumentationManagerProtocol.PSI_ELEMENT_PROTOCOL}$LINK_TYPE_PARENT$ancestor\">$ancestor</a>"
}
@JvmStatic
fun toParameterPossibleClass(type: String, anchor: PsiElement, context: TypeEvalContext): String {
val pyType = PyTypeParser.getTypeByName(anchor, type, context)
@@ -52,11 +46,14 @@ object PyDocumentationLink {
}
@JvmStatic
fun toPossibleClass(type: String, anchor: PsiElement, context: TypeEvalContext): String {
val pyType = PyTypeParser.getTypeByName(anchor, type, context)
fun toPossibleClass(type: String, anchor: PsiElement, context: TypeEvalContext) = toPossibleClass(type, type, anchor, context)
@JvmStatic
fun toPossibleClass(content: String, qualifiedName: String, anchor: PsiElement, context: TypeEvalContext): String {
val pyType = PyTypeParser.getTypeByName(anchor, qualifiedName, context)
return when (pyType) {
is PyClassType -> "<a href=\"${DocumentationManagerProtocol.PSI_ELEMENT_PROTOCOL}$LINK_TYPE_TYPENAME$type\">$type</a>"
else -> type
is PyClassType -> "<a href=\"${DocumentationManagerProtocol.PSI_ELEMENT_PROTOCOL}$LINK_TYPE_TYPENAME$qualifiedName\">$content</a>"
else -> content
}
}
@@ -68,9 +65,6 @@ object PyDocumentationLink {
else if (link == LINK_TYPE_PARAM) {
parameterPossibleClass(element, context)
}
else if (link.startsWith(LINK_TYPE_PARENT)) {
ancestorOfContainingClass(element, link.substring(LINK_TYPE_PARENT.length), context)
}
else if (link.startsWith(LINK_TYPE_TYPENAME)) {
possibleClass(link.substring(LINK_TYPE_TYPENAME.length), element, context)
}
@@ -88,12 +82,6 @@ object PyDocumentationLink {
}
}
@JvmStatic
private fun ancestorOfContainingClass(element: PsiElement, ancestor: String, context: TypeEvalContext): PyClass? {
val ancestors = containingClass(element)?.getAncestorClasses(context)
return ancestors?.find { it.name == ancestor }
}
@JvmStatic
private fun parameterPossibleClass(parameter: PsiElement, context: TypeEvalContext): PyClass? {
if (parameter is PyNamedParameter) {
@@ -308,9 +308,9 @@ public class PythonDocumentationProvider extends AbstractDocumentationProvider i
for (ResolveResult result : referenceExpression.getReference(resolveContext).multiResolve(false)) {
final PsiElement element = result.getElement();
if (element instanceof PyClass) {
final String name = ((PyClass)element).getName();
if (name != null) {
return PyDocumentationLink.toAncestorOfContainingClass(name);
final String qualifiedName = ((PyClass)element).getQualifiedName();
if (qualifiedName != null) {
return PyDocumentationLink.toPossibleClass(escaper.apply(expression.getText()), qualifiedName, element, context);
}
}
}
@@ -323,7 +323,7 @@ public class PythonDocumentationProvider extends AbstractDocumentationProvider i
if (indexExpression != null) {
return describeSuperClass(operand, escaper, true, context) +
escaper.apply("[") +
escaper.apply(indexExpression.getText()) +
describeSuperClass(indexExpression, escaper, true, context) +
escaper.apply("]");
}
}
@@ -1 +1 @@
<html><body><code>class&nbsp;<b>Foo</b>(<a href="psi_element://#parent#object">object</a>)<br>Doc&nbsp;of&nbsp;Foo.</code></body></html>
<html><body><code>class&nbsp;<b>Foo</b>(<a href="psi_element://#typename#object">object</a>)<br>Doc&nbsp;of&nbsp;Foo.</code></body></html>
@@ -1 +1 @@
<html><body><code><small>class <a href="psi_element://#class#">Foo</a>(<a href="psi_element://#parent#object">object</a>)</small><br><br>def <b>__init__</b>(self)</code><br><br><i>Documentation is missing.</i> The following is copied from class <code><a href="psi_element://#class#">Foo</a></code>.<br><br><code>Doc&nbsp;of&nbsp;Foo.</code></body></html>
<html><body><code><small>class <a href="psi_element://#class#">Foo</a>(<a href="psi_element://#typename#object">object</a>)</small><br><br>def <b>__init__</b>(self)</code><br><br><i>Documentation is missing.</i> The following is copied from class <code><a href="psi_element://#class#">Foo</a></code>.<br><br><code>Doc&nbsp;of&nbsp;Foo.</code></body></html>
@@ -1 +1 @@
<html><body><code><small>class <a href="psi_element://#class#">Foo</a>(<a href="psi_element://#parent#Moo">Moo</a>)</small><br><br>def <b>__init__</b>(self)</code><br><br><i>Documentation is missing.</i> The following is copied from <code><a href="psi_element://#parent#Moo">Moo</a>.__init__</code>.<br><br><code>Doc&nbsp;of&nbsp;Moo()</code></body></html>
<html><body><code><small>class <a href="psi_element://#class#">Foo</a>(<a href="psi_element://#typename#ClassUndocumentedEmptyConstructor.Moo">Moo</a>)</small><br><br>def <b>__init__</b>(self)</code><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><code>Doc&nbsp;of&nbsp;Moo()</code></body></html>
@@ -1 +1 @@
<html><body><code>class&nbsp;<b>A</b>(metaclass=Meta1,&nbsp;six.with_metaclass(Meta2,&nbsp;Base1),&nbsp;<a href="psi_element://#parent#Base2">Base2</a>[int],&nbsp;<a href="psi_element://#parent#Base3">Base3</a>,&nbsp;Base4)</code></body></html>
<html><body><code>class&nbsp;<b>A</b>(metaclass=Meta1,&nbsp;six.with_metaclass(Meta2,&nbsp;Base1),&nbsp;<a href="psi_element://#typename#ClassWithAllKindSuperClassExpressions.Base2">Base2</a>[<a href="psi_element://#typename#int">int</a>],&nbsp;<a href="psi_element://#typename#ClassWithAllKindSuperClassExpressions.Base3">Base3</a>,&nbsp;Base4)</code></body></html>
+1 -1
View File
@@ -1 +1 @@
<html><body><code>class&nbsp;<b>Foo</b>(<a href="psi_element://#parent#object">object</a>)<br>Doc&nbsp;of&nbsp;Foo.</code></body></html>
<html><body><code>class&nbsp;<b>Foo</b>(<a href="psi_element://#typename#object">object</a>)<br>Doc&nbsp;of&nbsp;Foo.</code></body></html>
@@ -1 +1 @@
<html><body><code><small>class <a href="psi_element://#class#">B</a>(<a href="psi_element://#parent#A">A</a>)</small><br><br>def <b>foo</b>(self)<br>Inferred&nbsp;type:&nbsp;(self:&nbsp;<a href="psi_element://#typename#B">B</a>)&nbsp;-&gt;&nbsp;None<br></code><br><br><i>Documentation is missing.</i> The following is copied from <code><a href="psi_element://#parent#A">A</a>.foo</code>.<br><br><code>Doc&nbsp;from&nbsp;A.foo.</code></body></html>
<html><body><code><small>class <a href="psi_element://#class#">B</a>(<a href="psi_element://#typename#InheritedMethod.A">A</a>)</small><br><br>def <b>foo</b>(self)<br>Inferred&nbsp;type:&nbsp;(self:&nbsp;<a href="psi_element://#typename#B">B</a>)&nbsp;-&gt;&nbsp;None<br></code><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><code>Doc&nbsp;from&nbsp;A.foo.</code></body></html>
+1 -1
View File
@@ -1 +1 @@
<html><body>property <b><code>x</code></b> of class <a href="psi_element://#class#">A</a>(<a href="psi_element://#parent#object">object</a>)<br><i>Copied from getter:</i><br>Does things to X<code><br><br>@<i>x.deleter</i><br>def <b>x</b>(self,&nbsp;v)<br>Inferred&nbsp;type:&nbsp;(self:&nbsp;<a href="psi_element://#typename#A">A</a>,&nbsp;v:&nbsp;Any)&nbsp;-&gt;&nbsp;None<br><br>Deletes&nbsp;X</code><small><br><br>Deleter of property</small><br></body></html>
<html><body>property <b><code>x</code></b> of class <a href="psi_element://#class#">A</a>(<a href="psi_element://#typename#object">object</a>)<br><i>Copied from getter:</i><br>Does things to X<code><br><br>@<i>x.deleter</i><br>def <b>x</b>(self,&nbsp;v)<br>Inferred&nbsp;type:&nbsp;(self:&nbsp;<a href="psi_element://#typename#A">A</a>,&nbsp;v:&nbsp;Any)&nbsp;-&gt;&nbsp;None<br><br>Deletes&nbsp;X</code><small><br><br>Deleter of property</small><br></body></html>
+1 -1
View File
@@ -1 +1 @@
<html><body>property <b><code>x</code></b> of class <a href="psi_element://#class#">A</a>(<a href="psi_element://#parent#object">object</a>)<code><br><br>@<i>property</i><br>def <b>x</b>(self)<br>Inferred&nbsp;type:&nbsp;(self:&nbsp;<a href="psi_element://#typename#A">A</a>)&nbsp;-&gt;&nbsp;<a href="psi_element://#typename#int">int</a><br><br>Does&nbsp;things&nbsp;to&nbsp;X</code><small><br><br>Getter of property</small><br></body></html>
<html><body>property <b><code>x</code></b> of class <a href="psi_element://#class#">A</a>(<a href="psi_element://#typename#object">object</a>)<code><br><br>@<i>property</i><br>def <b>x</b>(self)<br>Inferred&nbsp;type:&nbsp;(self:&nbsp;<a href="psi_element://#typename#A">A</a>)&nbsp;-&gt;&nbsp;<a href="psi_element://#typename#int">int</a><br><br>Does&nbsp;things&nbsp;to&nbsp;X</code><small><br><br>Getter of property</small><br></body></html>
+1 -1
View File
@@ -1 +1 @@
<html><body>property <b><code>x</code></b> of class <a href="psi_element://#class#">A</a>(<a href="psi_element://#parent#object">object</a>)<br><i>Copied from getter:</i><br>Does things to X<code><br><br>@<i>x.setter</i><br>def <b>x</b>(self,&nbsp;v)<br>Inferred&nbsp;type:&nbsp;(self:&nbsp;<a href="psi_element://#typename#A">A</a>,&nbsp;v:&nbsp;Any)&nbsp;-&gt;&nbsp;None<br><br>Sets&nbsp;X</code><small><br><br>Setter of property</small><br></body></html>
<html><body>property <b><code>x</code></b> of class <a href="psi_element://#class#">A</a>(<a href="psi_element://#typename#object">object</a>)<br><i>Copied from getter:</i><br>Does things to X<code><br><br>@<i>x.setter</i><br>def <b>x</b>(self,&nbsp;v)<br>Inferred&nbsp;type:&nbsp;(self:&nbsp;<a href="psi_element://#typename#A">A</a>,&nbsp;v:&nbsp;Any)&nbsp;-&gt;&nbsp;None<br><br>Sets&nbsp;X</code><small><br><br>Setter of property</small><br></body></html>
+1 -1
View File
@@ -1 +1 @@
<html><body>property <b><code>x</code></b> of class <a href="psi_element://#class#">A</a>(<a href="psi_element://#parent#object">object</a>)<code><br><br>def <b>__getX</b>(self)<br>Inferred&nbsp;type:&nbsp;(self:&nbsp;<a href="psi_element://#typename#A">A</a>)&nbsp;-&gt;&nbsp;Any<br><br>Doc&nbsp;of&nbsp;getter</code><small><br><br>Deleter of property</small><br></body></html>
<html><body>property <b><code>x</code></b> of class <a href="psi_element://#class#">A</a>(<a href="psi_element://#typename#object">object</a>)<code><br><br>def <b>__getX</b>(self)<br>Inferred&nbsp;type:&nbsp;(self:&nbsp;<a href="psi_element://#typename#A">A</a>)&nbsp;-&gt;&nbsp;Any<br><br>Doc&nbsp;of&nbsp;getter</code><small><br><br>Deleter of property</small><br></body></html>
+1 -1
View File
@@ -1 +1 @@
<html><body>property <b><code>x</code></b> of class <a href="psi_element://#class#">A</a>(<a href="psi_element://#parent#object">object</a>)<code><br><br>def <b>__getX</b>(self)<br>Inferred&nbsp;type:&nbsp;(self:&nbsp;<a href="psi_element://#typename#A">A</a>)&nbsp;-&gt;&nbsp;Any<br><br>Doc&nbsp;of&nbsp;getter</code><small><br><br>Getter of property</small><br></body></html>
<html><body>property <b><code>x</code></b> of class <a href="psi_element://#class#">A</a>(<a href="psi_element://#typename#object">object</a>)<code><br><br>def <b>__getX</b>(self)<br>Inferred&nbsp;type:&nbsp;(self:&nbsp;<a href="psi_element://#typename#A">A</a>)&nbsp;-&gt;&nbsp;Any<br><br>Doc&nbsp;of&nbsp;getter</code><small><br><br>Getter of property</small><br></body></html>
+1 -1
View File
@@ -1 +1 @@
<html><body>property <b><code>x</code></b> of class <a href="psi_element://#class#">A</a>(<a href="psi_element://#parent#object">object</a>)<code><br><br>def <b>__getX</b>(self,&nbsp;x)<br>Inferred&nbsp;type:&nbsp;(self:&nbsp;<a href="psi_element://#typename#A">A</a>,&nbsp;x:&nbsp;Any)&nbsp;-&gt;&nbsp;None<br><br>Doc&nbsp;of&nbsp;getter</code><small><br><br>Setter of property</small><br></body></html>
<html><body>property <b><code>x</code></b> of class <a href="psi_element://#class#">A</a>(<a href="psi_element://#typename#object">object</a>)<code><br><br>def <b>__getX</b>(self,&nbsp;x)<br>Inferred&nbsp;type:&nbsp;(self:&nbsp;<a href="psi_element://#typename#A">A</a>,&nbsp;x:&nbsp;Any)&nbsp;-&gt;&nbsp;None<br><br>Doc&nbsp;of&nbsp;getter</code><small><br><br>Setter of property</small><br></body></html>
@@ -1 +1 @@
<html><body><small>Assigned to <code>c1</code><br></small><code><small>class <a href="psi_element://#class#">list</a>(<a href="psi_element://#parent#MutableSequence">MutableSequence</a>[_T], Generic[_T])</small><br><br>def <b>count</b>(self,&nbsp;object:&nbsp;_T)<br>Inferred&nbsp;type:&nbsp;(self:&nbsp;<a href="psi_element://#typename#list">list</a>,&nbsp;object:&nbsp;TypeVar('_T'))&nbsp;-&gt;&nbsp;<a href="psi_element://#typename#int">int</a><br><br>L.count(value)&nbsp;-&gt;&nbsp;integer&nbsp;--&nbsp;return&nbsp;number&nbsp;of&nbsp;occurrences&nbsp;of&nbsp;value&nbsp;</code></body></html>
<html><body><small>Assigned to <code>c1</code><br></small><code><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 <b>count</b>(self,&nbsp;object:&nbsp;_T)<br>Inferred&nbsp;type:&nbsp;(self:&nbsp;<a href="psi_element://#typename#list">list</a>,&nbsp;object:&nbsp;TypeVar('_T'))&nbsp;-&gt;&nbsp;<a href="psi_element://#typename#int">int</a><br><br>L.count(value)&nbsp;-&gt;&nbsp;integer&nbsp;--&nbsp;return&nbsp;number&nbsp;of&nbsp;occurrences&nbsp;of&nbsp;value&nbsp;</code></body></html>