diff options
-rw-r--r-- | core/src/main/kotlin/Kotlin/DescriptorDocumentationParser.kt | 18 | ||||
-rw-r--r-- | core/src/test/kotlin/format/MarkdownFormatTest.kt | 16 | ||||
-rw-r--r-- | core/testdata/format/inheritedLink.1.kt | 10 | ||||
-rw-r--r-- | core/testdata/format/inheritedLink.kt | 11 | ||||
-rw-r--r-- | core/testdata/format/inheritedLink.md | 17 |
5 files changed, 68 insertions, 4 deletions
diff --git a/core/src/main/kotlin/Kotlin/DescriptorDocumentationParser.kt b/core/src/main/kotlin/Kotlin/DescriptorDocumentationParser.kt index f2d9d3a7..6e44df74 100644 --- a/core/src/main/kotlin/Kotlin/DescriptorDocumentationParser.kt +++ b/core/src/main/kotlin/Kotlin/DescriptorDocumentationParser.kt @@ -8,14 +8,17 @@ import org.intellij.markdown.parser.LinkMap import org.jetbrains.dokka.* import org.jetbrains.dokka.Samples.SampleProcessingService import org.jetbrains.kotlin.descriptors.* +import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny import org.jetbrains.kotlin.idea.kdoc.findKDoc import org.jetbrains.kotlin.incremental.components.NoLookupLocation import org.jetbrains.kotlin.kdoc.parser.KDocKnownTag +import org.jetbrains.kotlin.kdoc.psi.api.KDoc import org.jetbrains.kotlin.kdoc.psi.impl.KDocSection import org.jetbrains.kotlin.kdoc.psi.impl.KDocTag import org.jetbrains.kotlin.load.java.descriptors.JavaCallableMemberDescriptor import org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor import org.jetbrains.kotlin.name.FqName +import org.jetbrains.kotlin.psi.KtDeclaration import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.annotations.argumentValue import org.jetbrains.kotlin.resolve.constants.StringValue @@ -49,6 +52,13 @@ class DescriptorDocumentationParser } return Content.Empty to { node -> } } + + val contextDescriptor = + (PsiTreeUtil.getParentOfType(kdoc, KDoc::class.java)?.context as? KtDeclaration) + ?.takeIf { it != descriptor.original.sourcePsi() } + ?.resolveToDescriptorIfAny() + ?: descriptor + var kdocText = kdoc.getContent() // workaround for code fence parsing problem in IJ markdown parser if (kdocText.endsWith("```") || kdocText.endsWith("~~~")) { @@ -56,20 +66,20 @@ class DescriptorDocumentationParser } val tree = parseMarkdown(kdocText) val linkMap = LinkMap.buildLinkMap(tree.node, kdocText) - val content = buildContent(tree, LinkResolver(linkMap, { href -> linkResolver.resolveContentLink(descriptor, href) }), inline) + val content = buildContent(tree, LinkResolver(linkMap, { href -> linkResolver.resolveContentLink(contextDescriptor, href) }), inline) if (kdoc is KDocSection) { val tags = kdoc.getTags() tags.forEach { when (it.knownTag) { KDocKnownTag.SAMPLE -> - content.append(sampleService.resolveSample(descriptor, it.getSubjectName(), it)) + content.append(sampleService.resolveSample(contextDescriptor, it.getSubjectName(), it)) KDocKnownTag.SEE -> - content.addTagToSeeAlso(descriptor, it) + content.addTagToSeeAlso(contextDescriptor, it) else -> { val section = content.addSection(javadocSectionDisplayName(it.name), it.getSubjectName()) val sectionContent = it.getContent() val markdownNode = parseMarkdown(sectionContent) - buildInlineContentTo(markdownNode, section, LinkResolver(linkMap, { href -> linkResolver.resolveContentLink(descriptor, href) })) + buildInlineContentTo(markdownNode, section, LinkResolver(linkMap, { href -> linkResolver.resolveContentLink(contextDescriptor, href) })) } } } diff --git a/core/src/test/kotlin/format/MarkdownFormatTest.kt b/core/src/test/kotlin/format/MarkdownFormatTest.kt index f06f0e64..9e4c831d 100644 --- a/core/src/test/kotlin/format/MarkdownFormatTest.kt +++ b/core/src/test/kotlin/format/MarkdownFormatTest.kt @@ -423,6 +423,22 @@ class MarkdownFormatTest: FileGeneratorTestCase() { verifyMarkdownNode("enumRef") } + @Test fun inheritedLink() { + val filePath = "testdata/format/inheritedLink" + verifyOutput( + arrayOf( + contentRootFromPath("$filePath.kt"), + contentRootFromPath("$filePath.1.kt") + ), + ".md", + withJdk = true, + withKotlinRuntime = true, + includeNonPublic = false + ) { model, output -> + buildPagesAndReadInto(model.members.single { it.name == "p2" }.members.single().members, output) + } + } + private fun buildMultiplePlatforms(path: String): DocumentationModule { val module = DocumentationModule("test") diff --git a/core/testdata/format/inheritedLink.1.kt b/core/testdata/format/inheritedLink.1.kt new file mode 100644 index 00000000..29cc12b4 --- /dev/null +++ b/core/testdata/format/inheritedLink.1.kt @@ -0,0 +1,10 @@ +package p1 + +import java.util.LinkedList + +interface Foo { + + /** Says hello - [LinkedList]. */ + fun sayHello() : String + +}
\ No newline at end of file diff --git a/core/testdata/format/inheritedLink.kt b/core/testdata/format/inheritedLink.kt new file mode 100644 index 00000000..86b8f4e2 --- /dev/null +++ b/core/testdata/format/inheritedLink.kt @@ -0,0 +1,11 @@ +package p2 + +import p1.Foo + +class FooBar : Foo { + + override fun sayHello(): String { + return "Hello!" + } + +}
\ No newline at end of file diff --git a/core/testdata/format/inheritedLink.md b/core/testdata/format/inheritedLink.md new file mode 100644 index 00000000..e5af326c --- /dev/null +++ b/core/testdata/format/inheritedLink.md @@ -0,0 +1,17 @@ +<!-- File: test/p2/-foo-bar/-init-.md --> +[test](../../index.md) / [p2](../index.md) / [FooBar](index.md) / [<init>](./-init-.md) + +# <init> + +`FooBar()` +<!-- File: test/p2/-foo-bar/say-hello.md --> +[test](../../index.md) / [p2](../index.md) / [FooBar](index.md) / [sayHello](./say-hello.md) + +# sayHello + +`fun sayHello(): String` + +Overrides [Foo.sayHello](../../p1/-foo/say-hello.md) + +Says hello - [LinkedList](http://docs.oracle.com/javase/6/docs/api/java/util/LinkedList.html). + |