LineIndentProvider: support empty brackets

Part of #KT-22211
Part of #KT-39353
This commit is contained in:
Dmitry Gridin
2020-06-10 18:36:47 +07:00
parent d69ce74ca5
commit 306abc79ed
5 changed files with 66 additions and 0 deletions
@@ -47,6 +47,9 @@ abstract class KotlinLikeLangLineIndentProvider : JavaLikeLangLineIndentProvider
before.isAt(BlockOpeningBrace) && after.isAt(BlockClosingBrace) && !currentPosition.hasLineBreaksAfter(offset) ->
return factory.createIndentCalculator(Indent.getNoneIndent(), before.startOffset)
before.isAt(ArrayOpeningBracket) && after.isAt(ArrayClosingBracket) && !currentPosition.hasLineBreaksAfter(offset) ->
return factory.createIndentCalculator(Indent.getNoneIndent(), before.startOffset)
before.isAt(BlockOpeningBrace) && before.beforeIgnoringWhiteSpaceOrComment().isFunctionDeclaration() ->
return factory.createIndentCalculator(Indent.getNormalIndent(), before.startOffset)
@@ -203,6 +203,24 @@ public class PerformanceTypingIndentationTestGenerated extends AbstractPerforman
runTest("idea/testData/indentationOnNewline/SettingAlignMultilineParametersInCalls.kt");
}
@TestMetadata("idea/testData/indentationOnNewline/arrayAccess")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class ArrayAccess extends AbstractPerformanceTypingIndentationTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doPerfTest, this, testDataFilePath);
}
public void testAllFilesPresentInArrayAccess() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/indentationOnNewline/arrayAccess"), Pattern.compile("^([^.]+)\\.(kt|kts)$"), null, true);
}
@TestMetadata("listAccess.kt")
public void testListAccess() throws Exception {
runTest("idea/testData/indentationOnNewline/arrayAccess/listAccess.kt");
}
}
@TestMetadata("idea/testData/indentationOnNewline/controlFlowConstructions")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -0,0 +1,8 @@
fun a() {
val a = listOf(1, 2)
println(
a[
<caret>
]
)
}
@@ -0,0 +1,6 @@
fun a() {
val a = listOf(1, 2)
println(
a[<caret>]
)
}
@@ -205,6 +205,24 @@ public class TypingIndentationTestBaseGenerated extends AbstractTypingIndentatio
runTest("idea/testData/indentationOnNewline/SettingAlignMultilineParametersInCalls.after.kt");
}
@TestMetadata("idea/testData/indentationOnNewline/arrayAccess")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class ArrayAccess extends AbstractTypingIndentationTestBase {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doNewlineTest, this, testDataFilePath);
}
public void testAllFilesPresentInArrayAccess() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/indentationOnNewline/arrayAccess"), Pattern.compile("^([^\\.]+)\\.after\\.kt.*$"), null, true);
}
@TestMetadata("listAccess.after.kt")
public void testListAccess() throws Exception {
runTest("idea/testData/indentationOnNewline/arrayAccess/listAccess.after.kt");
}
}
@TestMetadata("idea/testData/indentationOnNewline/controlFlowConstructions")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -1174,6 +1192,19 @@ public class TypingIndentationTestBaseGenerated extends AbstractTypingIndentatio
runTest("idea/testData/indentationOnNewline/SettingAlignMultilineParametersInCalls.after.inv.kt");
}
@TestMetadata("idea/testData/indentationOnNewline/arrayAccess")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class ArrayAccess extends AbstractTypingIndentationTestBase {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doNewlineTestWithInvert, this, testDataFilePath);
}
public void testAllFilesPresentInArrayAccess() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/indentationOnNewline/arrayAccess"), Pattern.compile("^([^\\.]+)\\.after\\.inv\\.kt.*$"), null, true);
}
}
@TestMetadata("idea/testData/indentationOnNewline/controlFlowConstructions")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)