Don't consider function names as candidates for "Show expression type" (KT-14384)

This commit is contained in:
Dmitry Jemerov
2016-10-27 14:03:01 +02:00
parent 4246fcf256
commit 25c7dccd3b
3 changed files with 20 additions and 1 deletions
@@ -21,12 +21,14 @@ import com.intellij.psi.PsiElement
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.idea.references.mainReference
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
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
import org.jetbrains.kotlin.resolve.calls.callUtil.getType
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
@@ -51,7 +53,7 @@ class KotlinExpressionTypeProvider : ExpressionTypeProvider<KtExpression>() {
is KtIfExpression, is KtWhenExpression, is KtTryExpression -> shouldShowStatementType()
is KtLoopExpression -> false
is KtConstantExpression -> false
else -> getQualifiedExpressionForSelector() == null && parent !is KtCallableReferenceExpression
else -> getQualifiedExpressionForSelector() == null && parent !is KtCallableReferenceExpression && !isFunctionCallee()
}
private fun KtExpression.shouldShowStatementType(): Boolean {
@@ -62,6 +64,12 @@ class KotlinExpressionTypeProvider : ExpressionTypeProvider<KtExpression>() {
return false
}
private fun KtExpression.isFunctionCallee(): Boolean {
val callExpression = parent as? KtCallExpression ?: return false
if (callExpression.calleeExpression != this) return false
return mainReference?.resolve() is KtFunction
}
override fun getInformationHint(element: KtExpression): String {
val bindingContext = element.analyze(BodyResolveMode.PARTIAL)
@@ -0,0 +1,5 @@
fun foo(value: String) {
print<caret>ln(value)
}
// TYPE: println(value) -> <html>Unit</html>
@@ -65,6 +65,12 @@ public class ExpressionTypeTestGenerated extends AbstractExpressionTypeTest {
doTest(fileName);
}
@TestMetadata("MethodName.kt")
public void testMethodName() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/codeInsight/expressionType/MethodName.kt");
doTest(fileName);
}
@TestMetadata("MethodReference.kt")
public void testMethodReference() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/codeInsight/expressionType/MethodReference.kt");