More simple and correct overload to highlight detection
This commit is contained in:
+6
-10
@@ -42,6 +42,7 @@ import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
|||||||
import org.jetbrains.kotlin.resolve.bindingContextUtil.getDataFlowInfo
|
import org.jetbrains.kotlin.resolve.bindingContextUtil.getDataFlowInfo
|
||||||
import org.jetbrains.kotlin.resolve.calls.CallResolver
|
import org.jetbrains.kotlin.resolve.calls.CallResolver
|
||||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getCall
|
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.checkers.CallChecker
|
||||||
import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext
|
import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext
|
||||||
import org.jetbrains.kotlin.resolve.calls.context.CheckArgumentTypesMode
|
import org.jetbrains.kotlin.resolve.calls.context.CheckArgumentTypesMode
|
||||||
@@ -198,7 +199,7 @@ class KotlinFunctionParameterInfoHandler : ParameterInfoHandlerWithTabActionSupp
|
|||||||
}.toString()
|
}.toString()
|
||||||
|
|
||||||
|
|
||||||
val color = if (isResolvedToDescriptor(argumentList, itemToShow, bindingContext))
|
val color = if (isResolvedToDescriptor(call, itemToShow, bindingContext))
|
||||||
GREEN_BACKGROUND
|
GREEN_BACKGROUND
|
||||||
else
|
else
|
||||||
context.defaultParameterColor
|
context.defaultParameterColor
|
||||||
@@ -221,7 +222,7 @@ class KotlinFunctionParameterInfoHandler : ParameterInfoHandlerWithTabActionSupp
|
|||||||
}
|
}
|
||||||
append(parameter.name)
|
append(parameter.name)
|
||||||
append(": ")
|
append(": ")
|
||||||
append(DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(getActualParameterType(parameter)))
|
append(DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(parameterTypeToRender(parameter)))
|
||||||
if (parameter.hasDefaultValue()) {
|
if (parameter.hasDefaultValue()) {
|
||||||
val parameterDeclaration = DescriptorToSourceUtils.descriptorToDeclaration(parameter)
|
val parameterDeclaration = DescriptorToSourceUtils.descriptorToDeclaration(parameter)
|
||||||
append(" = ")
|
append(" = ")
|
||||||
@@ -253,7 +254,7 @@ class KotlinFunctionParameterInfoHandler : ParameterInfoHandlerWithTabActionSupp
|
|||||||
return "..."
|
return "..."
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getActualParameterType(descriptor: ValueParameterDescriptor): JetType {
|
private fun parameterTypeToRender(descriptor: ValueParameterDescriptor): JetType {
|
||||||
var type = descriptor.varargElementType ?: descriptor.type
|
var type = descriptor.varargElementType ?: descriptor.type
|
||||||
if (type.containsError()) {
|
if (type.containsError()) {
|
||||||
val original = descriptor.original
|
val original = descriptor.original
|
||||||
@@ -263,19 +264,14 @@ class KotlinFunctionParameterInfoHandler : ParameterInfoHandlerWithTabActionSupp
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun isResolvedToDescriptor(
|
private fun isResolvedToDescriptor(
|
||||||
argumentList: JetValueArgumentList,
|
call: Call,
|
||||||
functionDescriptor: FunctionDescriptor,
|
functionDescriptor: FunctionDescriptor,
|
||||||
bindingContext: BindingContext
|
bindingContext: BindingContext
|
||||||
): Boolean {
|
): Boolean {
|
||||||
val callNameExpression = getCallNameExpression(argumentList) ?: return false
|
val target = call.getResolvedCall(bindingContext)?.resultingDescriptor as? FunctionDescriptor
|
||||||
val target = bindingContext[BindingContext.REFERENCE_TARGET, callNameExpression] as? FunctionDescriptor
|
|
||||||
return target != null && descriptorsEqual(target, functionDescriptor)
|
return target != null && descriptorsEqual(target, functionDescriptor)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getCallNameExpression(argumentList: JetValueArgumentList): JetSimpleNameExpression? {
|
|
||||||
return (argumentList.parent as? JetCallElement)?.getCallNameExpression()
|
|
||||||
}
|
|
||||||
|
|
||||||
private data class SignatureInfo(
|
private data class SignatureInfo(
|
||||||
val substitutedDescriptor: FunctionDescriptor,
|
val substitutedDescriptor: FunctionDescriptor,
|
||||||
val argumentToParameter: (ValueArgument) -> ValueParameterDescriptor?,
|
val argumentToParameter: (ValueArgument) -> ValueParameterDescriptor?,
|
||||||
|
|||||||
@@ -4,5 +4,5 @@ fun x(name: String, next: (name: String) -> String): String {
|
|||||||
|
|
||||||
//TODO: use parameter names from functional type
|
//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
|
//TODO: use parameter names from functional type
|
||||||
/*
|
/*
|
||||||
Text: (<highlight>name: String</highlight>, value: Int), Disabled: false, Strikeout: false, Green: false
|
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
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user