aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorSimon Ogorodnik <Simon.Ogorodnik@jetbrains.com>2017-05-11 21:37:33 +0300
committerSimon Ogorodnik <Simon.Ogorodnik@jetbrains.com>2017-05-11 21:37:33 +0300
commit46b615b49fd9af994fc85c84596aa73bebed476c (patch)
treec0ec544d471f4bc37b3b73c7cd9fcf269b4ba854 /core
parent0e8733ead6d5c4c6db7e4fe8a1f34b7598823290 (diff)
downloaddokka-46b615b49fd9af994fc85c84596aa73bebed476c.tar.gz
dokka-46b615b49fd9af994fc85c84596aa73bebed476c.tar.bz2
dokka-46b615b49fd9af994fc85c84596aa73bebed476c.zip
Resolve links in package docs in whole module
#KT-16485 fixed
Diffstat (limited to 'core')
-rw-r--r--core/src/main/kotlin/Generation/DokkaGenerator.kt2
-rw-r--r--core/src/main/kotlin/Kotlin/DeclarationLinkResolver.kt17
-rw-r--r--core/src/main/kotlin/Model/PackageDocs.kt13
-rw-r--r--core/src/test/kotlin/format/PackageDocsTest.kt4
4 files changed, 21 insertions, 15 deletions
diff --git a/core/src/main/kotlin/Generation/DokkaGenerator.kt b/core/src/main/kotlin/Generation/DokkaGenerator.kt
index c0b631e4..e1b5a880 100644
--- a/core/src/main/kotlin/Generation/DokkaGenerator.kt
+++ b/core/src/main/kotlin/Generation/DokkaGenerator.kt
@@ -145,7 +145,7 @@ fun buildDocumentationModule(injector: Injector,
val packageDocs = injector.getInstance(PackageDocs::class.java)
for (include in includes) {
- packageDocs.parse(include, fragments.firstOrNull())
+ packageDocs.parse(include, fragments)
}
if (documentationModule.content.isEmpty()) {
documentationModule.updateContent {
diff --git a/core/src/main/kotlin/Kotlin/DeclarationLinkResolver.kt b/core/src/main/kotlin/Kotlin/DeclarationLinkResolver.kt
index 2ff69b4c..2b085769 100644
--- a/core/src/main/kotlin/Kotlin/DeclarationLinkResolver.kt
+++ b/core/src/main/kotlin/Kotlin/DeclarationLinkResolver.kt
@@ -1,14 +1,9 @@
package org.jetbrains.dokka
import com.google.inject.Inject
-import com.intellij.psi.PsiMethod
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.idea.kdoc.resolveKDocLink
-import org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor
-import org.jetbrains.kotlin.load.java.descriptors.JavaMethodDescriptor
-import org.jetbrains.kotlin.name.Name
-import org.jetbrains.kotlin.resolve.DescriptorUtils
class DeclarationLinkResolver
@Inject constructor(val resolutionFacade: DokkaResolutionFacade,
@@ -17,7 +12,8 @@ class DeclarationLinkResolver
val options: DocumentationOptions,
val externalDocumentationLinkResolver: ExternalDocumentationLinkResolver) {
- fun resolveContentLink(fromDescriptor: DeclarationDescriptor, href: String): ContentBlock {
+
+ fun tryResolveContentLink(fromDescriptor: DeclarationDescriptor, href: String): ContentBlock? {
val symbol = try {
val symbols = resolveKDocLink(resolutionFacade.resolveSession.bindingContext,
resolutionFacade, fromDescriptor, null, href.split('.').toList())
@@ -38,10 +34,15 @@ class DeclarationLinkResolver
if ("/" in href) {
return ContentExternalLink(href)
}
- logger.warn("Unresolved link to $href in doc comment of ${fromDescriptor.signatureWithSourceLocation()}")
- return ContentExternalLink("#")
+ return null
}
+ fun resolveContentLink(fromDescriptor: DeclarationDescriptor, href: String) =
+ tryResolveContentLink(fromDescriptor, href) ?: run {
+ logger.warn("Unresolved link to $href in doc comment of ${fromDescriptor.signatureWithSourceLocation()}")
+ ContentExternalLink("#")
+ }
+
fun findTargetSymbol(symbols: Collection<DeclarationDescriptor>): DeclarationDescriptor? {
if (symbols.isEmpty()) {
return null
diff --git a/core/src/main/kotlin/Model/PackageDocs.kt b/core/src/main/kotlin/Model/PackageDocs.kt
index 5ebf2119..d057d4d0 100644
--- a/core/src/main/kotlin/Model/PackageDocs.kt
+++ b/core/src/main/kotlin/Model/PackageDocs.kt
@@ -17,7 +17,7 @@ class PackageDocs
val packageContent: Map<String, Content>
get() = _packageContent
- fun parse(fileName: String, linkResolveContext: LazyPackageDescriptor?) {
+ fun parse(fileName: String, linkResolveContext: List<LazyPackageDescriptor>) {
val file = File(fileName)
if (file.exists()) {
val text = file.readText()
@@ -51,9 +51,14 @@ class PackageDocs
private fun findOrCreatePackageContent(packageName: String) =
_packageContent.getOrPut(packageName) { -> MutableContent() }
- private fun resolveContentLink(href: String, linkResolveContext: LazyPackageDescriptor?): ContentBlock {
- if (linkResolveContext != null && linkResolver != null) {
- return linkResolver.resolveContentLink(linkResolveContext, href)
+ private fun resolveContentLink(href: String, linkResolveContext: List<LazyPackageDescriptor>): ContentBlock {
+ if (linkResolver != null) {
+ linkResolveContext
+ .asSequence()
+ .map { p -> linkResolver.tryResolveContentLink(p, href) }
+ .filterNotNull()
+ .firstOrNull()
+ ?.let { return it }
}
return ContentExternalLink("#")
}
diff --git a/core/src/test/kotlin/format/PackageDocsTest.kt b/core/src/test/kotlin/format/PackageDocsTest.kt
index 7562c087..2ff6e85f 100644
--- a/core/src/test/kotlin/format/PackageDocsTest.kt
+++ b/core/src/test/kotlin/format/PackageDocsTest.kt
@@ -4,13 +4,13 @@ import org.jetbrains.dokka.ContentBlock
import org.jetbrains.dokka.ContentText
import org.jetbrains.dokka.DokkaConsoleLogger
import org.jetbrains.dokka.PackageDocs
-import org.junit.Test
import org.junit.Assert.assertEquals
+import org.junit.Test
public class PackageDocsTest {
@Test fun verifyParse() {
val docs = PackageDocs(null, DokkaConsoleLogger)
- docs.parse("testdata/packagedocs/stdlib.md", null)
+ docs.parse("testdata/packagedocs/stdlib.md", emptyList())
val packageContent = docs.packageContent["kotlin"]!!
val block = (packageContent.children.single() as ContentBlock).children.first() as ContentText
assertEquals("Core functions and types", block.text)