Formatter: fix indent for multiline expression in string template
#KT-35359 Fixed
This commit is contained in:
@@ -906,7 +906,17 @@ private val INDENT_RULES = arrayOf(
|
||||
strategy("Indent for block content")
|
||||
.within(BLOCK, CLASS_BODY, FUNCTION_LITERAL)
|
||||
.notForType(RBRACE, LBRACE, BLOCK)
|
||||
.set(Indent.getNormalIndent(false)),
|
||||
.set(Indent.getNormalIndent()),
|
||||
|
||||
strategy("Indent for template content")
|
||||
.within(LONG_STRING_TEMPLATE_ENTRY)
|
||||
.notForType(LONG_TEMPLATE_ENTRY_START, LONG_TEMPLATE_ENTRY_END)
|
||||
.set(Indent.getNormalIndent()),
|
||||
|
||||
strategy("No indent for braces in template")
|
||||
.within(LONG_STRING_TEMPLATE_ENTRY)
|
||||
.forType(LONG_TEMPLATE_ENTRY_START, LONG_TEMPLATE_ENTRY_END)
|
||||
.set(Indent.getNoneIndent()),
|
||||
|
||||
strategy("Indent for property accessors")
|
||||
.within(PROPERTY).forType(PROPERTY_ACCESSOR)
|
||||
@@ -1006,7 +1016,7 @@ private val INDENT_RULES = arrayOf(
|
||||
strategy("Colon of delegation list")
|
||||
.within(CLASS, OBJECT_DECLARATION)
|
||||
.forType(COLON)
|
||||
.set(Indent.getNormalIndent(false)),
|
||||
.set(Indent.getNormalIndent()),
|
||||
|
||||
strategy("Delegation list")
|
||||
.within(SUPER_TYPE_LIST)
|
||||
|
||||
@@ -240,6 +240,9 @@ fun createSpacingBuilder(settings: CodeStyleSettings, builderUtil: KotlinSpacing
|
||||
else
|
||||
null
|
||||
}
|
||||
|
||||
inPosition(parent = LONG_STRING_TEMPLATE_ENTRY, right = LONG_TEMPLATE_ENTRY_END).lineBreakIfLineBreakInParent(0)
|
||||
inPosition(parent = LONG_STRING_TEMPLATE_ENTRY, left = LONG_TEMPLATE_ENTRY_START).lineBreakIfLineBreakInParent(0)
|
||||
}
|
||||
|
||||
simple {
|
||||
@@ -396,9 +399,6 @@ fun createSpacingBuilder(settings: CodeStyleSettings, builderUtil: KotlinSpacing
|
||||
betweenInside(LPAR, DESTRUCTURING_DECLARATION, FOR).spaces(0)
|
||||
betweenInside(LOOP_RANGE, RPAR, FOR).spaces(0)
|
||||
|
||||
after(LONG_TEMPLATE_ENTRY_START).spaces(0)
|
||||
before(LONG_TEMPLATE_ENTRY_END).spaces(0)
|
||||
|
||||
afterInside(ANNOTATION_ENTRY, ANNOTATED_EXPRESSION).spaces(1)
|
||||
|
||||
before(SEMICOLON).spaces(0)
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
fun test() {
|
||||
val message1 = "${
|
||||
"sd"
|
||||
}"
|
||||
val message2 = {
|
||||
"sd"
|
||||
}()
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fun test() {
|
||||
val message1 = "${
|
||||
"sd"
|
||||
}"
|
||||
val message2 = {
|
||||
"sd"
|
||||
}()
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
fun test() {
|
||||
val message1 = "${"sd"}"
|
||||
val message2 = { "sd" }()
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
fun test() {
|
||||
val message1 = "${"sd"}"
|
||||
val message2 = {"sd"}()
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
val message = "${
|
||||
"sd"
|
||||
}"
|
||||
@@ -0,0 +1,2 @@
|
||||
val message = "${"sd"
|
||||
}"
|
||||
@@ -0,0 +1,5 @@
|
||||
fun test() {
|
||||
val message = "start ${
|
||||
"sd"
|
||||
} end"
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
fun test() {
|
||||
val message = "start ${
|
||||
"sd"} end"
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
fun test() {
|
||||
"start ${
|
||||
println("sd")
|
||||
} end"
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
fun test() {
|
||||
"start ${
|
||||
println("sd")} end"
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fun test() {
|
||||
"start ${
|
||||
println(
|
||||
"sd"
|
||||
)
|
||||
} end"
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
fun test() {
|
||||
"start ${println(
|
||||
"sd"
|
||||
)} end"
|
||||
}
|
||||
+4
-2
@@ -1,2 +1,4 @@
|
||||
val v = "${2 +
|
||||
2}"
|
||||
val v = "${
|
||||
2 +
|
||||
2
|
||||
}"
|
||||
Vendored
+4
-2
@@ -1,4 +1,6 @@
|
||||
fun foo() {
|
||||
val y = "x=${"""ab
|
||||
c"""}"
|
||||
val y = "x=${
|
||||
"""ab
|
||||
c"""
|
||||
}"
|
||||
}
|
||||
@@ -545,6 +545,36 @@ public class FormatterTestGenerated extends AbstractFormatterTest {
|
||||
runTest("idea/testData/formatter/MultilineFunctionLiteralWithParams.after.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("MultilineStringEntry.after.kt")
|
||||
public void testMultilineStringEntry() throws Exception {
|
||||
runTest("idea/testData/formatter/MultilineStringEntry.after.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("MultilineStringEntry2.after.kt")
|
||||
public void testMultilineStringEntry2() throws Exception {
|
||||
runTest("idea/testData/formatter/MultilineStringEntry2.after.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("MultilineStringEntry3.after.kt")
|
||||
public void testMultilineStringEntry3() throws Exception {
|
||||
runTest("idea/testData/formatter/MultilineStringEntry3.after.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("MultilineStringEntry4.after.kt")
|
||||
public void testMultilineStringEntry4() throws Exception {
|
||||
runTest("idea/testData/formatter/MultilineStringEntry4.after.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("MultilineStringEntry5.after.kt")
|
||||
public void testMultilineStringEntry5() throws Exception {
|
||||
runTest("idea/testData/formatter/MultilineStringEntry5.after.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("MultilineStringEntry6.after.kt")
|
||||
public void testMultilineStringEntry6() throws Exception {
|
||||
runTest("idea/testData/formatter/MultilineStringEntry6.after.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("NewLineForRBrace.after.kt")
|
||||
public void testNewLineForRBrace() throws Exception {
|
||||
runTest("idea/testData/formatter/NewLineForRBrace.after.kt");
|
||||
|
||||
Reference in New Issue
Block a user