From 9062f4229bae8444ba4ad9da979bcbcb2e746187 Mon Sep 17 00:00:00 2001 From: scache Date: Thu, 19 Oct 2017 02:45:16 +0900 Subject: [PATCH] QuickDoc: Show sample code containing type parameters correctly #KT-20777 Fixed --- .../org/jetbrains/kotlin/idea/kdoc/KDocRenderer.kt | 2 +- .../typeParameters/code/usageNestedTypeParameters.kt | 11 +++++++++++ .../typeParameters/code/usageSingleTypeParameter.kt | 11 +++++++++++ .../multiModuleSamples/typeParameters/samples/EMPTY | 0 .../typeParameters/samplesTest/nested.kt | 6 ++++++ .../typeParameters/samplesTest/single.kt | 6 ++++++ .../org/jetbrains/kotlin/idea/kdoc/KDocSampleTest.kt | 11 +++++++++++ 7 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 idea/testData/kdoc/multiModuleSamples/typeParameters/code/usageNestedTypeParameters.kt create mode 100644 idea/testData/kdoc/multiModuleSamples/typeParameters/code/usageSingleTypeParameter.kt create mode 100644 idea/testData/kdoc/multiModuleSamples/typeParameters/samples/EMPTY create mode 100644 idea/testData/kdoc/multiModuleSamples/typeParameters/samplesTest/nested.kt create mode 100644 idea/testData/kdoc/multiModuleSamples/typeParameters/samplesTest/single.kt diff --git a/idea/src/org/jetbrains/kotlin/idea/kdoc/KDocRenderer.kt b/idea/src/org/jetbrains/kotlin/idea/kdoc/KDocRenderer.kt index 9aa622e429a..632a0594418 100644 --- a/idea/src/org/jetbrains/kotlin/idea/kdoc/KDocRenderer.kt +++ b/idea/src/org/jetbrains/kotlin/idea/kdoc/KDocRenderer.kt @@ -124,7 +124,7 @@ object KDocRenderer { if (target == null) to.append("// Unresolved") else { - to.append(trimCommonIndent(target.extractExampleText())) + to.append(trimCommonIndent(target.extractExampleText()).htmlEscape()) } } } diff --git a/idea/testData/kdoc/multiModuleSamples/typeParameters/code/usageNestedTypeParameters.kt b/idea/testData/kdoc/multiModuleSamples/typeParameters/code/usageNestedTypeParameters.kt new file mode 100644 index 00000000000..552a839cf5a --- /dev/null +++ b/idea/testData/kdoc/multiModuleSamples/typeParameters/code/usageNestedTypeParameters.kt @@ -0,0 +1,11 @@ +/** + * @sample samples.nestedTypeParameter + */ +fun some() { + +} + +//INFO:
usageNestedTypeParameters.kt
public fun some(): Unit

Samples:

samples.nestedTypeParameter


+//INFO: val m = mapOf<String, Pair<Int, Long>>()
+//INFO: println(m)
+//INFO: 
diff --git a/idea/testData/kdoc/multiModuleSamples/typeParameters/code/usageSingleTypeParameter.kt b/idea/testData/kdoc/multiModuleSamples/typeParameters/code/usageSingleTypeParameter.kt new file mode 100644 index 00000000000..9c456f38937 --- /dev/null +++ b/idea/testData/kdoc/multiModuleSamples/typeParameters/code/usageSingleTypeParameter.kt @@ -0,0 +1,11 @@ +/** + * @sample samples.singleTypeParameter + */ +fun some() { + +} + +//INFO:
usageSingleTypeParameter.kt
public fun some(): Unit

Samples:

samples.singleTypeParameter


+//INFO: val l = listOf<String>()
+//INFO: println(l)
+//INFO: 
diff --git a/idea/testData/kdoc/multiModuleSamples/typeParameters/samples/EMPTY b/idea/testData/kdoc/multiModuleSamples/typeParameters/samples/EMPTY new file mode 100644 index 00000000000..e69de29bb2d diff --git a/idea/testData/kdoc/multiModuleSamples/typeParameters/samplesTest/nested.kt b/idea/testData/kdoc/multiModuleSamples/typeParameters/samplesTest/nested.kt new file mode 100644 index 00000000000..643fcdfe32f --- /dev/null +++ b/idea/testData/kdoc/multiModuleSamples/typeParameters/samplesTest/nested.kt @@ -0,0 +1,6 @@ +package samples + +fun nestedTypeParameter() { + val m = mapOf>() + println(m) +} diff --git a/idea/testData/kdoc/multiModuleSamples/typeParameters/samplesTest/single.kt b/idea/testData/kdoc/multiModuleSamples/typeParameters/samplesTest/single.kt new file mode 100644 index 00000000000..ebfcaee390e --- /dev/null +++ b/idea/testData/kdoc/multiModuleSamples/typeParameters/samplesTest/single.kt @@ -0,0 +1,6 @@ +package samples + +fun singleTypeParameter() { + val l = listOf() + println(l) +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/kdoc/KDocSampleTest.kt b/idea/tests/org/jetbrains/kotlin/idea/kdoc/KDocSampleTest.kt index 7f09b8e98df..65db4c65eb4 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/kdoc/KDocSampleTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/kdoc/KDocSampleTest.kt @@ -58,6 +58,17 @@ class KDocSampleTest : AbstractMultiModuleTest() { doResolveTest("fqName/code/usage.kt", "samplez.a.b.c.Samplez") } + fun testTypeParameters() { + + val code = module("code") + val samples = module("samples", hasTestRoot = true) + + samples.addDependency(code) + + doInfoTest("typeParameters/code/usageSingleTypeParameter.kt") + doInfoTest("typeParameters/code/usageNestedTypeParameters.kt") + } + fun doResolveTest(path: String, link: String) { configureByFile(path)