diff --git a/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinExpressionTypeProvider.kt b/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinExpressionTypeProvider.kt index 109acc0bc8a..7151f5ecd1f 100644 --- a/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinExpressionTypeProvider.kt +++ b/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinExpressionTypeProvider.kt @@ -29,10 +29,13 @@ import org.jetbrains.kotlin.types.KotlinType class KotlinExpressionTypeProvider : ExpressionTypeProvider() { override fun getExpressionsAt(elementAt: PsiElement): List = - elementAt.parentsWithSelf.filterIsInstance().filterNot { it.shouldSkip() }.toList() + elementAt.parentsWithSelf.filterIsInstance().filter { it.shouldShowType() }.toList() - private fun KtExpression.shouldSkip(): Boolean { - return this is KtStatementExpression && this !is KtFunction && this !is KtProperty + private fun KtExpression.shouldShowType() = when(this) { + is KtFunction -> !hasBlockBody() && !hasDeclaredReturnType() + is KtProperty -> true + is KtStatementExpression -> false + else -> true } override fun getInformationHint(element: KtExpression): String { diff --git a/idea/testData/codeInsight/expressionType/BlockBodyFunction.kt b/idea/testData/codeInsight/expressionType/BlockBodyFunction.kt new file mode 100644 index 00000000000..f353751faef --- /dev/null +++ b/idea/testData/codeInsight/expressionType/BlockBodyFunction.kt @@ -0,0 +1,5 @@ +fun foo() { + val x = 1 +} + +// TYPE: val x = 1 -> kotlin.Int diff --git a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/AbstractExpressionTypeTest.kt b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/AbstractExpressionTypeTest.kt index e3ae661aa06..e55f66c98aa 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/AbstractExpressionTypeTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/AbstractExpressionTypeTest.kt @@ -28,7 +28,7 @@ abstract class AbstractExpressionTypeTest : KotlinLightCodeInsightFixtureTestCas myFixture.configureByFile(path) val expressionTypeProvider = KotlinExpressionTypeProvider() val expressions = expressionTypeProvider.getExpressionsAt(myFixture.elementAtCaret) - val types = expressions.map { "${it.text} -> ${expressionTypeProvider.getInformationHint(it)}" } + val types = expressions.map { "${it.text.replace('\n', ' ')} -> ${expressionTypeProvider.getInformationHint(it)}" } val expectedTypes = InTextDirectivesUtils.findListWithPrefixes(myFixture.file.text, "// TYPE: ") UsefulTestCase.assertSameElements(types, expectedTypes) } diff --git a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/ExpressionTypeTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/ExpressionTypeTestGenerated.java index 432b1a1867c..d460199814e 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/ExpressionTypeTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/ExpressionTypeTestGenerated.java @@ -35,6 +35,12 @@ public class ExpressionTypeTestGenerated extends AbstractExpressionTypeTest { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/codeInsight/expressionType"), Pattern.compile("^(.+)\\.kt$"), true); } + @TestMetadata("BlockBodyFunction.kt") + public void testBlockBodyFunction() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/codeInsight/expressionType/BlockBodyFunction.kt"); + doTest(fileName); + } + @TestMetadata("VariableDeclaration.kt") public void testVariableDeclaration() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/codeInsight/expressionType/VariableDeclaration.kt");