don't show function literals and selectors of qualified expressions in "show expression type"

This commit is contained in:
Dmitry Jemerov
2016-08-26 17:19:00 +02:00
parent 256fd04e95
commit 02a5856ffd
3 changed files with 16 additions and 1 deletions
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.caches.resolve.findModuleDescriptor
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.getQualifiedExpressionForSelector
import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf
import org.jetbrains.kotlin.renderer.DescriptorRenderer
import org.jetbrains.kotlin.renderer.RenderingFormat
@@ -38,13 +39,14 @@ class KotlinExpressionTypeProvider : ExpressionTypeProvider<KtExpression>() {
elementAt.parentsWithSelf.filterIsInstance<KtExpression>().filter { it.shouldShowType() }.toList()
private fun KtExpression.shouldShowType() = when(this) {
is KtFunctionLiteral -> false
is KtFunction -> !hasBlockBody() && !hasDeclaredReturnType()
is KtProperty -> typeReference == null
is KtPropertyAccessor -> false
is KtDestructuringDeclarationEntry -> true
is KtStatementExpression, is KtDestructuringDeclaration -> false
is KtIfExpression, is KtLoopExpression, is KtWhenExpression, is KtTryExpression -> parent !is KtBlockExpression
else -> true
else -> getQualifiedExpressionForSelector() == null
}
override fun getInformationHint(element: KtExpression): String {
+7
View File
@@ -0,0 +1,7 @@
val x = listOf(1).map { q -> println(<caret>q) }
// TYPE: q -> <html>Int</html>
// TYPE: println(q) -> <html>Unit</html>
// TYPE: { q -> println(q) } -> <html>(Int) &rarr; Unit</html>
// TYPE: listOf(1).map { q -> println(q) } -> <html>List&lt;Unit&gt;</html>
// TYPE: val x = listOf(1).map { q -> println(q) } -> <html>List&lt;Unit&gt;</html>
@@ -53,6 +53,12 @@ public class ExpressionTypeTestGenerated extends AbstractExpressionTypeTest {
doTest(fileName);
}
@TestMetadata("Lambda.kt")
public void testLambda() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/codeInsight/expressionType/Lambda.kt");
doTest(fileName);
}
@TestMetadata("MultiDeclaration.kt")
public void testMultiDeclaration() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/codeInsight/expressionType/MultiDeclaration.kt");