mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Remove separate document link type for super class. Use link type for class instead.
This commit is contained in:
@@ -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 <b>Foo</b>(<a href="psi_element://#parent#object">object</a>)<br>Doc of Foo.</code></body></html>
|
||||
<html><body><code>class <b>Foo</b>(<a href="psi_element://#typename#object">object</a>)<br>Doc of 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 of 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 of 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 of 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 of Moo()</code></body></html>
|
||||
@@ -1 +1 @@
|
||||
<html><body><code>class <b>A</b>(metaclass=Meta1, six.with_metaclass(Meta2, Base1), <a href="psi_element://#parent#Base2">Base2</a>[int], <a href="psi_element://#parent#Base3">Base3</a>, Base4)</code></body></html>
|
||||
<html><body><code>class <b>A</b>(metaclass=Meta1, six.with_metaclass(Meta2, Base1), <a href="psi_element://#typename#ClassWithAllKindSuperClassExpressions.Base2">Base2</a>[<a href="psi_element://#typename#int">int</a>], <a href="psi_element://#typename#ClassWithAllKindSuperClassExpressions.Base3">Base3</a>, Base4)</code></body></html>
|
||||
@@ -1 +1 @@
|
||||
<html><body><code>class <b>Foo</b>(<a href="psi_element://#parent#object">object</a>)<br>Doc of Foo.</code></body></html>
|
||||
<html><body><code>class <b>Foo</b>(<a href="psi_element://#typename#object">object</a>)<br>Doc of 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 type: (self: <a href="psi_element://#typename#B">B</a>) -> 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 from 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 type: (self: <a href="psi_element://#typename#B">B</a>) -> 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 from A.foo.</code></body></html>
|
||||
@@ -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, v)<br>Inferred type: (self: <a href="psi_element://#typename#A">A</a>, v: Any) -> None<br><br>Deletes 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, v)<br>Inferred type: (self: <a href="psi_element://#typename#A">A</a>, v: Any) -> None<br><br>Deletes X</code><small><br><br>Deleter of property</small><br></body></html>
|
||||
@@ -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 type: (self: <a href="psi_element://#typename#A">A</a>) -> <a href="psi_element://#typename#int">int</a><br><br>Does things to 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 type: (self: <a href="psi_element://#typename#A">A</a>) -> <a href="psi_element://#typename#int">int</a><br><br>Does things to X</code><small><br><br>Getter of property</small><br></body></html>
|
||||
@@ -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, v)<br>Inferred type: (self: <a href="psi_element://#typename#A">A</a>, v: Any) -> None<br><br>Sets 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, v)<br>Inferred type: (self: <a href="psi_element://#typename#A">A</a>, v: Any) -> None<br><br>Sets X</code><small><br><br>Setter of property</small><br></body></html>
|
||||
@@ -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 type: (self: <a href="psi_element://#typename#A">A</a>) -> Any<br><br>Doc of 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 type: (self: <a href="psi_element://#typename#A">A</a>) -> Any<br><br>Doc of getter</code><small><br><br>Deleter of property</small><br></body></html>
|
||||
@@ -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 type: (self: <a href="psi_element://#typename#A">A</a>) -> Any<br><br>Doc of 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 type: (self: <a href="psi_element://#typename#A">A</a>) -> Any<br><br>Doc of getter</code><small><br><br>Getter of property</small><br></body></html>
|
||||
@@ -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, x)<br>Inferred type: (self: <a href="psi_element://#typename#A">A</a>, x: Any) -> None<br><br>Doc of 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, x)<br>Inferred type: (self: <a href="psi_element://#typename#A">A</a>, x: Any) -> None<br><br>Doc of 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, object: _T)<br>Inferred type: (self: <a href="psi_element://#typename#list">list</a>, object: TypeVar('_T')) -> <a href="psi_element://#typename#int">int</a><br><br>L.count(value) -> integer -- return number of occurrences of value </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, object: _T)<br>Inferred type: (self: <a href="psi_element://#typename#list">list</a>, object: TypeVar('_T')) -> <a href="psi_element://#typename#int">int</a><br><br>L.count(value) -> integer -- return number of occurrences of value </code></body></html>
|
||||
Reference in New Issue
Block a user