Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KotlinParseException on string concatenation in fix plugin #1183

Merged
merged 1 commit into from
Jan 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import org.jetbrains.kotlin.psi.KtDotQualifiedExpression
import org.jetbrains.kotlin.psi.KtOperationExpression
import org.jetbrains.kotlin.psi.KtParenthesizedExpression
import org.jetbrains.kotlin.psi.KtReferenceExpression
import org.jetbrains.kotlin.psi.KtSafeQualifiedExpression
import org.jetbrains.kotlin.psi.KtStringTemplateExpression

/**
Expand Down Expand Up @@ -153,7 +154,8 @@ class StringConcatenationRule(configRules: List<RulesConfig>) : DiktatRule(
// =========== "a " + "b" -> "a b"
val rvalueTextNew = rvalueText?.trim('"')
return "$lvalueText$rvalueTextNew"
} else if (binaryExpressionPsi.isRvalueCallExpression() || binaryExpressionPsi.isRvalueDotQualifiedExpression() || binaryExpressionPsi.isRvalueOperation()) {
} else if (binaryExpressionPsi.isRvalueCallExpression() || binaryExpressionPsi.isRvalueDotQualifiedExpression() ||
binaryExpressionPsi.isRvalueOperation() || binaryExpressionPsi.isRvalueSafeQualifiedExpression()) {
// =========== "a " + foo() -> "a ${foo()}}"
return "$lvalueText\${$rvalueText}"
} else if (binaryExpressionPsi.isRvalueReferenceExpression()) {
Expand Down Expand Up @@ -216,4 +218,7 @@ class StringConcatenationRule(configRules: List<RulesConfig>) : DiktatRule(

private fun KtBinaryExpression.isLvalueConstantExpression() =
this.left is KtConstantExpression

private fun KtBinaryExpression.isRvalueSafeQualifiedExpression() =
this.right is KtSafeQualifiedExpression
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ val myTest20 = "${x}string"
val myTest21 = "${x} string"
val myTest22 = "string${foo()}"
val myTest23 = x.toString() + foo()
val myTest24 = foo() + "string"
val myTest24 = foo() + "string"
val myTest25 = "String ${valueStr?.value}"
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ val myTest21 = x.toString() + " string"
val myTest22 = "string" + foo()
val myTest23 = x.toString() + foo()
val myTest24 = foo() + "string"
val myTest25 = "String " + valueStr?.value