From e61fbb16c5983f72f01f2fee6f9bb70011a066ba Mon Sep 17 00:00:00 2001 From: "Vitaliy.Bibaev" Date: Fri, 17 Nov 2017 15:03:00 +0300 Subject: [PATCH] Resolve types of arguments --- .../psi/impl/KotlinChainTransformerImpl.kt | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/psi/impl/KotlinChainTransformerImpl.kt b/idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/psi/impl/KotlinChainTransformerImpl.kt index 0f3d4e84c83..f07523dbc85 100644 --- a/idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/psi/impl/KotlinChainTransformerImpl.kt +++ b/idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/psi/impl/KotlinChainTransformerImpl.kt @@ -11,10 +11,14 @@ import com.intellij.debugger.streams.wrapper.StreamChain import com.intellij.debugger.streams.wrapper.impl.* import com.intellij.openapi.util.TextRange import com.intellij.psi.PsiElement -import org.jetbrains.kotlin.js.descriptorUtils.getJetTypeFqName +import org.jetbrains.kotlin.idea.caches.resolve.analyzeFully import org.jetbrains.kotlin.psi.KtCallExpression import org.jetbrains.kotlin.psi.KtDotQualifiedExpression import org.jetbrains.kotlin.psi.KtValueArgument +import org.jetbrains.kotlin.renderer.DescriptorRenderer +import org.jetbrains.kotlin.resolve.calls.callUtil.getParameterForArgument +import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall +import org.jetbrains.kotlin.types.KotlinType /** * @author Vitaliy.Bibaev @@ -31,7 +35,7 @@ class KotlinChainTransformerImpl : ChainTransformer { val intermediateCalls = mutableListOf() for (call in callChain.subList(0, callChain.size - 1)) { intermediateCalls += IntermediateStreamCallImpl(call.callName(), - call.valueArguments.map { it.toCallArgument() }, + call.valueArguments.map { createCallArgument(call, it) }, KotlinTypes.nullable { KotlinTypes.ANY }, KotlinTypes.nullable { KotlinTypes.ANY }, call.textRange) } @@ -39,15 +43,24 @@ class KotlinChainTransformerImpl : ChainTransformer { val terminationsPsiCall = callChain.last() // TODO: infer true types val terminationCall = TerminatorStreamCallImpl(terminationsPsiCall.callName(), - terminationsPsiCall.valueArguments.map { it.toCallArgument() }, + terminationsPsiCall.valueArguments.map { createCallArgument(terminationsPsiCall, it) }, KotlinTypes.nullable { KotlinTypes.ANY }, KotlinTypes.nullable { KotlinTypes.ANY }, terminationsPsiCall.textRange) return StreamChainImpl(qualifier, intermediateCalls, terminationCall, context) } - private fun KtValueArgument.toCallArgument(): CallArgument { - val argExpression = getArgumentExpression()!! - return CallArgumentImpl(argExpression.resolveType().getJetTypeFqName(true), argExpression.text) + private fun createCallArgument(callExpression: KtCallExpression, arg: KtValueArgument): CallArgument { + fun KtValueArgument.toCallArgument(): CallArgument { + val argExpression = getArgumentExpression()!! + return CallArgumentImpl(renderType(argExpression.resolveType()), this.text) + } + + val bindingContext = callExpression.analyzeFully() + val resolvedCall = callExpression.getResolvedCall(bindingContext) ?: return arg.toCallArgument() + val parameter = resolvedCall.getParameterForArgument(arg) ?: return arg.toCallArgument() + return CallArgumentImpl(renderType(parameter.type), arg.text) } + + private fun renderType(type: KotlinType): String = DescriptorRenderer.FQ_NAMES_IN_TYPES.renderType(type) }