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 cea091d1ad6..27668caa22d 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 @@ -68,6 +68,9 @@ abstract class KotlinLikeLangLineIndentProvider : JavaLikeLangLineIndentProvider val before = currentPosition.beforeOptionalMix(*WHITE_SPACE_OR_COMMENT_BIT_SET) val after = currentPosition.afterOptionalMix(*WHITE_SPACE_OR_COMMENT_BIT_SET) when { + before.isAt(BlockOpeningBrace) && after.isAt(BlockClosingBrace) && !currentPosition.hasLineBreaksAfter(offset) -> + return factory.createIndentCalculator(Indent.getNoneIndent(), before.startOffset) + after.isAt(Quest) && after.after().isAt(Colon) -> { val indent = if (settings.continuationIndentInElvis) Indent.getContinuationIndent() @@ -110,10 +113,8 @@ abstract class KotlinLikeLangLineIndentProvider : JavaLikeLangLineIndentProvider } } - before.isAt(LeftParenthesis) && after.isAt(RightParenthesis) -> { - val indentCalculator = factory.createIndentCalculatorForParenthesis(before, currentPosition, after, offset, settings) - if (indentCalculator != null) return indentCalculator - } + before.isAt(LeftParenthesis) && after.isAt(RightParenthesis) -> + factory.createIndentCalculatorForParenthesis(before, currentPosition, after, offset, settings)?.let { return it } } findFunctionOrPropertyDeclarationBefore(before)?.let { 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 be5b2cd45af..cb0ab9a7b37 100644 --- a/idea/performanceTests/test/org/jetbrains/kotlin/idea/perf/PerformanceTypingIndentationTestGenerated.java +++ b/idea/performanceTests/test/org/jetbrains/kotlin/idea/perf/PerformanceTypingIndentationTestGenerated.java @@ -88,6 +88,11 @@ public class PerformanceTypingIndentationTestGenerated extends AbstractPerforman runTest("idea/testData/indentationOnNewline/FunctionBlock.kt"); } + @TestMetadata("FunctionBlock2.kt") + public void testFunctionBlock2() throws Exception { + runTest("idea/testData/indentationOnNewline/FunctionBlock2.kt"); + } + @TestMetadata("InDelegationListAfterColon.kt") public void testInDelegationListAfterColon() throws Exception { runTest("idea/testData/indentationOnNewline/InDelegationListAfterColon.kt"); diff --git a/idea/testData/indentationOnNewline/FunctionBlock.after.kt b/idea/testData/indentationOnNewline/FunctionBlock.after.kt index a78751ea52e..ba24eb49187 100644 --- a/idea/testData/indentationOnNewline/FunctionBlock.after.kt +++ b/idea/testData/indentationOnNewline/FunctionBlock.after.kt @@ -7,5 +7,3 @@ fun main(args: Array) { } } - -// WITHOUT_CUSTOM_LINE_INDENT_PROVIDER \ No newline at end of file diff --git a/idea/testData/indentationOnNewline/FunctionBlock.kt b/idea/testData/indentationOnNewline/FunctionBlock.kt index da53d49ec12..928b1e28843 100644 --- a/idea/testData/indentationOnNewline/FunctionBlock.kt +++ b/idea/testData/indentationOnNewline/FunctionBlock.kt @@ -5,5 +5,3 @@ private fun times(times : Int, body : () -> T) {} fun main(args: Array) { times(3) {} } - -// WITHOUT_CUSTOM_LINE_INDENT_PROVIDER \ No newline at end of file diff --git a/idea/testData/indentationOnNewline/FunctionBlock2.after.kt b/idea/testData/indentationOnNewline/FunctionBlock2.after.kt new file mode 100644 index 00000000000..c49ef045b63 --- /dev/null +++ b/idea/testData/indentationOnNewline/FunctionBlock2.after.kt @@ -0,0 +1,13 @@ +package testing + +private fun times(times : Int, body : () -> T) {} + +fun main(args: Array) { + times(3) { + + + + + + } +} diff --git a/idea/testData/indentationOnNewline/FunctionBlock2.kt b/idea/testData/indentationOnNewline/FunctionBlock2.kt new file mode 100644 index 00000000000..4014a41fffd --- /dev/null +++ b/idea/testData/indentationOnNewline/FunctionBlock2.kt @@ -0,0 +1,11 @@ +package testing + +private fun times(times : Int, body : () -> T) {} + +fun main(args: Array) { + times(3) { + + + + } +} diff --git a/idea/testData/indentationOnNewline/InLambdaInsideChainCallSameLine.after.kt b/idea/testData/indentationOnNewline/InLambdaInsideChainCallSameLine.after.kt index 4cfb95b0031..4c72a986e93 100644 --- a/idea/testData/indentationOnNewline/InLambdaInsideChainCallSameLine.after.kt +++ b/idea/testData/indentationOnNewline/InLambdaInsideChainCallSameLine.after.kt @@ -7,5 +7,3 @@ fun test() { } } - -// WITHOUT_CUSTOM_LINE_INDENT_PROVIDER \ No newline at end of file diff --git a/idea/testData/indentationOnNewline/InLambdaInsideChainCallSameLine.kt b/idea/testData/indentationOnNewline/InLambdaInsideChainCallSameLine.kt index 8a8e0330e32..b8e40731298 100644 --- a/idea/testData/indentationOnNewline/InLambdaInsideChainCallSameLine.kt +++ b/idea/testData/indentationOnNewline/InLambdaInsideChainCallSameLine.kt @@ -5,5 +5,3 @@ class Test { fun test() { val abc = Test().foo()?.foo({ "str" }).foo {} } - -// WITHOUT_CUSTOM_LINE_INDENT_PROVIDER \ No newline at end of file diff --git a/idea/testData/indentationOnNewline/InLambdaInsideChainCallSameLineWithSpaces.after.kt b/idea/testData/indentationOnNewline/InLambdaInsideChainCallSameLineWithSpaces.after.kt index 4cfb95b0031..4c72a986e93 100644 --- a/idea/testData/indentationOnNewline/InLambdaInsideChainCallSameLineWithSpaces.after.kt +++ b/idea/testData/indentationOnNewline/InLambdaInsideChainCallSameLineWithSpaces.after.kt @@ -7,5 +7,3 @@ fun test() { } } - -// WITHOUT_CUSTOM_LINE_INDENT_PROVIDER \ No newline at end of file diff --git a/idea/testData/indentationOnNewline/InLambdaInsideChainCallSameLineWithSpaces.kt b/idea/testData/indentationOnNewline/InLambdaInsideChainCallSameLineWithSpaces.kt index fc48c148a68..d38e13dfdb9 100644 --- a/idea/testData/indentationOnNewline/InLambdaInsideChainCallSameLineWithSpaces.kt +++ b/idea/testData/indentationOnNewline/InLambdaInsideChainCallSameLineWithSpaces.kt @@ -5,5 +5,3 @@ class Test { fun test() { val abc = Test().foo()?.foo({ "str" }).foo { } } - -// WITHOUT_CUSTOM_LINE_INDENT_PROVIDER \ No newline at end of file diff --git a/idea/testData/indentationOnNewline/InLambdaInsideChainCallWithNewLine.after.kt b/idea/testData/indentationOnNewline/InLambdaInsideChainCallWithNewLine.after.kt index c083eb9e5c7..2b9e8e6e050 100644 --- a/idea/testData/indentationOnNewline/InLambdaInsideChainCallWithNewLine.after.kt +++ b/idea/testData/indentationOnNewline/InLambdaInsideChainCallWithNewLine.after.kt @@ -9,5 +9,3 @@ fun test() { } } - -// WITHOUT_CUSTOM_LINE_INDENT_PROVIDER \ No newline at end of file diff --git a/idea/testData/indentationOnNewline/InLambdaInsideChainCallWithNewLine.kt b/idea/testData/indentationOnNewline/InLambdaInsideChainCallWithNewLine.kt index 90e5bd42b2d..324ff463c8e 100644 --- a/idea/testData/indentationOnNewline/InLambdaInsideChainCallWithNewLine.kt +++ b/idea/testData/indentationOnNewline/InLambdaInsideChainCallWithNewLine.kt @@ -7,5 +7,3 @@ fun test() { .foo { "Str" } .foo {} } - -// WITHOUT_CUSTOM_LINE_INDENT_PROVIDER \ No newline at end of file diff --git a/idea/testData/indentationOnNewline/InLambdaInsideChainCallWithNewLineWithSpaces.after.kt b/idea/testData/indentationOnNewline/InLambdaInsideChainCallWithNewLineWithSpaces.after.kt index c083eb9e5c7..2b9e8e6e050 100644 --- a/idea/testData/indentationOnNewline/InLambdaInsideChainCallWithNewLineWithSpaces.after.kt +++ b/idea/testData/indentationOnNewline/InLambdaInsideChainCallWithNewLineWithSpaces.after.kt @@ -9,5 +9,3 @@ fun test() { } } - -// WITHOUT_CUSTOM_LINE_INDENT_PROVIDER \ No newline at end of file diff --git a/idea/testData/indentationOnNewline/InLambdaInsideChainCallWithNewLineWithSpaces.kt b/idea/testData/indentationOnNewline/InLambdaInsideChainCallWithNewLineWithSpaces.kt index 174cd06e695..23810c09e6c 100644 --- a/idea/testData/indentationOnNewline/InLambdaInsideChainCallWithNewLineWithSpaces.kt +++ b/idea/testData/indentationOnNewline/InLambdaInsideChainCallWithNewLineWithSpaces.kt @@ -7,5 +7,3 @@ fun test() { .foo { "Str" } .foo { } } - -// WITHOUT_CUSTOM_LINE_INDENT_PROVIDER \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/formatter/TypingIndentationTestBaseGenerated.java b/idea/tests/org/jetbrains/kotlin/formatter/TypingIndentationTestBaseGenerated.java index d63641c5a74..2f2e28681ef 100644 --- a/idea/tests/org/jetbrains/kotlin/formatter/TypingIndentationTestBaseGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/formatter/TypingIndentationTestBaseGenerated.java @@ -90,6 +90,11 @@ public class TypingIndentationTestBaseGenerated extends AbstractTypingIndentatio runTest("idea/testData/indentationOnNewline/FunctionBlock.after.kt"); } + @TestMetadata("FunctionBlock2.after.kt") + public void testFunctionBlock2() throws Exception { + runTest("idea/testData/indentationOnNewline/FunctionBlock2.after.kt"); + } + @TestMetadata("InDelegationListAfterColon.after.kt") public void testInDelegationListAfterColon() throws Exception { runTest("idea/testData/indentationOnNewline/InDelegationListAfterColon.after.kt");