diff options
-rw-r--r-- | src/Java/JavaDocumentationBuilder.kt | 19 | ||||
-rw-r--r-- | test/data/java/inheritorLinks.java | 9 | ||||
-rw-r--r-- | test/src/model/JavaTest.kt | 8 |
3 files changed, 34 insertions, 2 deletions
diff --git a/src/Java/JavaDocumentationBuilder.kt b/src/Java/JavaDocumentationBuilder.kt index a1724bb9..e1b91470 100644 --- a/src/Java/JavaDocumentationBuilder.kt +++ b/src/Java/JavaDocumentationBuilder.kt @@ -55,6 +55,16 @@ public class JavaDocumentationBuilder(private val options: DocumentationOptions, } } + fun link(element: PsiElement?, node: DocumentationNode, kind: DocumentationReference.Kind) { + val qualifiedName = getSignature(element) + if (qualifiedName != null) { + pendingReferences.add(PendingDocumentationReference( + {() -> signatureToNode[qualifiedName]}, + {() -> node}, + kind)) + } + } + private fun getSignature(element: PsiElement?) = when(element) { is PsiClass -> element.getQualifiedName() is PsiField -> element.getContainingClass().getQualifiedName() + "#" + element.getName() @@ -115,8 +125,13 @@ public class JavaDocumentationBuilder(private val options: DocumentationOptions, else -> DocumentationNode.Kind.Class } val node = DocumentationNode(this, kind) - getExtendsListTypes().filter { !ignoreSupertype(it) }.forEach { node.appendType(it, Kind.Supertype) } - getImplementsListTypes().forEach { node.appendType(it, Kind.Supertype) } + getSuperTypes().filter { !ignoreSupertype(it) }.forEach { + node.appendType(it, Kind.Supertype) + val superClass = it.resolve() + if (superClass != null) { + link(superClass, node, DocumentationReference.Kind.Inheritor) + } + } node.appendDetails(getTypeParameters()) { build() } node.appendMembers(getMethods()) { build() } node.appendMembers(getFields()) { build() } diff --git a/test/data/java/inheritorLinks.java b/test/data/java/inheritorLinks.java new file mode 100644 index 00000000..96caeb1d --- /dev/null +++ b/test/data/java/inheritorLinks.java @@ -0,0 +1,9 @@ +package test; + +class C { + public static class Foo { + } + + public static class Bar extends Foo { + } +} diff --git a/test/src/model/JavaTest.kt b/test/src/model/JavaTest.kt index 26e5536f..1c2df0d6 100644 --- a/test/src/model/JavaTest.kt +++ b/test/src/model/JavaTest.kt @@ -192,4 +192,12 @@ public class JavaTest { assertEquals(1, cls.members(DocumentationNode.Kind.EnumItem).size()) } } + + Test fun inheritorLinks() { + verifyPackageMember("test/data/java/inheritorLinks.java") { cls -> + val fooClass = cls.members.single { it.name == "Foo" } + val inheritors = fooClass.references(DocumentationReference.Kind.Inheritor) + assertEquals(1, inheritors.size()) + } + } } |