diff --git a/idea/src/org/jetbrains/kotlin/idea/codeInsight/postfix/surrounderBasedPostfixTemplates.kt b/idea/src/org/jetbrains/kotlin/idea/codeInsight/postfix/surrounderBasedPostfixTemplates.kt index e506f067041..19901b19c6b 100644 --- a/idea/src/org/jetbrains/kotlin/idea/codeInsight/postfix/surrounderBasedPostfixTemplates.kt +++ b/idea/src/org/jetbrains/kotlin/idea/codeInsight/postfix/surrounderBasedPostfixTemplates.kt @@ -29,14 +29,14 @@ import org.jetbrains.kotlin.types.typeUtil.isBoolean internal object KtIfExpressionPostfixTemplate : SurroundPostfixTemplateBase( "if", "if (expr)", - KtPostfixTemplatePsiInfo, createExpressionSelector(statementsOnly = true) { it.isBoolean() } + KtPostfixTemplatePsiInfo, createExpressionSelector(statementsOnly = false) { it.isBoolean() } ) { override fun getSurrounder() = KotlinWithIfExpressionSurrounder(withElse = false) } internal object KtElseExpressionPostfixTemplate : SurroundPostfixTemplateBase( "else", "if (!expr)", - KtPostfixTemplatePsiInfo, createExpressionSelector(statementsOnly = true) { it.isBoolean() } + KtPostfixTemplatePsiInfo, createExpressionSelector(statementsOnly = false) { it.isBoolean() } ) { override fun getSurrounder() = KotlinWithIfExpressionSurrounder(withElse = false) override fun getWrappedExpression(expression: PsiElement?) = (expression as KtExpression).negate() @@ -44,7 +44,7 @@ internal object KtElseExpressionPostfixTemplate : SurroundPostfixTemplateBase( internal class KtNotNullPostfixTemplate(val name: String) : SurroundPostfixTemplateBase( name, "if (expr != null)", - KtPostfixTemplatePsiInfo, createExpressionSelector(statementsOnly = true, predicate = TypeUtils::isNullableType) + KtPostfixTemplatePsiInfo, createExpressionSelector(statementsOnly = false, predicate = TypeUtils::isNullableType) ) { override fun getSurrounder() = KotlinWithIfExpressionSurrounder(withElse = false) override fun getTail() = "!= null" @@ -52,7 +52,7 @@ internal class KtNotNullPostfixTemplate(val name: String) : SurroundPostfixTempl internal object KtIsNullPostfixTemplate : SurroundPostfixTemplateBase( "null", "if (expr == null)", - KtPostfixTemplatePsiInfo, createExpressionSelector(statementsOnly = true, predicate = TypeUtils::isNullableType) + KtPostfixTemplatePsiInfo, createExpressionSelector(statementsOnly = false, predicate = TypeUtils::isNullableType) ) { override fun getSurrounder() = KotlinWithIfExpressionSurrounder(withElse = false) override fun getTail() = "== null" @@ -60,14 +60,14 @@ internal object KtIsNullPostfixTemplate : SurroundPostfixTemplateBase( internal object KtWhenExpressionPostfixTemplate : SurroundPostfixTemplateBase( "when", "when (expr)", - KtPostfixTemplatePsiInfo, createExpressionSelector(statementsOnly = true) + KtPostfixTemplatePsiInfo, createExpressionSelector(statementsOnly = false) ) { override fun getSurrounder() = KotlinWhenSurrounder() } internal object KtTryPostfixTemplate : SurroundPostfixTemplateBase( "try", "try { code } catch (e: Exception) { }", - KtPostfixTemplatePsiInfo, createExpressionSelector(statementsOnly = true) + KtPostfixTemplatePsiInfo, createExpressionSelector(statementsOnly = false) ) { override fun getSurrounder() = KotlinTryCatchSurrounder() } diff --git a/idea/testData/codeInsight/postfix/whenExpression.kt b/idea/testData/codeInsight/postfix/whenExpression.kt new file mode 100644 index 00000000000..42156014ed3 --- /dev/null +++ b/idea/testData/codeInsight/postfix/whenExpression.kt @@ -0,0 +1,3 @@ +fun foo(x: String) { + val y = x.when +} diff --git a/idea/testData/codeInsight/postfix/whenExpression.kt.after b/idea/testData/codeInsight/postfix/whenExpression.kt.after new file mode 100644 index 00000000000..e722dfdff51 --- /dev/null +++ b/idea/testData/codeInsight/postfix/whenExpression.kt.after @@ -0,0 +1,8 @@ +fun foo(x: String) { + val y = when (x) { + -> { + } + else -> { + } + } +} 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 128ad6335c5..da5c89ef801 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/postfix/PostfixTemplateProviderTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/postfix/PostfixTemplateProviderTestGenerated.java @@ -161,6 +161,12 @@ public class PostfixTemplateProviderTestGenerated extends AbstractPostfixTemplat doTest(fileName); } + @TestMetadata("whenExpression.kt") + public void testWhenExpression() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/codeInsight/postfix/whenExpression.kt"); + doTest(fileName); + } + @TestMetadata("while.kt") public void testWhile() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/codeInsight/postfix/while.kt");