aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin/Samples
diff options
context:
space:
mode:
authorDmitry Jemerov <yole@jetbrains.com>2017-02-24 14:23:29 +0100
committerDmitry Jemerov <yole@jetbrains.com>2017-02-24 14:23:29 +0100
commit004fc0c4eaf9d1ecaa78cf97f7d0fb2e91405031 (patch)
treec1d8e719e91cfd2bb6755d26e30a81aa0f6a84a5 /core/src/main/kotlin/Samples
parent5b90b573476f63366a5253280f5be5d68ac08a6d (diff)
parent64c8f35c00fcf483da76451b276e750533fbe9a4 (diff)
downloaddokka-004fc0c4eaf9d1ecaa78cf97f7d0fb2e91405031.tar.gz
dokka-004fc0c4eaf9d1ecaa78cf97f7d0fb2e91405031.tar.bz2
dokka-004fc0c4eaf9d1ecaa78cf97f7d0fb2e91405031.zip
Merge branch 'website-samples'
Diffstat (limited to 'core/src/main/kotlin/Samples')
-rw-r--r--core/src/main/kotlin/Samples/DefaultSampleProcessingService.kt7
-rw-r--r--core/src/main/kotlin/Samples/KotlinWebsiteSampleProcessingService.kt14
2 files changed, 9 insertions, 12 deletions
diff --git a/core/src/main/kotlin/Samples/DefaultSampleProcessingService.kt b/core/src/main/kotlin/Samples/DefaultSampleProcessingService.kt
index e6539135..1eb0c114 100644
--- a/core/src/main/kotlin/Samples/DefaultSampleProcessingService.kt
+++ b/core/src/main/kotlin/Samples/DefaultSampleProcessingService.kt
@@ -42,10 +42,9 @@ open class DefaultSampleProcessingService
return ContentBlockSampleCode().apply { append(ContentText("//Source not found: $functionName")) }
}
- val text = processSampleBody(psiElement)
-
- val lines = text.trimEnd().split("\n".toRegex()).toTypedArray().filterNot(String::isEmpty)
- val indent = lines.map { it.takeWhile(Char::isWhitespace).count() }.min() ?: 0
+ val text = processSampleBody(psiElement).trim { it == '\n' || it == '\r' }.trimEnd()
+ val lines = text.split("\n")
+ val indent = lines.filter(String::isNotBlank).map { it.takeWhile(Char::isWhitespace).count() }.min() ?: 0
val finalText = lines.map { it.drop(indent) }.joinToString("\n")
return ContentBlockSampleCode(importsBlock = processImports(psiElement)).apply { append(ContentText(finalText)) }
diff --git a/core/src/main/kotlin/Samples/KotlinWebsiteSampleProcessingService.kt b/core/src/main/kotlin/Samples/KotlinWebsiteSampleProcessingService.kt
index baf44904..864033f0 100644
--- a/core/src/main/kotlin/Samples/KotlinWebsiteSampleProcessingService.kt
+++ b/core/src/main/kotlin/Samples/KotlinWebsiteSampleProcessingService.kt
@@ -2,6 +2,7 @@ package org.jetbrains.dokka.Samples
import com.google.inject.Inject
import com.intellij.psi.PsiElement
+import com.intellij.psi.impl.source.tree.LeafPsiElement
import org.jetbrains.dokka.*
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.resolve.ImportPath
@@ -12,7 +13,7 @@ open class KotlinWebsiteSampleProcessingService
resolutionFacade: DokkaResolutionFacade)
: DefaultSampleProcessingService(options, logger, resolutionFacade) {
- private class SampleBuilder() : KtVisitorVoid() {
+ private class SampleBuilder : KtTreeVisitorVoid() {
val builder = StringBuilder()
val text: String
get() = builder.toString()
@@ -48,13 +49,10 @@ open class KotlinWebsiteSampleProcessingService
}
}
- override fun visitElement(element: PsiElement?) {
- if (element != null) {
- if (element.children.isEmpty())
- builder.append(element.text)
- else
- element.acceptChildren(this)
- }
+ override fun visitElement(element: PsiElement) {
+ if (element is LeafPsiElement)
+ builder.append(element.text)
+ super.visitElement(element)
}
}