From e6c05c3a19d1f487da2ff9241fa4c29f1dbb56a9 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Thu, 27 Oct 2016 13:25:47 +0200 Subject: [PATCH] Don't show type for reference expressions inside KtCallableReference (KT-14530) --- .../idea/codeInsight/KotlinExpressionTypeProvider.kt | 2 +- .../codeInsight/expressionType/MethodReference.kt | 9 +++++++++ .../idea/codeInsight/ExpressionTypeTestGenerated.java | 6 ++++++ 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 idea/testData/codeInsight/expressionType/MethodReference.kt diff --git a/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinExpressionTypeProvider.kt b/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinExpressionTypeProvider.kt index e11e0af94a3..387e13bdb7c 100644 --- a/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinExpressionTypeProvider.kt +++ b/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinExpressionTypeProvider.kt @@ -48,7 +48,7 @@ class KotlinExpressionTypeProvider : ExpressionTypeProvider() { is KtStatementExpression, is KtDestructuringDeclaration -> false is KtIfExpression, is KtWhenExpression, is KtTryExpression -> shouldShowStatementType() is KtLoopExpression -> false - else -> getQualifiedExpressionForSelector() == null + else -> getQualifiedExpressionForSelector() == null && parent !is KtCallableReferenceExpression } private fun KtExpression.shouldShowStatementType(): Boolean { diff --git a/idea/testData/codeInsight/expressionType/MethodReference.kt b/idea/testData/codeInsight/expressionType/MethodReference.kt new file mode 100644 index 00000000000..a0746270a2c --- /dev/null +++ b/idea/testData/codeInsight/expressionType/MethodReference.kt @@ -0,0 +1,9 @@ +fun foo() { +} + +fun bar() { + run(::foo) +} + +// TYPE: ::foo -> KFunction0<Unit> +// TYPE: run(::foo) -> Unit diff --git a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/ExpressionTypeTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/ExpressionTypeTestGenerated.java index bdc7519e630..bebb33fb31a 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/ExpressionTypeTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/ExpressionTypeTestGenerated.java @@ -65,6 +65,12 @@ public class ExpressionTypeTestGenerated extends AbstractExpressionTypeTest { doTest(fileName); } + @TestMetadata("MethodReference.kt") + public void testMethodReference() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/codeInsight/expressionType/MethodReference.kt"); + doTest(fileName); + } + @TestMetadata("MultiDeclaration.kt") public void testMultiDeclaration() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/codeInsight/expressionType/MultiDeclaration.kt");