More simple and correct overload to highlight detection

This commit is contained in:
Valentin Kipyatkov
2015-10-05 21:33:26 +03:00
parent 9ba2242ea9
commit 778e2f6f0b
4 changed files with 9 additions and 13 deletions
@@ -42,6 +42,7 @@ import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
import org.jetbrains.kotlin.resolve.bindingContextUtil.getDataFlowInfo
import org.jetbrains.kotlin.resolve.calls.CallResolver
import org.jetbrains.kotlin.resolve.calls.callUtil.getCall
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker
import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext
import org.jetbrains.kotlin.resolve.calls.context.CheckArgumentTypesMode
@@ -198,7 +199,7 @@ class KotlinFunctionParameterInfoHandler : ParameterInfoHandlerWithTabActionSupp
}.toString()
val color = if (isResolvedToDescriptor(argumentList, itemToShow, bindingContext))
val color = if (isResolvedToDescriptor(call, itemToShow, bindingContext))
GREEN_BACKGROUND
else
context.defaultParameterColor
@@ -221,7 +222,7 @@ class KotlinFunctionParameterInfoHandler : ParameterInfoHandlerWithTabActionSupp
}
append(parameter.name)
append(": ")
append(DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(getActualParameterType(parameter)))
append(DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(parameterTypeToRender(parameter)))
if (parameter.hasDefaultValue()) {
val parameterDeclaration = DescriptorToSourceUtils.descriptorToDeclaration(parameter)
append(" = ")
@@ -253,7 +254,7 @@ class KotlinFunctionParameterInfoHandler : ParameterInfoHandlerWithTabActionSupp
return "..."
}
private fun getActualParameterType(descriptor: ValueParameterDescriptor): JetType {
private fun parameterTypeToRender(descriptor: ValueParameterDescriptor): JetType {
var type = descriptor.varargElementType ?: descriptor.type
if (type.containsError()) {
val original = descriptor.original
@@ -263,19 +264,14 @@ class KotlinFunctionParameterInfoHandler : ParameterInfoHandlerWithTabActionSupp
}
private fun isResolvedToDescriptor(
argumentList: JetValueArgumentList,
call: Call,
functionDescriptor: FunctionDescriptor,
bindingContext: BindingContext
): Boolean {
val callNameExpression = getCallNameExpression(argumentList) ?: return false
val target = bindingContext[BindingContext.REFERENCE_TARGET, callNameExpression] as? FunctionDescriptor
val target = call.getResolvedCall(bindingContext)?.resultingDescriptor as? FunctionDescriptor
return target != null && descriptorsEqual(target, functionDescriptor)
}
private fun getCallNameExpression(argumentList: JetValueArgumentList): JetSimpleNameExpression? {
return (argumentList.parent as? JetCallElement)?.getCallNameExpression()
}
private data class SignatureInfo(
val substitutedDescriptor: FunctionDescriptor,
val argumentToParameter: (ValueArgument) -> ValueParameterDescriptor?,
@@ -4,5 +4,5 @@ fun x(name: String, next: (name: String) -> String): String {
//TODO: use parameter names from functional type
/*
Text: (<highlight>p1: String</highlight>), Disabled: false, Strikeout: false, Green: false
Text: (<highlight>p1: String</highlight>), Disabled: false, Strikeout: false, Green: true
*/
@@ -8,5 +8,5 @@ fun call() {
//TODO: use parameter names from functional type
/*
Text: (<highlight>name: String</highlight>, value: Int), Disabled: false, Strikeout: false, Green: false
Text: (<highlight>p1: String</highlight>, p2: String), Disabled: false, Strikeout: false, Green: false
Text: (<highlight>p1: String</highlight>, p2: String), Disabled: false, Strikeout: false, Green: true
*/
@@ -11,5 +11,5 @@ fun main(args: Array<String>) {
}
/*
Text: (<highlight>i: Int</highlight>), Disabled: false, Strikeout: false, Green: false
Text: (<highlight>i: Int</highlight>), Disabled: false, Strikeout: false, Green: true
*/