diff options
author | Simon Ogorodnik <Simon.Ogorodnik@jetbrains.com> | 2016-11-10 18:55:14 +0300 |
---|---|---|
committer | Simon Ogorodnik <Simon.Ogorodnik@jetbrains.com> | 2016-11-14 14:06:29 +0300 |
commit | dc99d1fd5c066ac6083f09e23e52cf6c592768e4 (patch) | |
tree | 3c8fa7d3fe895f0c360d071beb1b56f8bb7c25f3 /core/src/main/kotlin/Kotlin | |
parent | af81d5a311125fc30dcf9c14fc9bd9c8680e532b (diff) | |
download | dokka-dc99d1fd5c066ac6083f09e23e52cf6c592768e4.tar.gz dokka-dc99d1fd5c066ac6083f09e23e52cf6c592768e4.tar.bz2 dokka-dc99d1fd5c066ac6083f09e23e52cf6c592768e4.zip |
Added //sampleStart //sampleEnd to samples on kotlin website
Diffstat (limited to 'core/src/main/kotlin/Kotlin')
-rw-r--r-- | core/src/main/kotlin/Kotlin/DescriptorDocumentationParser.kt | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/core/src/main/kotlin/Kotlin/DescriptorDocumentationParser.kt b/core/src/main/kotlin/Kotlin/DescriptorDocumentationParser.kt index 2fc268e8..532b186c 100644 --- a/core/src/main/kotlin/Kotlin/DescriptorDocumentationParser.kt +++ b/core/src/main/kotlin/Kotlin/DescriptorDocumentationParser.kt @@ -18,6 +18,7 @@ import org.jetbrains.kotlin.name.FqName 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.DescriptorToSourceUtils import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.annotations.argumentValue @@ -148,7 +149,7 @@ class DescriptorDocumentationParser private fun functionBody(descriptor: DeclarationDescriptor, functionName: String?): ContentNode { if (functionName == null) { logger.warn("Missing function name in @sample in ${descriptor.signature()}") - return ContentBlockSampleCode().let { it.append(ContentText("//Missing function name in @sample")); it } + return ContentBlockSampleCode().apply { append(ContentText("//Missing function name in @sample")) } } val scope = getKDocLinkResolutionScope(resolutionFacade, descriptor) val rootPackage = resolutionFacade.moduleDescriptor.getPackage(FqName.ROOT) @@ -156,12 +157,12 @@ class DescriptorDocumentationParser val symbol = resolveInScope(functionName, scope) ?: resolveInScope(functionName, rootScope) if (symbol == null) { logger.warn("Unresolved function $functionName in @sample in ${descriptor.signature()}") - return ContentBlockSampleCode().let { it.append(ContentText("//Unresolved: $functionName")); it } + return ContentBlockSampleCode().apply { append(ContentText("//Unresolved: $functionName")) } } val psiElement = DescriptorToSourceUtils.descriptorToDeclaration(symbol) if (psiElement == null) { logger.warn("Can't find source for function $functionName in @sample in ${descriptor.signature()}") - return ContentBlockSampleCode().let { it.append(ContentText("//Source not found: $functionName")); it } + return ContentBlockSampleCode().apply { append(ContentText("//Source not found: $functionName")) } } val text = when (psiElement) { @@ -178,7 +179,18 @@ class DescriptorDocumentationParser val lines = text.trimEnd().split("\n".toRegex()).toTypedArray().filterNot(String::isEmpty) val indent = lines.map { it.takeWhile(Char::isWhitespace).count() }.min() ?: 0 val finalText = lines.map { it.drop(indent) }.joinToString("\n") - return ContentBlockSampleCode().let { it.append(ContentText(finalText)); it } + + val psiFile = psiElement.containingFile + val importsBlock = if (psiFile is KtFile) { + ContentBlockCode("kotlin").apply { + append(ContentText(psiFile.importList?.text ?: "")) + } + } else { + ContentBlockCode("") + } + + + return ContentBlockSampleCode(importsBlock = importsBlock).apply { append(ContentText(finalText)) } } private fun resolveInScope(functionName: String, scope: ResolutionScope): DeclarationDescriptor? { |