From 43e38725e64b788564203b8d157df795f443f28e Mon Sep 17 00:00:00 2001 From: Kamil Doległo Date: Thu, 27 Aug 2020 14:54:57 +0200 Subject: Implement link preference in MarkdownParser --- plugins/base/src/main/kotlin/parsers/MarkdownParser.kt | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'plugins/base/src/main/kotlin/parsers') diff --git a/plugins/base/src/main/kotlin/parsers/MarkdownParser.kt b/plugins/base/src/main/kotlin/parsers/MarkdownParser.kt index b9ccd02b..0fa4e360 100644 --- a/plugins/base/src/main/kotlin/parsers/MarkdownParser.kt +++ b/plugins/base/src/main/kotlin/parsers/MarkdownParser.kt @@ -19,6 +19,7 @@ import org.jetbrains.dokka.model.doc.Suppress import org.jetbrains.dokka.utilities.DokkaLogger import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.DeclarationDescriptor +import org.jetbrains.kotlin.descriptors.FunctionDescriptor import org.jetbrains.kotlin.idea.kdoc.resolveKDocLink import org.jetbrains.kotlin.kdoc.parser.KDocKnownTag import org.jetbrains.kotlin.kdoc.psi.impl.KDocSection @@ -118,7 +119,7 @@ class MarkdownParser( .removeSuffix("]") .let { link -> try { - java.net.URL(link) + URL(link) null } catch (e: MalformedURLException) { try { @@ -129,7 +130,7 @@ class MarkdownParser( declarationDescriptor, null, link.split('.') - ).minByOrNull { it is ClassDescriptor }?.let { DRI.from(it) } + ).sorted().firstOrNull()?.let { DRI.from(it) } } else null } catch (e1: IllegalArgumentException) { logger.warn("Couldn't resolve link for $mdLink") @@ -138,6 +139,15 @@ class MarkdownParser( } } + private fun Collection.sorted() = sortedWith( + compareBy( + { it is ClassDescriptor }, + { (it as? FunctionDescriptor)?.name }, + { (it as? FunctionDescriptor)?.valueParameters?.size }, + { (it as? FunctionDescriptor)?.valueParameters?.joinToString { it.type.toString() } } + ) + ) + private fun referenceLinksHandler(node: ASTNode): DocTag { val linkLabel = node.children.find { it.type == MarkdownElementTypes.LINK_LABEL } ?: throw IllegalStateException("Wrong AST Tree. Reference link does not contain expected content") @@ -199,7 +209,7 @@ class MarkdownParser( private fun String.isRemoteLink() = try { URL(this) true - } catch(e: MalformedURLException){ + } catch (e: MalformedURLException) { false } -- cgit