diff --git a/ChangeLog.md b/ChangeLog.md index b8ed1700881..dc42df04187 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -42,6 +42,7 @@ Issues fixed: - [KT-11512](https://youtrack.jetbrains.com/issue/KT-11512) Allow choosing any source root in "Move file to directory" intention - [KT-10950](https://youtrack.jetbrains.com/issue/KT-10950) Keep original file package name when moving top-level declarations to separate file (provided it's not ambiguous) - [KT-10174](https://youtrack.jetbrains.com/issue/KT-10174) Optimize imports after applying "Move declaration to separate file" intention +- [KT-12035](https://youtrack.jetbrains.com/issue/KT-12035) Auto-format cast expressions #### Debugger diff --git a/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/kotlinSpacingRules.kt b/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/kotlinSpacingRules.kt index 2133bc10edc..38704c29a19 100644 --- a/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/kotlinSpacingRules.kt +++ b/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/kotlinSpacingRules.kt @@ -164,6 +164,8 @@ fun createSpacingBuilder(settings: CodeStyleSettings, builderUtil: KotlinSpacing betweenInside(DOT, IDENTIFIER, FUN).spacing(0, 0, 0, false, 0) afterInside(IDENTIFIER, FUN).spacing(0, 0, 0, false, 0) + around(AS_KEYWORD).spaces(1) + // before LPAR in constructor(): this() {} after(CONSTRUCTOR_DELEGATION_REFERENCE).spacing(0, 0, 0, false, 0) diff --git a/idea/testData/formatter/Cast.after.kt b/idea/testData/formatter/Cast.after.kt new file mode 100644 index 00000000000..542750af173 --- /dev/null +++ b/idea/testData/formatter/Cast.after.kt @@ -0,0 +1,3 @@ +fun foo() { + val a = 1 as Int +} \ No newline at end of file diff --git a/idea/testData/formatter/Cast.kt b/idea/testData/formatter/Cast.kt new file mode 100644 index 00000000000..ce6776f3708 --- /dev/null +++ b/idea/testData/formatter/Cast.kt @@ -0,0 +1,3 @@ +fun foo() { + val a = 1 as Int +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/formatter/FormatterTestGenerated.java b/idea/tests/org/jetbrains/kotlin/formatter/FormatterTestGenerated.java index f0ab1d2874a..462325de902 100644 --- a/idea/tests/org/jetbrains/kotlin/formatter/FormatterTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/formatter/FormatterTestGenerated.java @@ -91,6 +91,12 @@ public class FormatterTestGenerated extends AbstractFormatterTest { doTest(fileName); } + @TestMetadata("Cast.after.kt") + public void testCast() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/formatter/Cast.after.kt"); + doTest(fileName); + } + @TestMetadata("CatchFinallyOnNewLine.after.kt") public void testCatchFinallyOnNewLine() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/formatter/CatchFinallyOnNewLine.after.kt");