mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-17 15:54:03 +00:00
Add intrinsics for compile-time computing trimMargin/trimIndent
These only apply when the receiver can be resolved to a constant and the margin prefix, if specified, is also a constant.
This commit is contained in:
committed by
Alexander Udalov
parent
2ec6ab92b5
commit
6ee987fa2e
20
compiler/testData/codegen/bytecodeText/intrinsicsTrim/trimIndentNegative.kt
vendored
Normal file
20
compiler/testData/codegen/bytecodeText/intrinsicsTrim/trimIndentNegative.kt
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
fun notConstant(arg: String): String {
|
||||
return arg.trimIndent()
|
||||
}
|
||||
|
||||
fun interpolated(arg: Int):String {
|
||||
return """
|
||||
Hello,
|
||||
$arg
|
||||
""".trimIndent()
|
||||
}
|
||||
|
||||
fun notInvoked():String {
|
||||
return """
|
||||
Hello,
|
||||
World
|
||||
"""
|
||||
}
|
||||
|
||||
// 1 LDC "\\n Hello,\\n World\\n "
|
||||
// 2 INVOKESTATIC kotlin/text/StringsKt.trimIndent
|
||||
22
compiler/testData/codegen/bytecodeText/intrinsicsTrim/trimIndentPositive.kt
vendored
Normal file
22
compiler/testData/codegen/bytecodeText/intrinsicsTrim/trimIndentPositive.kt
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
|
||||
fun constant(): String {
|
||||
return """
|
||||
Hello,
|
||||
World
|
||||
""".trimIndent()
|
||||
}
|
||||
|
||||
private const val HAS_INDENT = """Hello,
|
||||
World"""
|
||||
fun interpolatedUsingConstant(): String {
|
||||
return """
|
||||
Hello,
|
||||
$HAS_INDENT
|
||||
World
|
||||
""".trimIndent()
|
||||
}
|
||||
|
||||
// 1 LDC "Hello,\\nWorld"
|
||||
// 1 LDC "Hello,\\nHello,\\nWorld\\nWorld"
|
||||
// 0 INVOKESTATIC kotlin/text/StringsKt.trimIndent
|
||||
33
compiler/testData/codegen/bytecodeText/intrinsicsTrim/trimMarginNegative.kt
vendored
Normal file
33
compiler/testData/codegen/bytecodeText/intrinsicsTrim/trimMarginNegative.kt
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
fun notConstant(arg: String): String {
|
||||
return arg.trimMargin()
|
||||
}
|
||||
|
||||
fun notConstantCustomPrefix(arg: String): String {
|
||||
return arg.trimMargin("###")
|
||||
}
|
||||
|
||||
fun interpolated(arg: Int):String {
|
||||
return """
|
||||
|Hello,
|
||||
|$arg
|
||||
""".trimMargin()
|
||||
}
|
||||
|
||||
fun notInvoked():String {
|
||||
return """
|
||||
|Hello,
|
||||
|World
|
||||
"""
|
||||
}
|
||||
|
||||
fun constantWithNonConstantCustomPrefix(arg: String): String {
|
||||
return """
|
||||
|Hello,
|
||||
|World
|
||||
""".trimMargin(arg)
|
||||
}
|
||||
|
||||
// 1 LDC "\\n \|Hello,\\n \|"
|
||||
// 1 LDC "\\n "
|
||||
// 2 LDC "\\n \|Hello,\\n \|World\\n "
|
||||
// 4 INVOKESTATIC kotlin/text/StringsKt.trimMargin
|
||||
38
compiler/testData/codegen/bytecodeText/intrinsicsTrim/trimMarginPositive.kt
vendored
Normal file
38
compiler/testData/codegen/bytecodeText/intrinsicsTrim/trimMarginPositive.kt
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
|
||||
fun constant(): String {
|
||||
return """
|
||||
|Hello,
|
||||
|World
|
||||
""".trimMargin()
|
||||
}
|
||||
|
||||
private const val HAS_MARGIN = """Hello,
|
||||
|World"""
|
||||
fun interpolatedUsingConstant(): String {
|
||||
return """
|
||||
|Hello,
|
||||
|$HAS_MARGIN
|
||||
|World
|
||||
""".trimMargin()
|
||||
}
|
||||
|
||||
fun constantCustomPrefix(): String {
|
||||
return """
|
||||
###Hello,
|
||||
###World
|
||||
""".trimMargin(marginPrefix = "###")
|
||||
}
|
||||
|
||||
private const val OCTOTHORPE = '#'
|
||||
fun constantCustomPrefixInterpolatedUsingConstant(): String {
|
||||
return """
|
||||
#@#Hello,
|
||||
#@#World
|
||||
""".trimMargin(marginPrefix = "$OCTOTHORPE@$OCTOTHORPE")
|
||||
}
|
||||
|
||||
// 3 LDC "Hello,\\nWorld"
|
||||
// 1 LDC "Hello,\\nHello,\\nWorld\\nWorld"
|
||||
// 0 LDC "###"
|
||||
// 0 INVOKESTATIC kotlin/text/StringsKt.trimMargin
|
||||
Reference in New Issue
Block a user