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