don't show function literals and selectors of qualified expressions in "show expression type"
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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) → Unit</html>
|
||||
// TYPE: listOf(1).map { q -> println(q) } -> <html>List<Unit></html>
|
||||
// TYPE: val x = listOf(1).map { q -> println(q) } -> <html>List<Unit></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");
|
||||
|
||||
Reference in New Issue
Block a user