diff options
Diffstat (limited to 'core/src/main/kotlin')
-rw-r--r-- | core/src/main/kotlin/Generation/DokkaGenerator.kt | 2 | ||||
-rw-r--r-- | core/src/main/kotlin/Kotlin/DeclarationLinkResolver.kt | 17 | ||||
-rw-r--r-- | core/src/main/kotlin/Model/PackageDocs.kt | 13 |
3 files changed, 19 insertions, 13 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("#") } |