Resolve types of arguments

This commit is contained in:
Vitaliy.Bibaev
2017-11-17 15:03:00 +03:00
committed by Yan Zhulanow
parent 86ec8eab6e
commit e61fbb16c5
@@ -11,10 +11,14 @@ import com.intellij.debugger.streams.wrapper.StreamChain
import com.intellij.debugger.streams.wrapper.impl.* import com.intellij.debugger.streams.wrapper.impl.*
import com.intellij.openapi.util.TextRange import com.intellij.openapi.util.TextRange
import com.intellij.psi.PsiElement 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.KtCallExpression
import org.jetbrains.kotlin.psi.KtDotQualifiedExpression import org.jetbrains.kotlin.psi.KtDotQualifiedExpression
import org.jetbrains.kotlin.psi.KtValueArgument 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 * @author Vitaliy.Bibaev
@@ -31,7 +35,7 @@ class KotlinChainTransformerImpl : ChainTransformer<KtCallExpression> {
val intermediateCalls = mutableListOf<IntermediateStreamCall>() val intermediateCalls = mutableListOf<IntermediateStreamCall>()
for (call in callChain.subList(0, callChain.size - 1)) { for (call in callChain.subList(0, callChain.size - 1)) {
intermediateCalls += IntermediateStreamCallImpl(call.callName(), intermediateCalls += IntermediateStreamCallImpl(call.callName(),
call.valueArguments.map { it.toCallArgument() }, call.valueArguments.map { createCallArgument(call, it) },
KotlinTypes.nullable { KotlinTypes.ANY }, KotlinTypes.nullable { KotlinTypes.ANY }, KotlinTypes.nullable { KotlinTypes.ANY }, KotlinTypes.nullable { KotlinTypes.ANY },
call.textRange) call.textRange)
} }
@@ -39,15 +43,24 @@ class KotlinChainTransformerImpl : ChainTransformer<KtCallExpression> {
val terminationsPsiCall = callChain.last() val terminationsPsiCall = callChain.last()
// TODO: infer true types // TODO: infer true types
val terminationCall = TerminatorStreamCallImpl(terminationsPsiCall.callName(), val terminationCall = TerminatorStreamCallImpl(terminationsPsiCall.callName(),
terminationsPsiCall.valueArguments.map { it.toCallArgument() }, terminationsPsiCall.valueArguments.map { createCallArgument(terminationsPsiCall, it) },
KotlinTypes.nullable { KotlinTypes.ANY }, KotlinTypes.nullable { KotlinTypes.ANY }, KotlinTypes.nullable { KotlinTypes.ANY }, KotlinTypes.nullable { KotlinTypes.ANY },
terminationsPsiCall.textRange) terminationsPsiCall.textRange)
return StreamChainImpl(qualifier, intermediateCalls, terminationCall, context) return StreamChainImpl(qualifier, intermediateCalls, terminationCall, context)
} }
private fun KtValueArgument.toCallArgument(): CallArgument { private fun createCallArgument(callExpression: KtCallExpression, arg: KtValueArgument): CallArgument {
val argExpression = getArgumentExpression()!! fun KtValueArgument.toCallArgument(): CallArgument {
return CallArgumentImpl(argExpression.resolveType().getJetTypeFqName(true), argExpression.text) 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)
} }