Reformat: ConvertToStringTemplateIntention
This commit is contained in:
committed by
Mikhail Glukhikh
parent
66906e2c80
commit
a3b35cbfe0
@@ -29,11 +29,14 @@ import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluat
|
||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
|
||||
class ConvertToStringTemplateInspection : IntentionBasedInspection<KtBinaryExpression>(
|
||||
ConvertToStringTemplateIntention::class,
|
||||
{ it -> ConvertToStringTemplateIntention.shouldSuggestToConvert(it) }
|
||||
ConvertToStringTemplateIntention::class,
|
||||
{ it -> ConvertToStringTemplateIntention.shouldSuggestToConvert(it) }
|
||||
)
|
||||
|
||||
open class ConvertToStringTemplateIntention : SelfTargetingOffsetIndependentIntention<KtBinaryExpression>(KtBinaryExpression::class.java, "Convert concatenation to template") {
|
||||
open class ConvertToStringTemplateIntention : SelfTargetingOffsetIndependentIntention<KtBinaryExpression>(
|
||||
KtBinaryExpression::class.java,
|
||||
"Convert concatenation to template"
|
||||
) {
|
||||
override fun isApplicableTo(element: KtBinaryExpression): Boolean {
|
||||
if (!isApplicableToNoParentCheck(element)) return false
|
||||
|
||||
@@ -68,8 +71,7 @@ open class ConvertToStringTemplateIntention : SelfTargetingOffsetIndependentInte
|
||||
return if (left is KtBinaryExpression && isApplicableToNoParentCheck(left)) {
|
||||
val leftRight = buildText(left.right, forceBraces)
|
||||
fold(left.left, leftRight + right, factory)
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
val leftText = buildText(left, forceBraces)
|
||||
factory.createExpression("\"$leftText$right\"") as KtStringTemplateExpression
|
||||
}
|
||||
@@ -105,16 +107,14 @@ open class ConvertToStringTemplateIntention : SelfTargetingOffsetIndependentInte
|
||||
val base = if (expressionText.startsWith("\"\"\"") && expressionText.endsWith("\"\"\"")) {
|
||||
val unquoted = expressionText.substring(3, expressionText.length - 3)
|
||||
StringUtil.escapeStringCharacters(unquoted)
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
StringUtil.unquoteString(expressionText)
|
||||
}
|
||||
|
||||
if (forceBraces) {
|
||||
if (base.endsWith('$')) {
|
||||
return base.dropLast(1) + "\\$"
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
val lastPart = expression.children.lastOrNull()
|
||||
if (lastPart is KtSimpleNameStringTemplateEntry) {
|
||||
return base.dropLast(lastPart.textLength) + "\${" + lastPart.text.drop(1) + "}"
|
||||
|
||||
Reference in New Issue
Block a user