mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 22:51:17 +07:00
[uast-inspections] KTIJ-29797 support escape symbols when string literal is created
GitOrigin-RevId: a1dc2cf91d81991fac6442e57b2e5b65addeb987
This commit is contained in:
committed by
intellij-monorepo-bot
parent
e9fac5fa6d
commit
22fac7715b
@@ -4,6 +4,17 @@ import java.lang.RuntimeException
|
|||||||
|
|
||||||
class StringTemplateAsArgumentFix {
|
class StringTemplateAsArgumentFix {
|
||||||
private val loggerSlf4J = LoggerFactory.getLogger()
|
private val loggerSlf4J = LoggerFactory.getLogger()
|
||||||
|
|
||||||
|
val x = 1
|
||||||
|
val y = 2
|
||||||
|
|
||||||
|
fun testWithEscape() {
|
||||||
|
loggerSlf4J.debug("{}\n{}", x, y)
|
||||||
|
loggerSlf4J.debug("{}\t{}", x, y)
|
||||||
|
loggerSlf4J.debug("{}\"{}", x, y)
|
||||||
|
loggerSlf4J.debug("{}\${}", x, y)
|
||||||
|
}
|
||||||
|
|
||||||
fun testLoggerSlf4J() {
|
fun testLoggerSlf4J() {
|
||||||
val variable1 = "test"
|
val variable1 = "test"
|
||||||
val variable2 = 1
|
val variable2 = 1
|
||||||
|
|||||||
@@ -4,6 +4,17 @@ import java.lang.RuntimeException
|
|||||||
|
|
||||||
class StringTemplateAsArgumentFix {
|
class StringTemplateAsArgumentFix {
|
||||||
private val loggerSlf4J = LoggerFactory.getLogger()
|
private val loggerSlf4J = LoggerFactory.getLogger()
|
||||||
|
|
||||||
|
val x = 1
|
||||||
|
val y = 2
|
||||||
|
|
||||||
|
fun testWithEscape() {
|
||||||
|
loggerSlf4J.debug("$x\n$y")
|
||||||
|
loggerSlf4J.debug("$x\t$y")
|
||||||
|
loggerSlf4J.debug("$x\"$y")
|
||||||
|
loggerSlf4J.debug("$x$$y")
|
||||||
|
}
|
||||||
|
|
||||||
fun testLoggerSlf4J() {
|
fun testLoggerSlf4J() {
|
||||||
val variable1 = "test"
|
val variable1 = "test"
|
||||||
val variable2 = 1
|
val variable2 = 1
|
||||||
|
|||||||
@@ -274,10 +274,16 @@ abstract class KotlinUastElementFactory(project: Project) : UastElementFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun createStringLiteralExpression(text: String, context: PsiElement?): UExpression {
|
override fun createStringLiteralExpression(text: String, context: PsiElement?): UExpression {
|
||||||
val literal = psiFactory(context).createExpression(StringUtil.wrapWithDoubleQuote(text)) as KtStringTemplateExpression
|
val literal = psiFactory(context).createExpression(StringUtil.wrapWithDoubleQuote(text.escape())) as KtStringTemplateExpression
|
||||||
return KotlinStringTemplateUPolyadicExpression(literal, null)
|
return KotlinStringTemplateUPolyadicExpression(literal, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun String.escape(): String {
|
||||||
|
val stringBuilder = StringBuilder()
|
||||||
|
StringUtil.escapeStringCharacters(this.length, this, "\"$", stringBuilder)
|
||||||
|
return stringBuilder.toString()
|
||||||
|
}
|
||||||
|
|
||||||
override fun createLongConstantExpression(long: Long, context: PsiElement?): UExpression? {
|
override fun createLongConstantExpression(long: Long, context: PsiElement?): UExpression? {
|
||||||
return when (val literalExpr = psiFactory(context).createExpression(long.toString() + "L")) {
|
return when (val literalExpr = psiFactory(context).createExpression(long.toString() + "L")) {
|
||||||
is KtConstantExpression -> KotlinULiteralExpression(literalExpr, null)
|
is KtConstantExpression -> KotlinULiteralExpression(literalExpr, null)
|
||||||
|
|||||||
Reference in New Issue
Block a user