From 54d9b4bee6dfbfa9105cf716dcbc64b3bad2769a Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Wed, 28 Sep 2016 20:35:56 +0300 Subject: [PATCH] Do not suggest assignment as a subject in postfix templates #KT-14077 Fixed --- .../idea/codeInsight/postfix/KtPostfixTemplateProvider.kt | 2 +- idea/testData/codeInsight/postfix/parAssignment.kt | 5 +++++ idea/testData/codeInsight/postfix/parAssignment.kt.after | 5 +++++ .../postfix/PostfixTemplateProviderTestGenerated.java | 6 ++++++ 4 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 idea/testData/codeInsight/postfix/parAssignment.kt create mode 100644 idea/testData/codeInsight/postfix/parAssignment.kt.after diff --git a/idea/src/org/jetbrains/kotlin/idea/codeInsight/postfix/KtPostfixTemplateProvider.kt b/idea/src/org/jetbrains/kotlin/idea/codeInsight/postfix/KtPostfixTemplateProvider.kt index ba4312f8431..bf66509f216 100644 --- a/idea/src/org/jetbrains/kotlin/idea/codeInsight/postfix/KtPostfixTemplateProvider.kt +++ b/idea/src/org/jetbrains/kotlin/idea/codeInsight/postfix/KtPostfixTemplateProvider.kt @@ -140,7 +140,7 @@ private class KtExpressionPostfixTemplateSelector( it !is KtBlockExpression && it !is KtDeclarationWithBody && !it.isEffectivelyDeclaration() - }.filter { !it.isSelector && it.parent !is KtUserType && !it.isOperationReference } + }.filter { !it.isSelector && it.parent !is KtUserType && !it.isOperationReference && !KtPsiUtil.isAssignment(it) } .toList() } diff --git a/idea/testData/codeInsight/postfix/parAssignment.kt b/idea/testData/codeInsight/postfix/parAssignment.kt new file mode 100644 index 00000000000..b01ebef9a64 --- /dev/null +++ b/idea/testData/codeInsight/postfix/parAssignment.kt @@ -0,0 +1,5 @@ +fun foo(x: Any) { + var y: Any + // Only 'x' expression is suggested, not 'y = x' + y = x.par +} diff --git a/idea/testData/codeInsight/postfix/parAssignment.kt.after b/idea/testData/codeInsight/postfix/parAssignment.kt.after new file mode 100644 index 00000000000..25c4d852a1f --- /dev/null +++ b/idea/testData/codeInsight/postfix/parAssignment.kt.after @@ -0,0 +1,5 @@ +fun foo(x: Any) { + var y: Any + // Only 'x' expression is suggested, not 'y = x' + y = (x) +} diff --git a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/postfix/PostfixTemplateProviderTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/postfix/PostfixTemplateProviderTestGenerated.java index da5c89ef801..dc45ac4131c 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/postfix/PostfixTemplateProviderTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/postfix/PostfixTemplateProviderTestGenerated.java @@ -113,6 +113,12 @@ public class PostfixTemplateProviderTestGenerated extends AbstractPostfixTemplat doTest(fileName); } + @TestMetadata("parAssignment.kt") + public void testParAssignment() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/codeInsight/postfix/parAssignment.kt"); + doTest(fileName); + } + @TestMetadata("return.kt") public void testReturn() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/codeInsight/postfix/return.kt");