From d69382f129295c0383ae1fffda1a0867c342d5f1 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Wed, 20 Dec 2017 17:31:58 +0100 Subject: [PATCH] Don't apply indent on Enter after modifier list #KT-9562 Fixed --- .../jetbrains/kotlin/idea/formatter/KotlinCommonBlock.kt | 7 +++++++ idea/testData/indentationOnNewline/Annotation.after.kt | 2 ++ idea/testData/indentationOnNewline/Annotation.kt | 1 + .../formatter/TypingIndentationTestBaseGenerated.java | 6 ++++++ 4 files changed, 16 insertions(+) create mode 100644 idea/testData/indentationOnNewline/Annotation.after.kt create mode 100644 idea/testData/indentationOnNewline/Annotation.kt diff --git a/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/KotlinCommonBlock.kt b/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/KotlinCommonBlock.kt index 45beb3a019e..5debcc1aec9 100644 --- a/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/KotlinCommonBlock.kt +++ b/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/KotlinCommonBlock.kt @@ -237,6 +237,13 @@ abstract class KotlinCommonBlock( } } + if (newChildIndex > 0) { + val prevBlock = mySubBlocks?.get(newChildIndex - 1) + if (prevBlock?.node?.elementType == KtNodeTypes.MODIFIER_LIST) { + return ChildAttributes(Indent.getNoneIndent(), null) + } + } + return when (type) { in CODE_BLOCKS, KtNodeTypes.WHEN, KtNodeTypes.IF, KtNodeTypes.FOR, KtNodeTypes.WHILE, KtNodeTypes.DO_WHILE -> ChildAttributes(Indent.getNormalIndent(), null) diff --git a/idea/testData/indentationOnNewline/Annotation.after.kt b/idea/testData/indentationOnNewline/Annotation.after.kt new file mode 100644 index 00000000000..0a4c6db1a13 --- /dev/null +++ b/idea/testData/indentationOnNewline/Annotation.after.kt @@ -0,0 +1,2 @@ +@Aaaa + diff --git a/idea/testData/indentationOnNewline/Annotation.kt b/idea/testData/indentationOnNewline/Annotation.kt new file mode 100644 index 00000000000..555e66c3b8d --- /dev/null +++ b/idea/testData/indentationOnNewline/Annotation.kt @@ -0,0 +1 @@ +@Aaaa diff --git a/idea/tests/org/jetbrains/kotlin/formatter/TypingIndentationTestBaseGenerated.java b/idea/tests/org/jetbrains/kotlin/formatter/TypingIndentationTestBaseGenerated.java index fccec108a88..7715db450a9 100644 --- a/idea/tests/org/jetbrains/kotlin/formatter/TypingIndentationTestBaseGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/formatter/TypingIndentationTestBaseGenerated.java @@ -68,6 +68,12 @@ public class TypingIndentationTestBaseGenerated extends AbstractTypingIndentatio KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/indentationOnNewline"), Pattern.compile("^([^\\.]+)\\.after\\.kt.*$"), TargetBackend.ANY, true); } + @TestMetadata("Annotation.after.kt") + public void testAnnotation() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/indentationOnNewline/Annotation.after.kt"); + doNewlineTest(fileName); + } + @TestMetadata("AssignmentAfterEq.after.kt") public void testAssignmentAfterEq() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/indentationOnNewline/AssignmentAfterEq.after.kt");