FIR IDE: Change key of argumentMapping in KtCall to KtExpression.
This commit is contained in:
committed by
Ilya Kirillov
parent
ae17cd639b
commit
6b57621863
@@ -9,14 +9,14 @@ import org.jetbrains.kotlin.idea.frontend.api.diagnostics.KtDiagnostic
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtFunctionLikeSymbol
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtValueParameterSymbol
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtVariableLikeSymbol
|
||||
import org.jetbrains.kotlin.psi.KtValueArgument
|
||||
import org.jetbrains.kotlin.psi.KtExpression
|
||||
|
||||
/**
|
||||
* Represents direct or indirect (via invoke) function call from Kotlin code
|
||||
*/
|
||||
public sealed class KtCall {
|
||||
public abstract val isErrorCall: Boolean
|
||||
public abstract val argumentMapping: LinkedHashMap<KtValueArgument, KtValueParameterSymbol>
|
||||
public abstract val argumentMapping: LinkedHashMap<KtExpression, KtValueParameterSymbol>
|
||||
public abstract val targetFunction: KtCallTarget
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ public sealed class KtCall {
|
||||
*/
|
||||
public class KtFunctionalTypeVariableCall(
|
||||
public val target: KtVariableLikeSymbol,
|
||||
override val argumentMapping: LinkedHashMap<KtValueArgument, KtValueParameterSymbol>,
|
||||
override val argumentMapping: LinkedHashMap<KtExpression, KtValueParameterSymbol>,
|
||||
override val targetFunction: KtCallTarget
|
||||
) : KtCall() {
|
||||
override val isErrorCall: Boolean get() = false
|
||||
@@ -54,7 +54,7 @@ public sealed class KtDeclaredFunctionCall : KtCall() {
|
||||
*/
|
||||
public class KtVariableWithInvokeFunctionCall(
|
||||
public val target: KtVariableLikeSymbol,
|
||||
override val argumentMapping: LinkedHashMap<KtValueArgument, KtValueParameterSymbol>,
|
||||
override val argumentMapping: LinkedHashMap<KtExpression, KtValueParameterSymbol>,
|
||||
override val targetFunction: KtCallTarget
|
||||
) : KtDeclaredFunctionCall()
|
||||
|
||||
@@ -64,7 +64,7 @@ public class KtVariableWithInvokeFunctionCall(
|
||||
* x.toString() // function call
|
||||
*/
|
||||
public class KtFunctionCall(
|
||||
override val argumentMapping: LinkedHashMap<KtValueArgument, KtValueParameterSymbol>,
|
||||
override val argumentMapping: LinkedHashMap<KtExpression, KtValueParameterSymbol>,
|
||||
override val targetFunction: KtCallTarget
|
||||
) : KtDeclaredFunctionCall()
|
||||
|
||||
@@ -75,7 +75,7 @@ public class KtFunctionCall(
|
||||
* annotation class Ann
|
||||
*/
|
||||
public class KtAnnotationCall(
|
||||
override val argumentMapping: LinkedHashMap<KtValueArgument, KtValueParameterSymbol>,
|
||||
override val argumentMapping: LinkedHashMap<KtExpression, KtValueParameterSymbol>,
|
||||
override val targetFunction: KtCallTarget
|
||||
) : KtDeclaredFunctionCall()
|
||||
// TODO: Add other properties, e.g., useSiteTarget
|
||||
@@ -89,7 +89,7 @@ public class KtAnnotationCall(
|
||||
* }
|
||||
*/
|
||||
public class KtDelegatedConstructorCall(
|
||||
override val argumentMapping: LinkedHashMap<KtValueArgument, KtValueParameterSymbol>,
|
||||
override val argumentMapping: LinkedHashMap<KtExpression, KtValueParameterSymbol>,
|
||||
override val targetFunction: KtCallTarget,
|
||||
public val kind: KtDelegatedConstructorCallKind
|
||||
) : KtDeclaredFunctionCall()
|
||||
|
||||
+10
-10
@@ -176,28 +176,28 @@ internal class KtFirCallResolver(
|
||||
}
|
||||
}
|
||||
|
||||
private fun FirCall.createArgumentMapping(): LinkedHashMap<KtValueArgument, KtValueParameterSymbol> {
|
||||
val ktArgumentMapping = LinkedHashMap<KtValueArgument, KtValueParameterSymbol>()
|
||||
private fun FirCall.createArgumentMapping(): LinkedHashMap<KtExpression, KtValueParameterSymbol> {
|
||||
val ktArgumentMapping = LinkedHashMap<KtExpression, KtValueParameterSymbol>()
|
||||
argumentMapping?.let {
|
||||
fun FirExpression.findKtValueArgument(): KtValueArgument? {
|
||||
fun FirExpression.findKtExpression(): KtExpression? {
|
||||
// For spread and named arguments, the source is the KtValueArgument.
|
||||
// For other arguments, the source is the KtExpression itself and its parent should be the KtValueArgument.
|
||||
val psi = when (this) {
|
||||
is FirNamedArgumentExpression, is FirSpreadArgumentExpression -> realPsi
|
||||
else -> realPsi?.parent
|
||||
// For other arguments (including array indices), the source is the KtExpression.
|
||||
return when (this) {
|
||||
is FirNamedArgumentExpression, is FirSpreadArgumentExpression ->
|
||||
realPsi.safeAs<KtValueArgument>()?.getArgumentExpression()
|
||||
else -> realPsi as? KtExpression
|
||||
}
|
||||
return psi as? KtValueArgument
|
||||
}
|
||||
|
||||
for ((firExpression, firValueParameter) in it.entries) {
|
||||
val parameterSymbol = firValueParameter.buildSymbol(firSymbolBuilder) as KtValueParameterSymbol
|
||||
if (firExpression is FirVarargArgumentsExpression) {
|
||||
for (varargArgument in firExpression.arguments) {
|
||||
val valueArgument = varargArgument.findKtValueArgument() ?: continue
|
||||
val valueArgument = varargArgument.findKtExpression() ?: continue
|
||||
ktArgumentMapping[valueArgument] = parameterSymbol
|
||||
}
|
||||
} else {
|
||||
val valueArgument = firExpression.findKtValueArgument() ?: continue
|
||||
val valueArgument = firExpression.findKtExpression() ?: continue
|
||||
ktArgumentMapping[valueArgument] = parameterSymbol
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+1
-1
@@ -1,3 +1,3 @@
|
||||
KtFunctionCall:
|
||||
argumentMapping = { }
|
||||
argumentMapping = { 2 -> (other: B) }
|
||||
targetFunction = /to(<receiver>: A, other: B): A
|
||||
+1
-1
@@ -72,7 +72,7 @@ private fun KtCall.stringRepresentation(): String {
|
||||
is KtErrorCallTarget -> "ERR<${this.diagnostic.defaultMessage}, [${candidates.joinToString { it.stringValue() }}]>"
|
||||
is Boolean -> toString()
|
||||
is Map<*, *> -> entries.joinToString(prefix = "{ ", postfix = " }") { (k, v) -> "${k?.stringValue()} -> (${v?.stringValue()})" }
|
||||
is KtValueArgument -> this.text
|
||||
is KtExpression -> this.text
|
||||
is KtDelegatedConstructorCallKind -> toString()
|
||||
else -> error("unexpected parameter type ${this::class}")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user