From d0991fffd2e13fe8b37c118b9a73136dbc268d98 Mon Sep 17 00:00:00 2001 From: fitermay Date: Thu, 18 May 2017 01:52:22 -0400 Subject: [PATCH] Fix keyword completion in 'if' blocks #KT-17914 fixed --- .../idea/completion/KeywordCompletion.kt | 2 +- .../testData/keywords/AfterIf.kt | 35 +++++++++++++++++++ .../testData/keywords/InElse.kt | 34 ++++++++++++++++++ .../idea-completion/testData/keywords/InIf.kt | 34 ++++++++++++++++++ .../test/KeywordCompletionTestGenerated.java | 18 ++++++++++ 5 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 idea/idea-completion/testData/keywords/AfterIf.kt create mode 100644 idea/idea-completion/testData/keywords/InElse.kt create mode 100644 idea/idea-completion/testData/keywords/InIf.kt diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KeywordCompletion.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KeywordCompletion.kt index 67d0b8ff66f..a102a39f92c 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KeywordCompletion.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KeywordCompletion.kt @@ -217,7 +217,7 @@ object KeywordCompletion { } if (prevLeaf?.getParentOfType(strict = false) != null) { - prefixText += "if(true){}" + prefixText += "if(true){}\n" } return buildFilterWithContext(prefixText, prevParent, position) diff --git a/idea/idea-completion/testData/keywords/AfterIf.kt b/idea/idea-completion/testData/keywords/AfterIf.kt new file mode 100644 index 00000000000..8f17259a759 --- /dev/null +++ b/idea/idea-completion/testData/keywords/AfterIf.kt @@ -0,0 +1,35 @@ +fun some() { + + if (true) { + + } else { + + } + + +} + + +// EXIST: do +// EXIST: as +// EXIST: class +// EXIST: else +// EXIST: false +// EXIST: for +// EXIST: fun +// EXIST: if +// EXIST: interface +// EXIST: null +// EXIST: object +// EXIST: return +// EXIST: super +// EXIST: throw +// EXIST: true +// EXIST: try +// EXIST: typealias +// EXIST: val +// EXIST: var +// EXIST: when +// EXIST: while + +// NOTHING_ELSE \ No newline at end of file diff --git a/idea/idea-completion/testData/keywords/InElse.kt b/idea/idea-completion/testData/keywords/InElse.kt new file mode 100644 index 00000000000..2f3322e7473 --- /dev/null +++ b/idea/idea-completion/testData/keywords/InElse.kt @@ -0,0 +1,34 @@ +fun some() { + + if (true) { + + } else { + + } + +} + + +// EXIST: do +// EXIST: as +// EXIST: class +// EXIST: else +// EXIST: false +// EXIST: for +// EXIST: fun +// EXIST: if +// EXIST: interface +// EXIST: null +// EXIST: object +// EXIST: return +// EXIST: super +// EXIST: throw +// EXIST: true +// EXIST: try +// EXIST: typealias +// EXIST: val +// EXIST: var +// EXIST: when +// EXIST: while + +// NOTHING_ELSE \ No newline at end of file diff --git a/idea/idea-completion/testData/keywords/InIf.kt b/idea/idea-completion/testData/keywords/InIf.kt new file mode 100644 index 00000000000..6e496c67d19 --- /dev/null +++ b/idea/idea-completion/testData/keywords/InIf.kt @@ -0,0 +1,34 @@ +fun some() { + + if (true) { + + } else { + + } + +} + + +// EXIST: do +// EXIST: as +// EXIST: class +// EXIST: else +// EXIST: false +// EXIST: for +// EXIST: fun +// EXIST: if +// EXIST: interface +// EXIST: null +// EXIST: object +// EXIST: return +// EXIST: super +// EXIST: throw +// EXIST: true +// EXIST: try +// EXIST: typealias +// EXIST: val +// EXIST: var +// EXIST: when +// EXIST: while + +// NOTHING_ELSE \ No newline at end of file diff --git a/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/KeywordCompletionTestGenerated.java b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/KeywordCompletionTestGenerated.java index 7bd52ba2186..f44d4bbf283 100644 --- a/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/KeywordCompletionTestGenerated.java +++ b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/KeywordCompletionTestGenerated.java @@ -62,6 +62,12 @@ public class KeywordCompletionTestGenerated extends AbstractKeywordCompletionTes doTest(fileName); } + @TestMetadata("AfterIf.kt") + public void testAfterIf() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/keywords/AfterIf.kt"); + doTest(fileName); + } + @TestMetadata("AfterSafeDot.kt") public void testAfterSafeDot() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/keywords/AfterSafeDot.kt"); @@ -228,6 +234,12 @@ public class KeywordCompletionTestGenerated extends AbstractKeywordCompletionTes doTest(fileName); } + @TestMetadata("InElse.kt") + public void testInElse() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/keywords/InElse.kt"); + doTest(fileName); + } + @TestMetadata("InEnumScope1.kt") public void testInEnumScope1() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/keywords/InEnumScope1.kt"); @@ -270,6 +282,12 @@ public class KeywordCompletionTestGenerated extends AbstractKeywordCompletionTes doTest(fileName); } + @TestMetadata("InIf.kt") + public void testInIf() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/keywords/InIf.kt"); + doTest(fileName); + } + @TestMetadata("InInterfaceScope.kt") public void testInInterfaceScope() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/keywords/InInterfaceScope.kt");