aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Ogorodnik <Simon.Ogorodnik@jetbrains.com>2017-11-21 15:05:04 +0300
committerSimon Ogorodnik <Simon.Ogorodnik@jetbrains.com>2017-11-21 15:05:04 +0300
commit80bde3cb243b324df162a16d23f9dfd3e0ab2597 (patch)
treedf51e7c315769155ca2a87fea6e18e0e5a687c91
parent924832f8ae7a38ad7c6b105c04794195bf9d4f9f (diff)
downloaddokka-80bde3cb243b324df162a16d23f9dfd3e0ab2597.tar.gz
dokka-80bde3cb243b324df162a16d23f9dfd3e0ab2597.tar.bz2
dokka-80bde3cb243b324df162a16d23f9dfd3e0ab2597.zip
Fix find node by signature when linking to extension with Type Param
-rw-r--r--core/src/main/kotlin/Kotlin/DocumentationBuilder.kt29
-rw-r--r--core/src/test/kotlin/format/MarkdownFormatTest.kt4
-rw-r--r--core/testdata/format/extensionScope.kt14
-rw-r--r--core/testdata/format/extensionScope.md8
4 files changed, 42 insertions, 13 deletions
diff --git a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt
index 04993ad4..177c6f50 100644
--- a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt
+++ b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt
@@ -906,18 +906,21 @@ fun CallableMemberDescriptor.getExtensionClassDescriptor(): ClassifierDescriptor
return null
}
-fun DeclarationDescriptor.signature(): String = when (this) {
- is ClassDescriptor,
- is PackageFragmentDescriptor,
- is PackageViewDescriptor,
- is TypeAliasDescriptor -> DescriptorUtils.getFqName(this).asString()
-
- is PropertyDescriptor -> containingDeclaration.signature() + "$" + name + receiverSignature()
- is FunctionDescriptor -> containingDeclaration.signature() + "$" + name + parameterSignature()
- is ValueParameterDescriptor -> containingDeclaration.signature() + "/" + name
- is TypeParameterDescriptor -> containingDeclaration.signature() + "*" + name
- is ReceiverParameterDescriptor -> containingDeclaration.signature() + "*" + name
- else -> throw UnsupportedOperationException("Don't know how to calculate signature for $this")
+fun DeclarationDescriptor.signature(): String {
+ if (this != original) return original.signature()
+ return when (this) {
+ is ClassDescriptor,
+ is PackageFragmentDescriptor,
+ is PackageViewDescriptor,
+ is TypeAliasDescriptor -> DescriptorUtils.getFqName(this).asString()
+
+ is PropertyDescriptor -> containingDeclaration.signature() + "$" + name + receiverSignature()
+ is FunctionDescriptor -> containingDeclaration.signature() + "$" + name + parameterSignature()
+ is ValueParameterDescriptor -> containingDeclaration.signature() + "/" + name
+ is TypeParameterDescriptor -> containingDeclaration.signature() + "*" + name
+ is ReceiverParameterDescriptor -> containingDeclaration.signature() + "*" + name
+ else -> throw UnsupportedOperationException("Don't know how to calculate signature for $this")
+ }
}
fun PropertyDescriptor.receiverSignature(): String {
@@ -934,7 +937,7 @@ fun CallableMemberDescriptor.parameterSignature(): String {
if (extensionReceiver != null) {
params.add(0, extensionReceiver.type)
}
- return "(" + params.map { it.signature() }.joinToString() + ")"
+ return params.joinToString(prefix = "(", postfix = ")") { it.signature() }
}
fun KotlinType.signature(): String {
diff --git a/core/src/test/kotlin/format/MarkdownFormatTest.kt b/core/src/test/kotlin/format/MarkdownFormatTest.kt
index 97a8ad4b..5fbd80fb 100644
--- a/core/src/test/kotlin/format/MarkdownFormatTest.kt
+++ b/core/src/test/kotlin/format/MarkdownFormatTest.kt
@@ -384,6 +384,10 @@ class MarkdownFormatTest {
verifyMarkdownNode("receiverReference")
}
+ @Test fun extensionScope() {
+ verifyMarkdownNodeByName("extensionScope", "test")
+ }
+
private fun buildMultiplePlatforms(path: String): DocumentationModule {
val module = DocumentationModule("test")
val options = DocumentationOptions("", "html", generateIndexPages = false, noStdlibLink = true)
diff --git a/core/testdata/format/extensionScope.kt b/core/testdata/format/extensionScope.kt
new file mode 100644
index 00000000..9f3130b8
--- /dev/null
+++ b/core/testdata/format/extensionScope.kt
@@ -0,0 +1,14 @@
+/**
+ * Test class with Type-parameter
+ */
+class Foo<T>
+
+/**
+ * Some extension on Foo
+ */
+fun <T> Foo<T>.ext() {}
+
+/**
+ * Correct link: [Foo.ext]
+ */
+fun test() {} \ No newline at end of file
diff --git a/core/testdata/format/extensionScope.md b/core/testdata/format/extensionScope.md
new file mode 100644
index 00000000..3515ed84
--- /dev/null
+++ b/core/testdata/format/extensionScope.md
@@ -0,0 +1,8 @@
+[test](test/index) / [test](test/test)
+
+# test
+
+`fun test(): Unit`
+
+Correct link: [Foo.ext](test/ext)
+