From 4692ea6a4bdfd11bef63b3cda8e4bd61caf54518 Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Wed, 27 Jun 2012 21:01:55 +0400 Subject: [PATCH] KT-2254 Incorrect indentation after = in val: #KT-2254 fixed GitOrigin-RevId: e454814d8dd898ce36462d3f864ce5f135bd6462 --- .../jetbrains/jet/plugin/formatter/JetBlock.java | 14 +++++++++++--- .../jetbrains/jet/formatter/JetFormatterTest.java | 8 ++++++++ .../jet/formatter/JetTypingIndentationTest.java | 8 ++++++++ .../functionWithTypeParameters.kt.after | 2 +- .../testData/formatter/FunctionWithInference.kt | 3 +++ .../formatter/FunctionWithInference_after.kt | 3 +++ .../IndentationOnNewline/FunctionWithInference.kt | 1 + .../FunctionWithInference_after.kt | 2 ++ .../IndentationOnNewline/PropertyWithInference.kt | 1 + .../PropertyWithInference_after.kt | 2 ++ .../formatter/PropertyWIthInference_after.kt | 3 +++ .../testData/formatter/PropertyWithInference.kt | 3 +++ 12 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 plugins/kotlin/idea/tests/testData/formatter/FunctionWithInference.kt create mode 100644 plugins/kotlin/idea/tests/testData/formatter/FunctionWithInference_after.kt create mode 100644 plugins/kotlin/idea/tests/testData/formatter/IndentationOnNewline/FunctionWithInference.kt create mode 100644 plugins/kotlin/idea/tests/testData/formatter/IndentationOnNewline/FunctionWithInference_after.kt create mode 100644 plugins/kotlin/idea/tests/testData/formatter/IndentationOnNewline/PropertyWithInference.kt create mode 100644 plugins/kotlin/idea/tests/testData/formatter/IndentationOnNewline/PropertyWithInference_after.kt create mode 100644 plugins/kotlin/idea/tests/testData/formatter/PropertyWIthInference_after.kt create mode 100644 plugins/kotlin/idea/tests/testData/formatter/PropertyWithInference.kt diff --git a/plugins/kotlin/idea/src/org/jetbrains/jet/plugin/formatter/JetBlock.java b/plugins/kotlin/idea/src/org/jetbrains/jet/plugin/formatter/JetBlock.java index 0dcfca95f28e..a24cef482847 100644 --- a/plugins/kotlin/idea/src/org/jetbrains/jet/plugin/formatter/JetBlock.java +++ b/plugins/kotlin/idea/src/org/jetbrains/jet/plugin/formatter/JetBlock.java @@ -37,8 +37,8 @@ import java.util.*; * @see Block for good JavaDoc documentation */ public class JetBlock extends AbstractBlock { - private Indent myIndent; - private CodeStyleSettings mySettings; + private final Indent myIndent; + private final CodeStyleSettings mySettings; private final SpacingBuilder mySpacingBuilder; private List mySubBlocks; @@ -158,6 +158,10 @@ public class JetBlock extends AbstractBlock { return new ChildAttributes(Indent.getContinuationIndent(), null); } + if (isIncomplete()) { + return super.getChildAttributes(newChildIndex); + } + return new ChildAttributes(Indent.getNoneIndent(), null); } @@ -266,7 +270,11 @@ public class JetBlock extends AbstractBlock { ASTIndentStrategy.forNode("For single statement in THEN and ELSE") .in(JetNodeTypes.THEN, JetNodeTypes.ELSE) .notForType(JetNodeTypes.BLOCK) - .set(Indent.getNormalIndent()) + .set(Indent.getNormalIndent()), + + ASTIndentStrategy.forNode("Indent for parts") + .in(JetNodeTypes.PROPERTY, JetNodeTypes.FUN) + .set(Indent.getContinuationWithoutFirstIndent()), }; @Nullable diff --git a/plugins/kotlin/idea/tests/test/org/jetbrains/jet/formatter/JetFormatterTest.java b/plugins/kotlin/idea/tests/test/org/jetbrains/jet/formatter/JetFormatterTest.java index 5674b8d13377..10874a50d1dd 100644 --- a/plugins/kotlin/idea/tests/test/org/jetbrains/jet/formatter/JetFormatterTest.java +++ b/plugins/kotlin/idea/tests/test/org/jetbrains/jet/formatter/JetFormatterTest.java @@ -53,6 +53,10 @@ public class JetFormatterTest extends AbstractJetFormatterTest { doTest(); } + public void testFunctionWithInference() throws Exception { + doTest(); + } + public void testGetterAndSetter() throws Exception { doTest(); } @@ -65,6 +69,10 @@ public class JetFormatterTest extends AbstractJetFormatterTest { doTestWithInvert(); } + public void testPropertyWithInference() throws Exception { + doTest(); + } + public void testRightBracketOnNewLine() throws Exception { doTestWithInvert(); } diff --git a/plugins/kotlin/idea/tests/test/org/jetbrains/jet/formatter/JetTypingIndentationTest.java b/plugins/kotlin/idea/tests/test/org/jetbrains/jet/formatter/JetTypingIndentationTest.java index 5aec6c4bdf67..77e785dfce3a 100644 --- a/plugins/kotlin/idea/tests/test/org/jetbrains/jet/formatter/JetTypingIndentationTest.java +++ b/plugins/kotlin/idea/tests/test/org/jetbrains/jet/formatter/JetTypingIndentationTest.java @@ -53,6 +53,10 @@ public class JetTypingIndentationTest extends LightCodeInsightTestCase { doFileNewlineTest(); } + public void testFunctionWithInference() { + doFileNewlineTest(); + } + public void testIf() { doFileNewlineTest(); } @@ -61,6 +65,10 @@ public class JetTypingIndentationTest extends LightCodeInsightTestCase { doFileNewlineTest(); } + public void testPropertyWithInference() { + doFileNewlineTest(); + } + public void testSettingAlignMultilineParametersInCalls() throws Exception { doFileSettingNewLineTest(); } diff --git a/plugins/kotlin/idea/tests/testData/codeInsight/overrideImplement/functionWithTypeParameters.kt.after b/plugins/kotlin/idea/tests/testData/codeInsight/overrideImplement/functionWithTypeParameters.kt.after index b3056ffb5174..3a0b2bdb45ed 100644 --- a/plugins/kotlin/idea/tests/testData/codeInsight/overrideImplement/functionWithTypeParameters.kt.after +++ b/plugins/kotlin/idea/tests/testData/codeInsight/overrideImplement/functionWithTypeParameters.kt.after @@ -7,7 +7,7 @@ trait Trait { class TraitImpl : Trait { override fun > foo() - where B: Cloneable, B: Comparable { + where B: Cloneable, B: Comparable { throw UnsupportedOperationException() } } \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/formatter/FunctionWithInference.kt b/plugins/kotlin/idea/tests/testData/formatter/FunctionWithInference.kt new file mode 100644 index 000000000000..3de1c11594aa --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/formatter/FunctionWithInference.kt @@ -0,0 +1,3 @@ +fun +test() = +12 diff --git a/plugins/kotlin/idea/tests/testData/formatter/FunctionWithInference_after.kt b/plugins/kotlin/idea/tests/testData/formatter/FunctionWithInference_after.kt new file mode 100644 index 000000000000..bcd8f70bd01e --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/formatter/FunctionWithInference_after.kt @@ -0,0 +1,3 @@ +fun + test() = + 12 diff --git a/plugins/kotlin/idea/tests/testData/formatter/IndentationOnNewline/FunctionWithInference.kt b/plugins/kotlin/idea/tests/testData/formatter/IndentationOnNewline/FunctionWithInference.kt new file mode 100644 index 000000000000..14b2fe431e4e --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/formatter/IndentationOnNewline/FunctionWithInference.kt @@ -0,0 +1 @@ +fun test() = \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/formatter/IndentationOnNewline/FunctionWithInference_after.kt b/plugins/kotlin/idea/tests/testData/formatter/IndentationOnNewline/FunctionWithInference_after.kt new file mode 100644 index 000000000000..cdd35d0107ed --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/formatter/IndentationOnNewline/FunctionWithInference_after.kt @@ -0,0 +1,2 @@ +fun test() = + \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/formatter/IndentationOnNewline/PropertyWithInference.kt b/plugins/kotlin/idea/tests/testData/formatter/IndentationOnNewline/PropertyWithInference.kt new file mode 100644 index 000000000000..771f562e866b --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/formatter/IndentationOnNewline/PropertyWithInference.kt @@ -0,0 +1 @@ +val a = \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/formatter/IndentationOnNewline/PropertyWithInference_after.kt b/plugins/kotlin/idea/tests/testData/formatter/IndentationOnNewline/PropertyWithInference_after.kt new file mode 100644 index 000000000000..c5d2284b0f16 --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/formatter/IndentationOnNewline/PropertyWithInference_after.kt @@ -0,0 +1,2 @@ +val a = + \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/formatter/PropertyWIthInference_after.kt b/plugins/kotlin/idea/tests/testData/formatter/PropertyWIthInference_after.kt new file mode 100644 index 000000000000..9fcbe03018f2 --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/formatter/PropertyWIthInference_after.kt @@ -0,0 +1,3 @@ +val + a = + 12 diff --git a/plugins/kotlin/idea/tests/testData/formatter/PropertyWithInference.kt b/plugins/kotlin/idea/tests/testData/formatter/PropertyWithInference.kt new file mode 100644 index 000000000000..eb877ed15c2c --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/formatter/PropertyWithInference.kt @@ -0,0 +1,3 @@ +val +a = +12