aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/main/kotlin/parsers
diff options
context:
space:
mode:
authorKamil Doległo <kamilok1965@interia.pl>2020-08-27 14:54:57 +0200
committerSebastian Sellmair <34319766+sellmair@users.noreply.github.com>2020-08-28 16:34:23 +0200
commit43e38725e64b788564203b8d157df795f443f28e (patch)
treec8ba173e05e8d18cadf260ff793b148741b2a5a6 /plugins/base/src/main/kotlin/parsers
parent6d00ac775b77ce373a9a8d39eadeec32b155920a (diff)
downloaddokka-43e38725e64b788564203b8d157df795f443f28e.tar.gz
dokka-43e38725e64b788564203b8d157df795f443f28e.tar.bz2
dokka-43e38725e64b788564203b8d157df795f443f28e.zip
Implement link preference in MarkdownParser
Diffstat (limited to 'plugins/base/src/main/kotlin/parsers')
-rw-r--r--plugins/base/src/main/kotlin/parsers/MarkdownParser.kt16
1 files changed, 13 insertions, 3 deletions
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<DeclarationDescriptor>.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
}