[kotlin] k2: inline: retrieve default values from overridden symbols

^KTIJ-30300 fixed

GitOrigin-RevId: 26d97690371335404f6ece1c1f37c1c1a9cfe242
This commit is contained in:
Anna Kozlova
2024-06-14 21:43:23 +00:00
committed by intellij-monorepo-bot
parent ce97fcef18
commit 331c0fc111
7 changed files with 47 additions and 3 deletions
@@ -2115,6 +2115,11 @@ public abstract class InlineTestGenerated extends AbstractInlineTest {
runTest("testData/refactoring/inline/namedFunction/defaultParameterDiffers1.kt");
}
@TestMetadata("defaultParameterFromSuper.kt")
public void testDefaultParameterFromSuper() throws Exception {
runTest("testData/refactoring/inline/namedFunction/defaultParameterFromSuper.kt");
}
@TestMetadata("defaultParameterImplicitlyUsed.kt")
public void testDefaultParameterImplicitlyUsed() throws Exception {
runTest("testData/refactoring/inline/namedFunction/defaultParameterImplicitlyUsed.kt");
@@ -17,4 +17,4 @@ fun foo(c: C) {
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
/* IGNORE_K2 */
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -17,4 +17,4 @@ fun foo(c: C) {
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
/* IGNORE_K2 */
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -0,0 +1,13 @@
interface I {
fun oldFun(p1: String, p2: Int = 0, p3: Int = 1) = newFun(p1, p2, p3)
fun newFun(p1: String, p2: Int = 1, p3: Int = 1)
}
abstract class C : I {
override fun newFun(p1: String, p2: Int, p3: Int) { }
}
fun foo(c: C) {
c.old<caret>Fun("", 0)
}
@@ -0,0 +1,12 @@
interface I {
fun newFun(p1: String, p2: Int = 1, p3: Int = 1)
}
abstract class C : I {
override fun newFun(p1: String, p2: Int, p3: Int) {}
}
fun foo(c: C) {
c.newFun("", 0)
}
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.analysis.api.resolution.singleFunctionCallOrNull
import org.jetbrains.kotlin.analysis.api.resolution.successfulFunctionCallOrNull
import org.jetbrains.kotlin.analysis.api.resolution.symbol
import org.jetbrains.kotlin.analysis.api.symbols.KaValueParameterSymbol
import org.jetbrains.kotlin.analysis.api.symbols.KtFunctionLikeSymbol
import org.jetbrains.kotlin.idea.base.analysis.api.utils.defaultValue
import org.jetbrains.kotlin.idea.base.codeInsight.ShortenReferencesFacility
import org.jetbrains.kotlin.idea.codeinsight.utils.RemoveExplicitTypeArgumentsUtils
@@ -144,9 +145,17 @@ object InlinePostProcessor: AbstractInlinePostProcessor() {
val functionCall = callExpression.resolveCallOld()?.singleFunctionCallOrNull() ?: return@forEachDescendantOfType
val arguments = functionCall.argumentMapping.entries.toList()
val valueParameters = functionCall.partiallyAppliedSymbol.symbol.valueParameters
val callableSymbol = functionCall.partiallyAppliedSymbol.symbol
val valueParameters = callableSymbol.valueParameters
var idx = arguments.size
for ((argument, param) in arguments.asReversed()) {
idx--
val defaultValue = param.symbol.defaultValue
?: callableSymbol.getAllOverriddenSymbols()
.mapNotNull {
val params = (it as? KtFunctionLikeSymbol)?.valueParameters
params?.getOrNull(idx)?.defaultValue
}.firstOrNull()
fun substituteDefaultValueWithPassedArguments(): @NlsSafe String? {
val key = Key<KtExpression>("SUBSTITUTION")
@@ -824,6 +824,11 @@ public abstract class KotlinFirInlineTestGenerated extends AbstractKotlinFirInli
runTest("../../idea/tests/testData/refactoring/inline/namedFunction/defaultParameterDiffers1.kt");
}
@TestMetadata("defaultParameterFromSuper.kt")
public void testDefaultParameterFromSuper() throws Exception {
runTest("../../idea/tests/testData/refactoring/inline/namedFunction/defaultParameterFromSuper.kt");
}
@TestMetadata("defaultParameterImplicitlyUsed.kt")
public void testDefaultParameterImplicitlyUsed() throws Exception {
runTest("../../idea/tests/testData/refactoring/inline/namedFunction/defaultParameterImplicitlyUsed.kt");