diff --git a/idea/line-indent-provider/src/org/jetbrains/kotlin/idea/formatter/lineIndent/KotlinLikeLangLineIndentProvider.kt b/idea/line-indent-provider/src/org/jetbrains/kotlin/idea/formatter/lineIndent/KotlinLikeLangLineIndentProvider.kt index 21c896cf2d3..97bc11dda22 100644 --- a/idea/line-indent-provider/src/org/jetbrains/kotlin/idea/formatter/lineIndent/KotlinLikeLangLineIndentProvider.kt +++ b/idea/line-indent-provider/src/org/jetbrains/kotlin/idea/formatter/lineIndent/KotlinLikeLangLineIndentProvider.kt @@ -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) diff --git a/idea/performanceTests/test/org/jetbrains/kotlin/idea/perf/PerformanceTypingIndentationTestGenerated.java b/idea/performanceTests/test/org/jetbrains/kotlin/idea/perf/PerformanceTypingIndentationTestGenerated.java index cb0ab9a7b37..61e9f91fb4f 100644 --- a/idea/performanceTests/test/org/jetbrains/kotlin/idea/perf/PerformanceTypingIndentationTestGenerated.java +++ b/idea/performanceTests/test/org/jetbrains/kotlin/idea/perf/PerformanceTypingIndentationTestGenerated.java @@ -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) diff --git a/idea/testData/indentationOnNewline/arrayAccess/listAccess.after.kt b/idea/testData/indentationOnNewline/arrayAccess/listAccess.after.kt new file mode 100644 index 00000000000..7b440c75065 --- /dev/null +++ b/idea/testData/indentationOnNewline/arrayAccess/listAccess.after.kt @@ -0,0 +1,8 @@ +fun a() { + val a = listOf(1, 2) + println( + a[ + + ] + ) +} diff --git a/idea/testData/indentationOnNewline/arrayAccess/listAccess.kt b/idea/testData/indentationOnNewline/arrayAccess/listAccess.kt new file mode 100644 index 00000000000..411fd3074b0 --- /dev/null +++ b/idea/testData/indentationOnNewline/arrayAccess/listAccess.kt @@ -0,0 +1,6 @@ +fun a() { + val a = listOf(1, 2) + println( + a[] + ) +} diff --git a/idea/tests/org/jetbrains/kotlin/formatter/TypingIndentationTestBaseGenerated.java b/idea/tests/org/jetbrains/kotlin/formatter/TypingIndentationTestBaseGenerated.java index 2f2e28681ef..2a7465c07a2 100644 --- a/idea/tests/org/jetbrains/kotlin/formatter/TypingIndentationTestBaseGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/formatter/TypingIndentationTestBaseGenerated.java @@ -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)