Don't consider function names as candidates for "Show expression type" (KT-14384)
This commit is contained in:
@@ -21,12 +21,14 @@ import com.intellij.psi.PsiElement
|
|||||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.findModuleDescriptor
|
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.*
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.getQualifiedExpressionForSelector
|
import org.jetbrains.kotlin.psi.psiUtil.getQualifiedExpressionForSelector
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf
|
import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf
|
||||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||||
import org.jetbrains.kotlin.renderer.RenderingFormat
|
import org.jetbrains.kotlin.renderer.RenderingFormat
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext
|
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.callUtil.getType
|
||||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory
|
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory
|
||||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||||
@@ -51,7 +53,7 @@ class KotlinExpressionTypeProvider : ExpressionTypeProvider<KtExpression>() {
|
|||||||
is KtIfExpression, is KtWhenExpression, is KtTryExpression -> shouldShowStatementType()
|
is KtIfExpression, is KtWhenExpression, is KtTryExpression -> shouldShowStatementType()
|
||||||
is KtLoopExpression -> false
|
is KtLoopExpression -> false
|
||||||
is KtConstantExpression -> false
|
is KtConstantExpression -> false
|
||||||
else -> getQualifiedExpressionForSelector() == null && parent !is KtCallableReferenceExpression
|
else -> getQualifiedExpressionForSelector() == null && parent !is KtCallableReferenceExpression && !isFunctionCallee()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun KtExpression.shouldShowStatementType(): Boolean {
|
private fun KtExpression.shouldShowStatementType(): Boolean {
|
||||||
@@ -62,6 +64,12 @@ class KotlinExpressionTypeProvider : ExpressionTypeProvider<KtExpression>() {
|
|||||||
return false
|
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 {
|
override fun getInformationHint(element: KtExpression): String {
|
||||||
val bindingContext = element.analyze(BodyResolveMode.PARTIAL)
|
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);
|
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")
|
@TestMetadata("MethodReference.kt")
|
||||||
public void testMethodReference() throws Exception {
|
public void testMethodReference() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/codeInsight/expressionType/MethodReference.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/codeInsight/expressionType/MethodReference.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user