diff --git a/idea/src/org/jetbrains/kotlin/idea/parameterInfo/ArgumentNameHints.kt b/idea/src/org/jetbrains/kotlin/idea/parameterInfo/ArgumentNameHints.kt index 2314a483352..8a72652a958 100644 --- a/idea/src/org/jetbrains/kotlin/idea/parameterInfo/ArgumentNameHints.kt +++ b/idea/src/org/jetbrains/kotlin/idea/parameterInfo/ArgumentNameHints.kt @@ -53,7 +53,8 @@ private fun getArgumentNameHintsForCallCandidate( return resolvedCall.valueArguments.mapNotNull { (valueParam: ValueParameterDescriptor, resolvedArg) -> if (resultingDescriptor is FunctionInvokeDescriptor && - valueParam.type.extractParameterNameFromFunctionTypeArgument() == null) { + valueParam.type.extractParameterNameFromFunctionTypeArgument() == null + ) { return@mapNotNull null } @@ -73,7 +74,7 @@ private fun getArgumentNameHintsForCallCandidate( } } -private fun KtExpression.isUnclearExpression() = when(this) { +private fun KtExpression.isUnclearExpression() = when (this) { is KtConstantExpression, is KtThisExpression, is KtBinaryExpression, is KtStringTemplateExpression -> true is KtPrefixExpression -> baseExpression is KtConstantExpression && (operationToken == KtTokens.PLUS || operationToken == KtTokens.MINUS) else -> false diff --git a/idea/src/org/jetbrains/kotlin/idea/parameterInfo/KotlinFunctionParameterInfoHandler.kt b/idea/src/org/jetbrains/kotlin/idea/parameterInfo/KotlinFunctionParameterInfoHandler.kt index 2276540fc3a..cbe81e7122b 100644 --- a/idea/src/org/jetbrains/kotlin/idea/parameterInfo/KotlinFunctionParameterInfoHandler.kt +++ b/idea/src/org/jetbrains/kotlin/idea/parameterInfo/KotlinFunctionParameterInfoHandler.kt @@ -57,7 +57,9 @@ import java.awt.Color import java.util.* import kotlin.reflect.KClass -class KotlinFunctionParameterInfoHandler : KotlinParameterInfoWithCallHandlerBase(KtValueArgumentList::class, KtValueArgument::class) { +class KotlinFunctionParameterInfoHandler : + KotlinParameterInfoWithCallHandlerBase(KtValueArgumentList::class, KtValueArgument::class) { + override fun getActualParameters(arguments: KtValueArgumentList) = arguments.arguments.toTypedArray() override fun getActualParametersRBraceType() = KtTokens.RPAR @@ -67,6 +69,7 @@ class KotlinFunctionParameterInfoHandler : KotlinParameterInfoWithCallHandlerBas class KotlinLambdaParameterInfoHandler : KotlinParameterInfoWithCallHandlerBase(KtLambdaArgument::class, KtLambdaArgument::class) { + override fun getActualParameters(lambdaArgument: KtLambdaArgument) = arrayOf(lambdaArgument) override fun getActualParametersRBraceType() = KtTokens.RBRACE @@ -79,17 +82,20 @@ class KotlinLambdaParameterInfoHandler : } } -class KotlinArrayAccessParameterInfoHandler : KotlinParameterInfoWithCallHandlerBase(KtContainerNode::class, KtExpression::class) { +class KotlinArrayAccessParameterInfoHandler : + KotlinParameterInfoWithCallHandlerBase(KtContainerNode::class, KtExpression::class) { + override fun getArgumentListAllowedParentClasses() = setOf(KtArrayAccessExpression::class.java) - override fun getActualParameters(containerNode: KtContainerNode): Array = containerNode.allChildren.filterIsInstance().toList().toTypedArray() + override fun getActualParameters(containerNode: KtContainerNode): Array = + containerNode.allChildren.filterIsInstance().toList().toTypedArray() override fun getActualParametersRBraceType() = KtTokens.RBRACKET } abstract class KotlinParameterInfoWithCallHandlerBase( - private val argumentListClass: KClass, - private val argumentClass: KClass + private val argumentListClass: KClass, + private val argumentClass: KClass ) : ParameterInfoHandlerWithTabActionSupport { companion object { @@ -136,14 +142,16 @@ abstract class KotlinParameterInfoWithCallHandlerBase() override fun getParametersForDocumentation(item: FunctionDescriptor, context: ParameterInfoContext) = emptyArray() @@ -311,8 +320,7 @@ abstract class KotlinParameterInfoWithCallHandlerBase ValueParameterDescriptor?, - val highlightParameterIndex: Int?, - val isGrey: Boolean + val substitutedDescriptor: FunctionDescriptor, + val argumentToParameter: (ValueArgument) -> ValueParameterDescriptor?, + val highlightParameterIndex: Int?, + val isGrey: Boolean ) private fun matchCallWithSignature( - call: Call, - overload: FunctionDescriptor, - currentArgumentIndex: Int, - bindingContext: BindingContext, - resolutionFacade: ResolutionFacade + call: Call, + overload: FunctionDescriptor, + currentArgumentIndex: Int, + bindingContext: BindingContext, + resolutionFacade: ResolutionFacade ): SignatureInfo? { if (currentArgumentIndex == 0 && call.valueArguments.isEmpty() && overload.valueParameters.isEmpty()) { return SignatureInfo(overload, { null }, null, isGrey = false) @@ -370,8 +378,7 @@ abstract class KotlinParameterInfoWithCallHandlerBase currentArgumentIndex) { currentArgument = arguments[currentArgumentIndex] callToUse = call - } - else { + } else { // add dummy current argument if we don't have one currentArgument = object : ValueArgument { override fun getArgumentExpression(): KtExpression? = null @@ -383,9 +390,9 @@ abstract class KotlinParameterInfoWithCallHandlerBase() @@ -398,8 +405,8 @@ abstract class KotlinParameterInfoWithCallHandlerBase resolvedCall.getArgumentMapping(argument).isError() && - !argument.hasError(bindingContext) /* ignore arguments that have error type */ + !argument.hasError(bindingContext) /* ignore arguments that have error type */ } return SignatureInfo(resultingDescriptor, ::argumentToParameter, highlightParameterIndex, isGrey) } - private fun ValueArgument.hasError(bindingContext: BindingContext) - = getArgumentExpression()?.let { bindingContext.getType(it) }?.isError ?: true + private fun ValueArgument.hasError(bindingContext: BindingContext) = + getArgumentExpression()?.let { bindingContext.getType(it) }?.isError ?: true // we should not compare descriptors directly because partial resolve is involved private fun descriptorsEqual(descriptor1: FunctionDescriptor, descriptor2: FunctionDescriptor): Boolean { diff --git a/idea/src/org/jetbrains/kotlin/idea/parameterInfo/KotlinTypeArgumentInfoHandler.kt b/idea/src/org/jetbrains/kotlin/idea/parameterInfo/KotlinTypeArgumentInfoHandler.kt index f9041d25efd..59459bcecdb 100644 --- a/idea/src/org/jetbrains/kotlin/idea/parameterInfo/KotlinTypeArgumentInfoHandler.kt +++ b/idea/src/org/jetbrains/kotlin/idea/parameterInfo/KotlinTypeArgumentInfoHandler.kt @@ -60,14 +60,16 @@ class KotlinFunctionTypeArgumentInfoHandler : KotlinTypeArgumentInfoHandlerBase< val call = callElement.getCall(bindingContext) ?: return null val candidates = call.resolveCandidates(bindingContext, callElement.getResolutionFacade()) return candidates - .map { it.resultingDescriptor } - .distinctBy { buildPresentation(it.typeParameters, -1).first } + .map { it.resultingDescriptor } + .distinctBy { buildPresentation(it.typeParameters, -1).first } } override fun getArgumentListAllowedParentClasses() = setOf(KtCallElement::class.java) } -abstract class KotlinTypeArgumentInfoHandlerBase : ParameterInfoHandlerWithTabActionSupport { +abstract class KotlinTypeArgumentInfoHandlerBase : + ParameterInfoHandlerWithTabActionSupport { + protected abstract fun fetchTypeParameters(descriptor: TParameterOwner): List protected abstract fun findParameterOwners(argumentList: KtTypeArgumentList): Collection? @@ -78,7 +80,8 @@ abstract class KotlinTypeArgumentInfoHandlerBase, - currentIndex: Int + parameters: List, + currentIndex: Int ): Triple { var currentParameterStart = -1 var currentParameterEnd = -1 @@ -172,7 +177,8 @@ abstract class KotlinTypeArgumentInfoHandlerBase {} + Variance.INVARIANT -> { + } Variance.IN_VARIANCE -> append("in ") Variance.OUT_VARIANCE -> append("out ") } @@ -185,8 +191,7 @@ abstract class KotlinTypeArgumentInfoHandlerBase 1) { + } else if (upperBounds.size > 1) { needWhere = true } @@ -205,7 +210,9 @@ abstract class KotlinTypeArgumentInfoHandlerBase