aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin/Samples
diff options
context:
space:
mode:
authorSimon Ogorodnik <Simon.Ogorodnik@jetbrains.com>2018-01-10 22:25:11 +0300
committerZubakov Aleksey <aleks.zubakov@gmail.com>2018-08-17 13:00:32 +0300
commita838a096da246babd93dc518dec8d2470d1c14f5 (patch)
treed72f096437653ca2a2f73dc6a91e435f6d6b01b7 /core/src/main/kotlin/Samples
parentfc517baac7ba381f0f4f2529e59700b1191dd0ce (diff)
downloaddokka-a838a096da246babd93dc518dec8d2470d1c14f5.tar.gz
dokka-a838a096da246babd93dc518dec8d2470d1c14f5.tar.bz2
dokka-a838a096da246babd93dc518dec8d2470d1c14f5.zip
Convert assertFails in kws samples without message properly
Diffstat (limited to 'core/src/main/kotlin/Samples')
-rw-r--r--core/src/main/kotlin/Samples/KotlinWebsiteSampleProcessingService.kt40
1 files changed, 29 insertions, 11 deletions
diff --git a/core/src/main/kotlin/Samples/KotlinWebsiteSampleProcessingService.kt b/core/src/main/kotlin/Samples/KotlinWebsiteSampleProcessingService.kt
index b12e3a66..4525e9d9 100644
--- a/core/src/main/kotlin/Samples/KotlinWebsiteSampleProcessingService.kt
+++ b/core/src/main/kotlin/Samples/KotlinWebsiteSampleProcessingService.kt
@@ -1,7 +1,10 @@
package org.jetbrains.dokka.Samples
import com.google.inject.Inject
-import com.intellij.psi.*
+import com.intellij.psi.PsiDocumentManager
+import com.intellij.psi.PsiElement
+import com.intellij.psi.PsiElementVisitor
+import com.intellij.psi.PsiWhiteSpace
import com.intellij.psi.impl.source.tree.LeafPsiElement
import com.intellij.psi.util.PsiTreeUtil
import org.jetbrains.dokka.*
@@ -61,27 +64,42 @@ open class KotlinWebsiteSampleProcessingService
}
fun convertAssertFails(expression: KtCallExpression) {
- val (message, funcArgument) = expression.valueArguments
+ val valueArguments = expression.valueArguments
+
+ val funcArgument: KtValueArgument
+ val message: KtValueArgument?
+
+ if (valueArguments.size == 1) {
+ message = null
+ funcArgument = valueArguments.first()
+ } else {
+ message = valueArguments.first()
+ funcArgument = valueArguments.last()
+ }
+
builder.apply {
- val argument = if (funcArgument.getArgumentExpression() is KtLambdaExpression)
- PsiTreeUtil.findChildOfType(funcArgument, KtBlockExpression::class.java)?.text ?: ""
- else
- funcArgument.text
+ val argument = funcArgument.extractFunctionalArgumentText()
append(argument.lines().joinToString(separator = "\n") { "// $it" })
append(" // ")
- append(message.extractStringArgumentValue())
+ if (message != null) {
+ append(message.extractStringArgumentValue())
+ }
append(" will fail")
}
}
+ private fun KtValueArgument.extractFunctionalArgumentText(): String {
+ return if (getArgumentExpression() is KtLambdaExpression)
+ PsiTreeUtil.findChildOfType(this, KtBlockExpression::class.java)?.text ?: ""
+ else
+ text
+ }
+
fun convertAssertFailsWith(expression: KtCallExpression) {
val (funcArgument) = expression.valueArguments
val (exceptionType) = expression.typeArguments
builder.apply {
- val argument = if (funcArgument.firstChild is KtLambdaExpression)
- PsiTreeUtil.findChildOfType(funcArgument, KtBlockExpression::class.java)?.text ?: ""
- else
- funcArgument.text
+ val argument = funcArgument.extractFunctionalArgumentText()
append(argument.lines().joinToString(separator = "\n") { "// $it" })
append(" // will fail with ")
append(exceptionType.text)