diff options
author | Simon Ogorodnik <Simon.Ogorodnik@jetbrains.com> | 2017-03-20 15:37:46 +0300 |
---|---|---|
committer | Simon Ogorodnik <Simon.Ogorodnik@jetbrains.com> | 2017-03-20 15:37:46 +0300 |
commit | 8eff2cf33d1ba671191d6e2873f005e6b5f7057e (patch) | |
tree | 8cfd83e1eb6aa08500e600233a5ca509bd1f4bd7 /core | |
parent | 39bfaa5f89dc07bce5456578f4e17905f2e4c095 (diff) | |
parent | 372e9c796cc77aaff788df56a13deeef64b6edd7 (diff) | |
download | dokka-8eff2cf33d1ba671191d6e2873f005e6b5f7057e.tar.gz dokka-8eff2cf33d1ba671191d6e2873f005e6b5f7057e.tar.bz2 dokka-8eff2cf33d1ba671191d6e2873f005e6b5f7057e.zip |
Merge branch '0.9.14/KT-15497'
# Conflicts:
# core/src/test/kotlin/format/MarkdownFormatTest.kt
Diffstat (limited to 'core')
-rw-r--r-- | core/src/main/kotlin/Kotlin/DescriptorDocumentationParser.kt | 2 | ||||
-rw-r--r-- | core/src/main/kotlin/Samples/DefaultSampleProcessingService.kt | 12 | ||||
-rw-r--r-- | core/src/main/kotlin/Samples/SampleProcessingService.kt | 3 | ||||
-rw-r--r-- | core/src/test/kotlin/format/MarkdownFormatTest.kt | 9 | ||||
-rw-r--r-- | core/testdata/format/sampleByFQName.kt | 12 | ||||
-rw-r--r-- | core/testdata/format/sampleByFQName.md | 14 | ||||
-rw-r--r-- | core/testdata/format/sampleByShortName.kt | 12 | ||||
-rw-r--r-- | core/testdata/format/sampleByShortName.md | 14 |
8 files changed, 70 insertions, 8 deletions
diff --git a/core/src/main/kotlin/Kotlin/DescriptorDocumentationParser.kt b/core/src/main/kotlin/Kotlin/DescriptorDocumentationParser.kt index 06acf2e6..6d7ff7ba 100644 --- a/core/src/main/kotlin/Kotlin/DescriptorDocumentationParser.kt +++ b/core/src/main/kotlin/Kotlin/DescriptorDocumentationParser.kt @@ -59,7 +59,7 @@ class DescriptorDocumentationParser tags.forEach { when (it.knownTag) { KDocKnownTag.SAMPLE -> - content.append(sampleService.resolveSample(descriptor, it.getSubjectName())) + content.append(sampleService.resolveSample(descriptor, it.getSubjectName(), it)) KDocKnownTag.SEE -> content.addTagToSeeAlso(descriptor, it) else -> { diff --git a/core/src/main/kotlin/Samples/DefaultSampleProcessingService.kt b/core/src/main/kotlin/Samples/DefaultSampleProcessingService.kt index 1eb0c114..116a5c02 100644 --- a/core/src/main/kotlin/Samples/DefaultSampleProcessingService.kt +++ b/core/src/main/kotlin/Samples/DefaultSampleProcessingService.kt @@ -7,11 +7,13 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.descriptors.PackageViewDescriptor import org.jetbrains.kotlin.idea.kdoc.getKDocLinkResolutionScope -import org.jetbrains.kotlin.name.FqName +import org.jetbrains.kotlin.idea.kdoc.resolveKDocLink +import org.jetbrains.kotlin.kdoc.psi.impl.KDocTag import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.psi.KtBlockExpression import org.jetbrains.kotlin.psi.KtDeclarationWithBody import org.jetbrains.kotlin.psi.KtFile +import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter import org.jetbrains.kotlin.resolve.scopes.ResolutionScope @@ -23,15 +25,13 @@ open class DefaultSampleProcessingService val resolutionFacade: DokkaResolutionFacade) : SampleProcessingService { - override fun resolveSample(descriptor: DeclarationDescriptor, functionName: String?): ContentNode { + override fun resolveSample(descriptor: DeclarationDescriptor, functionName: String?, kdocTag: KDocTag): ContentNode { if (functionName == null) { logger.warn("Missing function name in @sample in ${descriptor.signature()}") return ContentBlockSampleCode().apply { append(ContentText("//Missing function name in @sample")) } } - val scope = getKDocLinkResolutionScope(resolutionFacade, descriptor) - val rootPackage = resolutionFacade.moduleDescriptor.getPackage(FqName.ROOT) - val rootScope = rootPackage.memberScope - val symbol = resolveInScope(functionName, scope) ?: resolveInScope(functionName, rootScope) + val bindingContext = BindingContext.EMPTY + val symbol = resolveKDocLink(bindingContext, resolutionFacade, descriptor, kdocTag, functionName.split(".")).firstOrNull() if (symbol == null) { logger.warn("Unresolved function $functionName in @sample in ${descriptor.signature()}") return ContentBlockSampleCode().apply { append(ContentText("//Unresolved: $functionName")) } diff --git a/core/src/main/kotlin/Samples/SampleProcessingService.kt b/core/src/main/kotlin/Samples/SampleProcessingService.kt index 7f46299f..86c917cf 100644 --- a/core/src/main/kotlin/Samples/SampleProcessingService.kt +++ b/core/src/main/kotlin/Samples/SampleProcessingService.kt @@ -2,7 +2,8 @@ package org.jetbrains.dokka.Samples import org.jetbrains.dokka.ContentNode import org.jetbrains.kotlin.descriptors.DeclarationDescriptor +import org.jetbrains.kotlin.kdoc.psi.impl.KDocTag interface SampleProcessingService { - fun resolveSample(descriptor: DeclarationDescriptor, functionName: String?): ContentNode + fun resolveSample(descriptor: DeclarationDescriptor, functionName: String?, kdocTag: KDocTag): ContentNode }
\ No newline at end of file diff --git a/core/src/test/kotlin/format/MarkdownFormatTest.kt b/core/src/test/kotlin/format/MarkdownFormatTest.kt index c643eec2..21298520 100644 --- a/core/src/test/kotlin/format/MarkdownFormatTest.kt +++ b/core/src/test/kotlin/format/MarkdownFormatTest.kt @@ -233,6 +233,15 @@ class MarkdownFormatTest { verifyMarkdownPackage("typeAliases") } + @Test fun sampleByFQName() { + verifyMarkdownNode("sampleByFQName") + } + + @Test fun sampleByShortName() { + verifyMarkdownNode("sampleByShortName") + } + + @Test fun suspendParam() { verifyMarkdownNode("suspendParam") verifyMarkdownPackage("suspendParam") diff --git a/core/testdata/format/sampleByFQName.kt b/core/testdata/format/sampleByFQName.kt new file mode 100644 index 00000000..2c0af092 --- /dev/null +++ b/core/testdata/format/sampleByFQName.kt @@ -0,0 +1,12 @@ +package test + +fun sample() { + println("sample") +} + +/** + * @sample test.sample + */ +fun use() { + +}
\ No newline at end of file diff --git a/core/testdata/format/sampleByFQName.md b/core/testdata/format/sampleByFQName.md new file mode 100644 index 00000000..06333e13 --- /dev/null +++ b/core/testdata/format/sampleByFQName.md @@ -0,0 +1,14 @@ +[test](test/index) / [test](test/test/index) / [sample](test/test/sample) + +# sample + +`fun sample(): Unit`[test](test/index) / [test](test/test/index) / [use](test/test/use) + +# use + +`fun use(): Unit` + +``` kotlin +println("sample") +``` + diff --git a/core/testdata/format/sampleByShortName.kt b/core/testdata/format/sampleByShortName.kt new file mode 100644 index 00000000..2e03310f --- /dev/null +++ b/core/testdata/format/sampleByShortName.kt @@ -0,0 +1,12 @@ +package test + +fun sample() { + println("sample") +} + +/** + * @sample sample + */ +fun use() { + +}
\ No newline at end of file diff --git a/core/testdata/format/sampleByShortName.md b/core/testdata/format/sampleByShortName.md new file mode 100644 index 00000000..06333e13 --- /dev/null +++ b/core/testdata/format/sampleByShortName.md @@ -0,0 +1,14 @@ +[test](test/index) / [test](test/test/index) / [sample](test/test/sample) + +# sample + +`fun sample(): Unit`[test](test/index) / [test](test/test/index) / [use](test/test/use) + +# use + +`fun use(): Unit` + +``` kotlin +println("sample") +``` + |