From 4f1f313b36bc6c4c27adbae337a51710d5a2000b Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Fri, 26 Aug 2016 11:52:49 +0200 Subject: [PATCH] don't show type of statements if they are not used as expressions --- .../kotlin/idea/codeInsight/KotlinExpressionTypeProvider.kt | 1 + idea/testData/codeInsight/expressionType/IfAsExpression.kt | 5 +++++ idea/testData/codeInsight/expressionType/SmartCast.kt | 1 - .../idea/codeInsight/ExpressionTypeTestGenerated.java | 6 ++++++ 4 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 idea/testData/codeInsight/expressionType/IfAsExpression.kt diff --git a/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinExpressionTypeProvider.kt b/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinExpressionTypeProvider.kt index 8719d258ef1..7d7d2fbc9df 100644 --- a/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinExpressionTypeProvider.kt +++ b/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinExpressionTypeProvider.kt @@ -39,6 +39,7 @@ class KotlinExpressionTypeProvider : ExpressionTypeProvider() { is KtFunction -> !hasBlockBody() && !hasDeclaredReturnType() is KtProperty, is KtDestructuringDeclarationEntry -> true is KtStatementExpression, is KtDestructuringDeclaration -> false + is KtIfExpression, is KtLoopExpression, is KtWhenExpression, is KtTryExpression -> parent !is KtBlockExpression else -> true } diff --git a/idea/testData/codeInsight/expressionType/IfAsExpression.kt b/idea/testData/codeInsight/expressionType/IfAsExpression.kt new file mode 100644 index 00000000000..e64b5777d2d --- /dev/null +++ b/idea/testData/codeInsight/expressionType/IfAsExpression.kt @@ -0,0 +1,5 @@ +val x = if (2 > 1) 3 else 4 + +// TYPE: 3 -> Int +// TYPE: if (2 > 1) 3 else 4 -> Int +// TYPE: val x = if (2 > 1) 3 else 4 -> Int diff --git a/idea/testData/codeInsight/expressionType/SmartCast.kt b/idea/testData/codeInsight/expressionType/SmartCast.kt index cb8069c6ec1..d6d1a1dbd02 100644 --- a/idea/testData/codeInsight/expressionType/SmartCast.kt +++ b/idea/testData/codeInsight/expressionType/SmartCast.kt @@ -4,6 +4,5 @@ fun foo(x: Any) { } } -// TYPE: if (x is String) { x.length } -> Unit // TYPE: x -> String (smart cast) // TYPE: x.length -> Int diff --git a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/ExpressionTypeTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/ExpressionTypeTestGenerated.java index 9b47b967f73..6ad5cf8e966 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/ExpressionTypeTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/ExpressionTypeTestGenerated.java @@ -41,6 +41,12 @@ public class ExpressionTypeTestGenerated extends AbstractExpressionTypeTest { doTest(fileName); } + @TestMetadata("IfAsExpression.kt") + public void testIfAsExpression() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/codeInsight/expressionType/IfAsExpression.kt"); + doTest(fileName); + } + @TestMetadata("MultiDeclaration.kt") public void testMultiDeclaration() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/codeInsight/expressionType/MultiDeclaration.kt");