[kotlin] k2: support ClassUsageReplacementStrategy in replaceWith

^KTIJ-29498 fixed

GitOrigin-RevId: 3165adf9fdf066807c3fcc73de4fa517d93b382e
This commit is contained in:
Anna Kozlova
2024-07-11 20:56:03 +00:00
committed by intellij-monorepo-bot
parent 4748ac2520
commit 60f1e8301e
99 changed files with 610 additions and 125 deletions
@@ -4,9 +4,11 @@ package org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith
import com.intellij.codeInsight.intention.HighPriorityAction
import com.intellij.codeInsight.intention.IntentionAction
import com.intellij.openapi.diagnostic.ControlFlowException
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.analysis.api.KaExperimentalApi
import org.jetbrains.kotlin.analysis.api.KaSession
import org.jetbrains.kotlin.analysis.api.annotations.*
import org.jetbrains.kotlin.analysis.api.base.KaConstantValue
@@ -19,9 +21,10 @@ import org.jetbrains.kotlin.idea.codeinsight.api.applicators.fixes.KotlinQuickFi
import org.jetbrains.kotlin.idea.codeinsight.api.classic.quickfixes.KotlinPsiOnlyQuickFixAction
import org.jetbrains.kotlin.idea.core.moveCaret
import org.jetbrains.kotlin.idea.k2.refactoring.inline.codeInliner.CallableUsageReplacementStrategy
import org.jetbrains.kotlin.idea.k2.refactoring.inline.codeInliner.ClassUsageReplacementStrategy
import org.jetbrains.kotlin.idea.k2.refactoring.inline.codeInliner.CodeToInlineBuilder
import org.jetbrains.kotlin.idea.k2.refactoring.inline.codeInliner.TypeAliasUsageReplacementStrategy
import org.jetbrains.kotlin.idea.quickfix.replaceWith.ReplaceWithData
import org.jetbrains.kotlin.idea.refactoring.inline.codeInliner.CodeToInline
import org.jetbrains.kotlin.idea.refactoring.inline.codeInliner.UsageReplacementStrategy
import org.jetbrains.kotlin.idea.refactoring.inline.codeInliner.buildCodeToInline
import org.jetbrains.kotlin.idea.references.mainReference
@@ -30,14 +33,17 @@ import org.jetbrains.kotlin.psi.KtArrayAccessExpression
import org.jetbrains.kotlin.psi.KtBinaryExpression
import org.jetbrains.kotlin.psi.KtCallExpression
import org.jetbrains.kotlin.psi.KtCallableDeclaration
import org.jetbrains.kotlin.psi.KtClassLikeDeclaration
import org.jetbrains.kotlin.psi.KtConstructorCalleeExpression
import org.jetbrains.kotlin.psi.KtDeclaration
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.psi.KtFunction
import org.jetbrains.kotlin.psi.KtNullableType
import org.jetbrains.kotlin.psi.KtPrimaryConstructor
import org.jetbrains.kotlin.psi.KtProperty
import org.jetbrains.kotlin.psi.KtPsiFactory
import org.jetbrains.kotlin.psi.KtReferenceExpression
import org.jetbrains.kotlin.psi.KtSimpleNameExpression
import org.jetbrains.kotlin.psi.KtTypeAlias
import org.jetbrains.kotlin.psi.KtTypeReference
import org.jetbrains.kotlin.psi.KtUserType
import org.jetbrains.kotlin.psi.KtValVarKeywordOwner
@@ -65,23 +71,30 @@ object DeprecationFixFactory {
}
context(KaSession)
@OptIn(KaExperimentalApi::class)
private fun createDeprecation(
kaSymbol: KaDeclarationSymbol,
psi: PsiElement
): List<IntentionAction> {
val deprecatedSymbol = kaSymbol.takeIf { it.deprecationStatus != null }
?: (kaSymbol.containingSymbol as? KaDeclarationSymbol)?.takeIf { it.deprecationStatus != null }
?: return emptyList()
val referenceExpression = when (val psiElement = psi) {
is KtArrayAccessExpression -> psiElement
is KtSimpleNameExpression -> psiElement
is KtTypeReference -> (psiElement.typeElement as? KtUserType)?.referenceExpression
is KtTypeReference -> {
val typeElement = psiElement.typeElement
(((typeElement as? KtNullableType)?.innerType ?: typeElement) as? KtUserType)?.referenceExpression
}
is KtConstructorCalleeExpression -> psiElement.constructorReferenceExpression
is KtBinaryExpression -> psiElement.operationReference
else -> null
} ?: return emptyList()
val expression = (referenceExpression.parent as? KtCallExpression)?.takeIf {
(kaSymbol as? KaNamedFunctionSymbol)?.isOperator == true && referenceExpression.mainReference.resolve() is KtValVarKeywordOwner
(deprecatedSymbol as? KaNamedFunctionSymbol)?.isOperator == true && referenceExpression.mainReference.resolve() is KtValVarKeywordOwner
} ?: referenceExpression
val replaceWithData =
fetchReplaceWithPattern(kaSymbol) ?: return emptyList()
val replaceWithData = fetchReplaceWithPattern(deprecatedSymbol) ?: return emptyList()
return listOf(DeprecatedSymbolUsageFix(expression, replaceWithData))
}
@@ -118,8 +131,7 @@ abstract class DeprecatedSymbolUsageFixBase(
"${javaClass.name} should not be created on EDT"
}
isAvailable = buildUsageReplacementStrategy(
element,
replaceWith
element, replaceWith
)?.let { it.createReplacer(element) != null } == true
}
@@ -142,28 +154,47 @@ abstract class DeprecatedSymbolUsageFixBase(
val target = element.mainReference.resolve()
when (target) {
is KtCallableDeclaration -> {
val context = (if (target is KtFunction) (target.bodyBlockExpression ?: target.bodyExpression
?: target.valueParameterList?.parameters?.lastOrNull()) else null)
?: (target as? KtProperty)?.getter ?: (target as? KtProperty)?.setter ?: (target as? KtProperty)?.initializer
?: target
is KtPrimaryConstructor, is KtClassLikeDeclaration -> {
val psiFactory = KtPsiFactory(element.project)
val expression =
psiFactory.createExpressionCodeFragment(replaceWith.pattern, context).getContentElement() ?: return null
val typeReference = try {
psiFactory.createType(replaceWith.pattern)
} catch (e: Exception) {
if (e is ControlFlowException) throw e
val replacement = createReplacement(target as KtDeclaration, element, replaceWith) ?: return null
return CallableUsageReplacementStrategy(replacement, inlineSetter = false)
}
val typeElement = typeReference.typeElement as? KtUserType ?: return null
return ClassUsageReplacementStrategy(typeElement, null, element.project)
}
is KtCallableDeclaration -> {
val replacement = createReplacement(target, element, replaceWith) ?: return null
val replacement = buildCodeToInline(
target, expression, false, null, CodeToInlineBuilder(
original = target
)
) ?: return null
return CallableUsageReplacementStrategy(replacement, inlineSetter = false)
}
is KtTypeAlias -> {
return TypeAliasUsageReplacementStrategy(target)
}
else -> return null
}
}
private fun createReplacement(
target: KtDeclaration,
element: KtReferenceExpression,
replaceWith: ReplaceWithData
): CodeToInline? {
val context = (if (target is KtFunction) (target.bodyBlockExpression ?: target.bodyExpression
?: target.valueParameterList?.parameters?.lastOrNull()) else null)
?: (target as? KtProperty)?.getter ?: (target as? KtProperty)?.setter ?: (target as? KtProperty)?.initializer
?: target
val psiFactory = KtPsiFactory(element.project)
val expression =
psiFactory.createExpressionCodeFragment(replaceWith.pattern, context).getContentElement() ?: return null
return buildCodeToInline(target, expression, false, null, CodeToInlineBuilder(original = target))
}
}
}
@@ -7047,6 +7047,235 @@ public abstract class HighLevelQuickFixTestGenerated extends AbstractHighLevelQu
}
}
@RunWith(JUnit3RunnerWithInners.class)
@TestMetadata("../../../idea/tests/testData/quickfix/deprecatedSymbolUsage/classUsages")
public static class ClassUsages extends AbstractHighLevelQuickFixTest {
@java.lang.Override
@org.jetbrains.annotations.NotNull
public final KotlinPluginMode getPluginMode() {
return KotlinPluginMode.K2;
}
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
@TestMetadata("annotation1.kt")
public void testAnnotation1() throws Exception {
runTest("../../../idea/tests/testData/quickfix/deprecatedSymbolUsage/classUsages/annotation1.kt");
}
@TestMetadata("annotation2.kt")
public void testAnnotation2() throws Exception {
runTest("../../../idea/tests/testData/quickfix/deprecatedSymbolUsage/classUsages/annotation2.kt");
}
@TestMetadata("annotation3.kt")
public void testAnnotation3() throws Exception {
runTest("../../../idea/tests/testData/quickfix/deprecatedSymbolUsage/classUsages/annotation3.kt");
}
@TestMetadata("annotation4.kt")
public void testAnnotation4() throws Exception {
runTest("../../../idea/tests/testData/quickfix/deprecatedSymbolUsage/classUsages/annotation4.kt");
}
@TestMetadata("annotationKeepNamedArgs.kt")
public void testAnnotationKeepNamedArgs() throws Exception {
runTest("../../../idea/tests/testData/quickfix/deprecatedSymbolUsage/classUsages/annotationKeepNamedArgs.kt");
}
@TestMetadata("annotationWithFileUseSiteTarget1.kt")
public void testAnnotationWithFileUseSiteTarget1() throws Exception {
runTest("../../../idea/tests/testData/quickfix/deprecatedSymbolUsage/classUsages/annotationWithFileUseSiteTarget1.kt");
}
@TestMetadata("annotationWithFileUseSiteTarget2.kt")
public void testAnnotationWithFileUseSiteTarget2() throws Exception {
runTest("../../../idea/tests/testData/quickfix/deprecatedSymbolUsage/classUsages/annotationWithFileUseSiteTarget2.kt");
}
@TestMetadata("annotationWithFileUseSiteTarget3.kt")
public void testAnnotationWithFileUseSiteTarget3() throws Exception {
runTest("../../../idea/tests/testData/quickfix/deprecatedSymbolUsage/classUsages/annotationWithFileUseSiteTarget3.kt");
}
@TestMetadata("annotationWithGetUseSiteTarget1.kt")
public void testAnnotationWithGetUseSiteTarget1() throws Exception {
runTest("../../../idea/tests/testData/quickfix/deprecatedSymbolUsage/classUsages/annotationWithGetUseSiteTarget1.kt");
}
@TestMetadata("annotationWithGetUseSiteTarget2.kt")
public void testAnnotationWithGetUseSiteTarget2() throws Exception {
runTest("../../../idea/tests/testData/quickfix/deprecatedSymbolUsage/classUsages/annotationWithGetUseSiteTarget2.kt");
}
@TestMetadata("annotationWithGetUseSiteTarget3.kt")
public void testAnnotationWithGetUseSiteTarget3() throws Exception {
runTest("../../../idea/tests/testData/quickfix/deprecatedSymbolUsage/classUsages/annotationWithGetUseSiteTarget3.kt");
}
@TestMetadata("constructorUsage1.kt")
public void testConstructorUsage1() throws Exception {
runTest("../../../idea/tests/testData/quickfix/deprecatedSymbolUsage/classUsages/constructorUsage1.kt");
}
@TestMetadata("constructorUsage2.kt")
public void testConstructorUsage2() throws Exception {
runTest("../../../idea/tests/testData/quickfix/deprecatedSymbolUsage/classUsages/constructorUsage2.kt");
}
@TestMetadata("constructorUsage3.kt")
public void testConstructorUsage3() throws Exception {
runTest("../../../idea/tests/testData/quickfix/deprecatedSymbolUsage/classUsages/constructorUsage3.kt");
}
@TestMetadata("constructorUsage4.kt")
public void testConstructorUsage4() throws Exception {
runTest("../../../idea/tests/testData/quickfix/deprecatedSymbolUsage/classUsages/constructorUsage4.kt");
}
@TestMetadata("constructorUsage5.kt")
public void testConstructorUsage5() throws Exception {
runTest("../../../idea/tests/testData/quickfix/deprecatedSymbolUsage/classUsages/constructorUsage5.kt");
}
@TestMetadata("constructorUsage6.kt")
public void testConstructorUsage6() throws Exception {
runTest("../../../idea/tests/testData/quickfix/deprecatedSymbolUsage/classUsages/constructorUsage6.kt");
}
@TestMetadata("constructorUsage7.kt")
public void testConstructorUsage7() throws Exception {
runTest("../../../idea/tests/testData/quickfix/deprecatedSymbolUsage/classUsages/constructorUsage7.kt");
}
@TestMetadata("constructorUsageWithTypeArgument.kt")
public void testConstructorUsageWithTypeArgument() throws Exception {
runTest("../../../idea/tests/testData/quickfix/deprecatedSymbolUsage/classUsages/constructorUsageWithTypeArgument.kt");
}
@TestMetadata("constructorUsageWithTypeArgument2.kt")
public void testConstructorUsageWithTypeArgument2() throws Exception {
runTest("../../../idea/tests/testData/quickfix/deprecatedSymbolUsage/classUsages/constructorUsageWithTypeArgument2.kt");
}
@TestMetadata("constructorUsageWithTypeArgument3.kt")
public void testConstructorUsageWithTypeArgument3() throws Exception {
runTest("../../../idea/tests/testData/quickfix/deprecatedSymbolUsage/classUsages/constructorUsageWithTypeArgument3.kt");
}
@TestMetadata("constructorUsageWithTypeArgument4.kt")
public void testConstructorUsageWithTypeArgument4() throws Exception {
runTest("../../../idea/tests/testData/quickfix/deprecatedSymbolUsage/classUsages/constructorUsageWithTypeArgument4.kt");
}
@TestMetadata("constructorUsageWithTypeArgument5.kt")
public void testConstructorUsageWithTypeArgument5() throws Exception {
runTest("../../../idea/tests/testData/quickfix/deprecatedSymbolUsage/classUsages/constructorUsageWithTypeArgument5.kt");
}
@TestMetadata("constructorUsageWithTypeArgument6.kt")
public void testConstructorUsageWithTypeArgument6() throws Exception {
runTest("../../../idea/tests/testData/quickfix/deprecatedSymbolUsage/classUsages/constructorUsageWithTypeArgument6.kt");
}
@TestMetadata("constructorUsageWithTypeArgument7.kt")
public void testConstructorUsageWithTypeArgument7() throws Exception {
runTest("../../../idea/tests/testData/quickfix/deprecatedSymbolUsage/classUsages/constructorUsageWithTypeArgument7.kt");
}
@TestMetadata("constructorUsageWithTypeArgumentWithoutSpecifyType.kt")
public void testConstructorUsageWithTypeArgumentWithoutSpecifyType() throws Exception {
runTest("../../../idea/tests/testData/quickfix/deprecatedSymbolUsage/classUsages/constructorUsageWithTypeArgumentWithoutSpecifyType.kt");
}
@TestMetadata("imports.kt")
public void testImports() throws Exception {
runTest("../../../idea/tests/testData/quickfix/deprecatedSymbolUsage/classUsages/imports.kt");
}
@TestMetadata("inAliasSimple.kt")
public void testInAliasSimple() throws Exception {
runTest("../../../idea/tests/testData/quickfix/deprecatedSymbolUsage/classUsages/inAliasSimple.kt");
}
@TestMetadata("inAliasWithOwnReplaceForConstructorForAliasArguments.kt")
public void testInAliasWithOwnReplaceForConstructorForAliasArguments() throws Exception {
runTest("../../../idea/tests/testData/quickfix/deprecatedSymbolUsage/classUsages/inAliasWithOwnReplaceForConstructorForAliasArguments.kt");
}
@TestMetadata("inAliasWithOwnReplaceForConstructorUnused.kt")
public void testInAliasWithOwnReplaceForConstructorUnused() throws Exception {
runTest("../../../idea/tests/testData/quickfix/deprecatedSymbolUsage/classUsages/inAliasWithOwnReplaceForConstructorUnused.kt");
}
@TestMetadata("inAliasWithOwnReplaceForConstructorUsed.kt")
public void testInAliasWithOwnReplaceForConstructorUsed() throws Exception {
runTest("../../../idea/tests/testData/quickfix/deprecatedSymbolUsage/classUsages/inAliasWithOwnReplaceForConstructorUsed.kt");
}
@TestMetadata("inAliasWithOwnReplaceForSecondaryConstructorUnused.kt")
public void testInAliasWithOwnReplaceForSecondaryConstructorUnused() throws Exception {
runTest("../../../idea/tests/testData/quickfix/deprecatedSymbolUsage/classUsages/inAliasWithOwnReplaceForSecondaryConstructorUnused.kt");
}
@TestMetadata("inAliasWithOwnReplaceForSecondaryConstructorUsed.kt")
public void testInAliasWithOwnReplaceForSecondaryConstructorUsed() throws Exception {
runTest("../../../idea/tests/testData/quickfix/deprecatedSymbolUsage/classUsages/inAliasWithOwnReplaceForSecondaryConstructorUsed.kt");
}
@TestMetadata("inTypeArgument.kt")
public void testInTypeArgument() throws Exception {
runTest("../../../idea/tests/testData/quickfix/deprecatedSymbolUsage/classUsages/inTypeArgument.kt");
}
@TestMetadata("innerType.kt")
public void testInnerType() throws Exception {
runTest("../../../idea/tests/testData/quickfix/deprecatedSymbolUsage/classUsages/innerType.kt");
}
@TestMetadata("nestedClassToNestedClass.kt")
public void testNestedClassToNestedClass() throws Exception {
runTest("../../../idea/tests/testData/quickfix/deprecatedSymbolUsage/classUsages/nestedClassToNestedClass.kt");
}
@TestMetadata("noAnnotationConstructorUsage.kt")
public void testNoAnnotationConstructorUsage() throws Exception {
runTest("../../../idea/tests/testData/quickfix/deprecatedSymbolUsage/classUsages/noAnnotationConstructorUsage.kt");
}
@TestMetadata("noMatchTypeArgument.kt")
public void testNoMatchTypeArgument() throws Exception {
runTest("../../../idea/tests/testData/quickfix/deprecatedSymbolUsage/classUsages/noMatchTypeArgument.kt");
}
@TestMetadata("noMatchTypeArgument2.kt")
public void testNoMatchTypeArgument2() throws Exception {
runTest("../../../idea/tests/testData/quickfix/deprecatedSymbolUsage/classUsages/noMatchTypeArgument2.kt");
}
@TestMetadata("qualifiedClassName.kt")
public void testQualifiedClassName() throws Exception {
runTest("../../../idea/tests/testData/quickfix/deprecatedSymbolUsage/classUsages/qualifiedClassName.kt");
}
@TestMetadata("qualifiedClassNameInPattern.kt")
public void testQualifiedClassNameInPattern() throws Exception {
runTest("../../../idea/tests/testData/quickfix/deprecatedSymbolUsage/classUsages/qualifiedClassNameInPattern.kt");
}
@TestMetadata("secondaryConstructor.kt")
public void testSecondaryConstructor() throws Exception {
runTest("../../../idea/tests/testData/quickfix/deprecatedSymbolUsage/classUsages/secondaryConstructor.kt");
}
@TestMetadata("simple.kt")
public void testSimple() throws Exception {
runTest("../../../idea/tests/testData/quickfix/deprecatedSymbolUsage/classUsages/simple.kt");
}
}
@RunWith(JUnit3RunnerWithInners.class)
@TestMetadata("../../../idea/tests/testData/quickfix/deprecatedSymbolUsage/functionLiteralArguments")
public static class FunctionLiteralArguments extends AbstractHighLevelQuickFixTest {
@@ -8,4 +8,5 @@ annotation class Foo
annotation class Bar
@Foo<caret> class C {}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -9,4 +9,5 @@ annotation class Bar
@Bar
class C {}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -8,4 +8,5 @@ annotation class Foo(val p1: String, val p2: Int)
annotation class Bar(val p1: String, val p2: Int)
@Foo<caret>("", 1) class C {}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -8,4 +8,5 @@ annotation class Foo(val p1: String, val p2: Int)
annotation class Bar(val p1: String, val p2: Int)
@Bar("", 1) class C {}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -8,4 +8,5 @@ annotation class Foo
annotation class Bar(val p: Int)
@Foo<caret> class C {}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -9,4 +9,5 @@ annotation class Bar(val p: Int)
@Bar(1)
class C {}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -8,4 +8,5 @@ annotation class Foo(val p: Int)
annotation class Bar(val p: Int, val s: String)
@Foo<caret>(1) class C {}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -9,4 +9,5 @@ annotation class Bar(val p: Int, val s: String)
@Bar(1, "")
class C {}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -8,4 +8,5 @@ annotation class Foo(val p: Int)
annotation class Bar(val p: Int, val s: String)
@Foo<caret>(p = 1) class C
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -9,4 +9,5 @@ annotation class Bar(val p: Int, val s: String)
@Bar(p = 1, s = "")
class C
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -1,4 +1,5 @@
// "Replace with 'OptIn(*markerClass)'" "true"
// WITH_STDLIB 1.7.0
@file:<caret>UseExperimental
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
/* IGNORE_K2 */
@@ -1,4 +1,5 @@
// "Replace with 'OptIn(*markerClass)'" "true"
// WITH_STDLIB 1.7.0
@file:<caret>OptIn()
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
/* IGNORE_K2 */
@@ -1,4 +1,5 @@
// "Replace with 'OptIn(*markerClass)'" "true"
// WITH_STDLIB 1.7.0
@file:<caret>UseExperimental()
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
/* IGNORE_K2 */
@@ -1,4 +1,5 @@
// "Replace with 'OptIn(*markerClass)'" "true"
// WITH_STDLIB 1.7.0
@file:OptIn()
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
/* IGNORE_K2 */
@@ -4,4 +4,5 @@
annotation class Foo
annotation class Bar
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
/* IGNORE_K2 */
@@ -4,4 +4,5 @@
annotation class Foo
annotation class Bar
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
/* IGNORE_K2 */
@@ -10,4 +10,5 @@ annotation class Foo
@Target(AnnotationTarget.PROPERTY_GETTER)
annotation class Bar
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -10,4 +10,5 @@ annotation class Foo
@Target(AnnotationTarget.PROPERTY_GETTER)
annotation class Bar
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -10,4 +10,5 @@ annotation class Foo
@Target(AnnotationTarget.PROPERTY_GETTER)
annotation class Bar
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -10,4 +10,5 @@ annotation class Foo
@Target(AnnotationTarget.PROPERTY_GETTER)
annotation class Bar
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -10,4 +10,5 @@ annotation class Foo(val i: Int)
@Target(AnnotationTarget.PROPERTY_GETTER)
annotation class Bar(val i: Int)
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -10,4 +10,5 @@ annotation class Foo(val i: Int)
@Target(AnnotationTarget.PROPERTY_GETTER)
annotation class Bar(val i: Int)
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -9,4 +9,5 @@ fun foo() {
<caret>OldClass(1)
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -9,4 +9,5 @@ fun foo() {
NewClass(1)
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -7,4 +7,5 @@ fun foo() {
<caret>OldClass(1)
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -9,4 +9,5 @@ fun foo() {
Random(1)
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -10,4 +10,5 @@ fun foo() {
ppp.<caret>OldClass(1)
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -10,4 +10,5 @@ fun foo() {
NewClass(1)
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -10,4 +10,5 @@ fun foo() {
<caret>OldClass(1)
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -10,4 +10,5 @@ fun foo() {
<caret>NewClass(1 + 1)
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -11,4 +11,5 @@ fun a() {
A(42)
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -11,4 +11,5 @@ fun a() {
A(42)
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -13,4 +13,5 @@ fun b() {
val b = 30
A(b)
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageInWholeProjectFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageInWholeProjectFix
/* IGNORE_K2 */
@@ -13,4 +13,5 @@ fun b() {
val b = 30
C(s = "", a = { b }, m = b)
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageInWholeProjectFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageInWholeProjectFix
/* IGNORE_K2 */
@@ -11,4 +11,5 @@ fun a() {
A(42)
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageInWholeProjectFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageInWholeProjectFix
/* IGNORE_K2 */
@@ -11,4 +11,5 @@ fun a() {
A(b = "") { 42 }
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageInWholeProjectFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageInWholeProjectFix
/* IGNORE_K2 */
@@ -1,4 +1,5 @@
// "Replace with 'NewClass<Int>'" "true"
// K2_ACTION: "Replace with 'NewClass<T>'" "true"
package ppp
@Deprecated("renamed", ReplaceWith("NewClass<T>"))
@@ -10,4 +11,5 @@ fun foo() {
<caret>OldClass<Int>()
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -1,4 +1,5 @@
// "Replace with 'NewClass<Int>'" "true"
// K2_ACTION: "Replace with 'NewClass<T>'" "true"
package ppp
@Deprecated("renamed", ReplaceWith("NewClass<T>"))
@@ -10,4 +11,5 @@ fun foo() {
<caret>NewClass<Int>()
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -10,4 +10,5 @@ fun foo() {
<caret>OldClass<Int, String>()
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -10,4 +10,5 @@ fun foo() {
<caret>NewClass<Int>()
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -10,4 +10,5 @@ fun foo() {
<caret>OldClass<Int, String>()
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -10,4 +10,5 @@ fun foo() {
<caret>NewClass()
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -1,4 +1,5 @@
// "Replace with 'Factory<Int>()'" "true"
// K2_ACTION: "Replace with 'Factory<T>()'" "true"
// WITH_STDLIB
class Foo<T> @Deprecated("", ReplaceWith("Factory<T>()")) constructor()
@@ -7,4 +8,5 @@ fun <T> Factory(): Foo<T> = TODO()
fun baz() {
val foo = <caret>Foo<Int>()
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -1,4 +1,5 @@
// "Replace with 'Factory<Int>()'" "true"
// K2_ACTION: "Replace with 'Factory<T>()'" "true"
// WITH_STDLIB
class Foo<T> @Deprecated("", ReplaceWith("Factory<T>()")) constructor()
@@ -7,4 +8,5 @@ fun <T> Factory(): Foo<T> = TODO()
fun baz() {
val foo = <caret>Factory<Int>()
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -1,4 +1,5 @@
// "Replace with 'Factory<Int>()'" "true"
// K2_ACTION: "Replace with 'Factory()'" "true"
// WITH_STDLIB
class Foo<T> @Deprecated("", ReplaceWith("Factory()")) constructor()
@@ -7,4 +8,5 @@ fun <T> Factory(): Foo<T> = TODO()
fun baz() {
val foo = <caret>Foo<Int>()
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
/* IGNORE_K2 */
@@ -1,4 +1,5 @@
// "Replace with 'Factory<Int>()'" "true"
// K2_ACTION: "Replace with 'Factory()'" "true"
// WITH_STDLIB
class Foo<T> @Deprecated("", ReplaceWith("Factory()")) constructor()
@@ -7,4 +8,5 @@ fun <T> Factory(): Foo<T> = TODO()
fun baz() {
val foo = <caret>Factory<Int>()
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
/* IGNORE_K2 */
@@ -13,4 +13,5 @@ class New<T> : Main<T>()
fun test() {
val main = <caret>Old<Int>()
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -13,4 +13,5 @@ class New<T> : Main<T>()
fun test() {
val main = <caret>New<Int>()
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -12,4 +12,5 @@ class New<T> : Main<T>()
fun test() {
val main = <caret>Old<Int, String>()
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -12,4 +12,5 @@ class New<T> : Main<T>()
fun test() {
val main = <caret>New()
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -7,4 +7,5 @@ fun <T> Factory(): Foo<T> = TODO()
fun baz() {
val foo: Foo<Int> = <caret>Foo()
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -7,4 +7,5 @@ fun <T> Factory(): Foo<T> = TODO()
fun baz() {
val foo: Foo<Int> = <caret>Factory()
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -7,4 +7,5 @@ fun foo(): OldClass<caret>? {
return null
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
/* IGNORE_K2 */
@@ -9,4 +9,5 @@ fun foo(): File? {
return null
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
/* IGNORE_K2 */
@@ -8,4 +8,5 @@ class NewClass
typealias Old = <caret>OldClass
val a: Old = Old()
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -8,4 +8,5 @@ class NewClass
typealias Old = <caret>NewClass
val a: Old = Old()
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -11,4 +11,5 @@ typealias Old = OldClass<<caret>A>
val o: Old = Old()
val a = A() // Usage of A()
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -11,4 +11,5 @@ typealias Old = OldClass<<caret>B>
val o: Old = Old()
val a = A() // Usage of A()
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -8,4 +8,5 @@ class NewClass(p: Int)
typealias Old = <caret>OldClass
val a: Old = null!!
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -8,4 +8,5 @@ class NewClass(p: Int)
typealias Old = <caret>NewClass
val a: Old = null!!
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -12,4 +12,5 @@ class NewClass(p: Int)
typealias Old = <caret>OldClass
val a: Old = aa.Old()
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
/* IGNORE_K2 */
@@ -12,4 +12,5 @@ class NewClass(p: Int)
typealias Old = <caret>OldClass
val a: Old = aa.Old()
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
/* IGNORE_K2 */
@@ -10,4 +10,5 @@ class NewClass(p: Int = 0)
typealias Old = <caret>OldClass
val a: Old = Old()
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -10,4 +10,5 @@ class NewClass(p: Int = 0)
typealias Old = <caret>NewClass
val a: Old = Old()
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -12,4 +12,5 @@ class NewClass(p: Int)
typealias Old = <caret>OldClass
val a: Old = Old(1)
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
/* IGNORE_K2 */
@@ -12,4 +12,5 @@ class NewClass(p: Int)
typealias Old = <caret>OldClass
val a: Old = Old(1)
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
/* IGNORE_K2 */
@@ -9,4 +9,5 @@ fun foo(): List<OldClass<caret>>? {
return null
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -9,4 +9,5 @@ fun foo(): List<NewClass>? {
return null
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -1,4 +1,5 @@
// "Replace with 'B<F<Int>>'" "true"
// K2_ACTION: "Replace with 'B<N>'" "true"
// WITH_STDLIB
@Deprecated(message = "renamed", replaceWith = ReplaceWith("B<N>"))
@@ -10,4 +11,5 @@ class F<G>
fun test() {
var x: <caret>A<F<Int>>
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -1,4 +1,5 @@
// "Replace with 'B<F<Int>>'" "true"
// K2_ACTION: "Replace with 'B<N>'" "true"
// WITH_STDLIB
@Deprecated(message = "renamed", replaceWith = ReplaceWith("B<N>"))
@@ -10,4 +11,5 @@ class F<G>
fun test() {
var x: <caret>B<F<Int>>
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -11,4 +11,5 @@ fun foo(): Outer.OldClass<caret>? {
return null
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
/* IGNORE_K2 */
@@ -11,4 +11,5 @@ fun foo(): Outer.NewClass? {
return null
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
/* IGNORE_K2 */
@@ -9,4 +9,5 @@ fun foo() {
var c: <caret>C<Int, String>
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -9,4 +9,5 @@ fun foo() {
var c: <caret>B<Int>
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -9,4 +9,5 @@ fun foo() {
var c: <caret>C<Int, String>
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -9,4 +9,5 @@ fun foo() {
var c: <caret>B
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -11,4 +11,5 @@ fun foo(): ppp.OldClass<caret>? {
return null
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -11,4 +11,5 @@ fun foo(): NewClass? {
return null
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -7,4 +7,5 @@ fun foo(): OldClass<caret>? {
return null
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -9,4 +9,5 @@ fun foo(): File? {
return null
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -9,4 +9,5 @@ fun foo(): OldClass<caret>? {
return null
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -9,4 +9,5 @@ fun foo(): NewClass? {
return null
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.replaceWith.DeprecatedSymbolUsageFix
@@ -12,4 +12,4 @@ object Old {
val test = <caret>Old.foo()
// 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
@@ -12,4 +12,4 @@ object Old {
val test = <caret>New.foo()
// 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
@@ -12,4 +12,4 @@ object Old {
val test = some.<caret>Old
// 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
@@ -12,4 +12,4 @@ object Old {
val test = New
// 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
@@ -18,3 +18,5 @@ typealias New = NewClass
fun foo() {
<caret>Old()
}
/* IGNORE_K2 */
@@ -14,4 +14,5 @@ typealias Old2 = Old1
class NewClass()
fun foo() = <caret>Old2()
fun foo() = <caret>Old2()
/* IGNORE_K2 */
@@ -10,4 +10,4 @@ typealias B<E> = List<E>
val x: <caret>A<String> = emptyList()
// 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
@@ -10,4 +10,4 @@ typealias B<E> = List<E>
val x: B<String> = emptyList()
// 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
@@ -69,7 +69,6 @@ class AnnotationEntryReplacementPerformer(
override fun createDummyElement(mainExpression: KtExpression): KtAnnotationEntry =
createByPattern("@Dummy($0)", mainExpression) { psiFactory.createAnnotationEntry(it) }
@Suppress("KotlinConstantConditions") // KTIJ-23767
override fun rangeToElement(range: PsiChildRange): KtAnnotationEntry {
val useSiteTargetText = useSiteTarget?.renderName?.let { "$it:" } ?: ""
val isFileUseSiteTarget = useSiteTarget == AnnotationUseSiteTarget.FILE
@@ -56,5 +56,6 @@
<orderEntry type="library" name="Guava" level="project" />
<orderEntry type="module" module-name="kotlin.refactorings.move.k2" />
<orderEntry type="module" module-name="intellij.platform.util.text.matching" />
<orderEntry type="module" module-name="kotlin.base.indices" />
</component>
</module>
@@ -0,0 +1,122 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.kotlin.idea.k2.refactoring.inline.codeInliner
import com.intellij.openapi.project.Project
import org.jetbrains.kotlin.idea.base.analysis.api.utils.shortenReferences
import org.jetbrains.kotlin.idea.base.psi.replaced
import org.jetbrains.kotlin.idea.refactoring.inline.codeInliner.CodeToInline
import org.jetbrains.kotlin.idea.refactoring.inline.codeInliner.UsageReplacementStrategy
import org.jetbrains.kotlin.idea.references.KtSimpleNameReference
import org.jetbrains.kotlin.idea.references.mainReference
import org.jetbrains.kotlin.idea.stubindex.KotlinClassShortNameIndex
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.getQualifiedExpressionForSelector
class ClassUsageReplacementStrategy(
typeReplacement: KtUserType?,
constructorReplacement: CodeToInline?,
project: Project
) : UsageReplacementStrategy {
private val factory = KtPsiFactory(project)
private val typeReplacement = typeReplacement?.takeIf { it.referenceExpression != null }
private val typeReplacementQualifierAsExpression = typeReplacement?.qualifier?.let { factory.createExpression(it.text) }
private val constructorReplacementStrategy = constructorReplacement?.let {
CallableUsageReplacementStrategy(it, inlineSetter = false)
}
override fun createReplacer(usage: KtReferenceExpression): (() -> KtElement?)? {
if (usage !is KtNameReferenceExpression) return null
constructorReplacementStrategy?.createReplacer(usage)?.let { return it }
when (val parent = usage.parent) {
is KtUserType -> {
if (typeReplacement == null) return null
return {
val oldArgumentList = parent.typeArgumentList?.copy() as? KtTypeArgumentList
val replaced = parent.replaced(typeReplacement)
val newArgumentList = replaced.typeArgumentList
if (oldArgumentList != null && oldArgumentList.arguments.size == newArgumentList?.arguments?.size) {
newArgumentList.replace(oldArgumentList)
}
shortenReferences(replaced) as? KtElement
}
}
is KtCallElement -> {
if (usage != parent.calleeExpression) return null
when {
constructorReplacementStrategy == null && typeReplacement != null -> return {
replaceConstructorCallWithOtherTypeConstruction(parent)
}
else -> return null
}
}
else -> {
if (typeReplacement != null) {
val fqNameStr = typeReplacement.text
val fqName = FqName(fqNameStr)
return {
usage.mainReference.bindToFqName(fqName, KtSimpleNameReference.ShorteningMode.FORCED_SHORTENING) as? KtElement
}
}
return null
}
}
}
private fun replaceConstructorCallWithOtherTypeConstruction(callExpression: KtCallElement): KtElement? {
val referenceExpression = typeReplacement?.referenceExpression ?: error("Couldn't find referenceExpression")
val classFromReplacement = KotlinClassShortNameIndex
.get(referenceExpression.text, callExpression.project, callExpression.resolveScope)
.firstOrNull()
val replacementTypeArgumentList = typeReplacement.typeArgumentList
val replacementTypeArgumentCount = classFromReplacement?.typeParameters?.size
?: replacementTypeArgumentList?.arguments?.size
val typeArgumentList = callExpression.typeArgumentList
val constructor = callExpression.mainReference?.resolve()
val typeArgumentCount = (constructor as? KtConstructor<*>)?.typeParameters?.size ?: typeArgumentList?.arguments?.size
if (typeArgumentCount != replacementTypeArgumentCount) {
if (replacementTypeArgumentList == null) typeArgumentList?.delete()
else callExpression.replaceOrCreateTypeArgumentList(
replacementTypeArgumentList.copy() as KtTypeArgumentList
)
}
callExpression.calleeExpression?.replace(referenceExpression)
val expressionToReplace = callExpression.getQualifiedExpressionForSelector() ?: callExpression
val newExpression = if (typeReplacementQualifierAsExpression != null)
factory.createExpressionByPattern("$0.$1", typeReplacementQualifierAsExpression, callExpression)
else
callExpression
val result = if (expressionToReplace != newExpression) {
expressionToReplace.replaced(newExpression)
} else {
expressionToReplace
}
return shortenReferences(result) as? KtElement
}
}
private fun KtCallElement.replaceOrCreateTypeArgumentList(newTypeArgumentList: KtTypeArgumentList) {
if (typeArgumentList != null) typeArgumentList?.replace(newTypeArgumentList)
else addAfter(
newTypeArgumentList,
calleeExpression,
)
}
@@ -3,7 +3,6 @@ package org.jetbrains.kotlin.idea.k2.refactoring.inline.codeInliner
import com.intellij.psi.createSmartPointer
import com.intellij.psi.search.LocalSearchScope
import com.intellij.psi.util.PsiTreeUtil
import org.jetbrains.kotlin.analysis.api.KaExperimentalApi
import org.jetbrains.kotlin.analysis.api.KaSession
import org.jetbrains.kotlin.analysis.api.analyze
@@ -26,6 +25,7 @@ import org.jetbrains.kotlin.idea.base.searching.usages.ReferencesSearchScopeHelp
import org.jetbrains.kotlin.idea.core.CollectingNameValidator
import org.jetbrains.kotlin.idea.k2.refactoring.util.LambdaToAnonymousFunctionUtil
import org.jetbrains.kotlin.idea.refactoring.inline.codeInliner.AbstractCodeInliner
import org.jetbrains.kotlin.idea.refactoring.inline.codeInliner.AnnotationEntryReplacementPerformer
import org.jetbrains.kotlin.idea.refactoring.inline.codeInliner.CodeToInline
import org.jetbrains.kotlin.idea.refactoring.inline.codeInliner.CommentHolder
import org.jetbrains.kotlin.idea.refactoring.inline.codeInliner.ExpressionReplacementPerformer
@@ -52,7 +52,15 @@ class CodeInliner(
codeToInline: CodeToInline
) : AbstractCodeInliner<KtElement, KtParameter, KaType, KtDeclaration>(call, codeToInline) {
private val mapping: Map<KtExpression, Name>? = analyze(call) {
call.resolveToCall()?.singleFunctionCallOrNull()?.argumentMapping?.mapValues { e -> e.value.name }
treeUpToCall().resolveToCall()?.singleFunctionCallOrNull()?.argumentMapping?.mapValues { e -> e.value.name }
}
private fun treeUpToCall(): KtElement {
val userType = call.parent as? KtUserType ?: return call
val typeReference = userType.parent as? KtTypeReference ?: return call
val constructorCalleeExpression = typeReference.parent as? KtConstructorCalleeExpression ?: return call
val gParent = constructorCalleeExpression.parent
return gParent as? KtSuperTypeCallEntry ?: gParent as? KtAnnotationEntry ?: call
}
@OptIn(KaExperimentalApi::class)
@@ -60,16 +68,14 @@ class CodeInliner(
val qualifiedElement = if (call is KtExpression) {
call.getQualifiedExpressionForSelector()
?: call.callableReferenceExpressionForReference()
?: call.parent as? KtSuperTypeCallEntry
?: call
?: treeUpToCall()
} else call
val assignment = (qualifiedElement as? KtExpression)
?.getAssignmentByLHS()
?.takeIf { it.operationToken == KtTokens.EQ }
val originalDeclaration = analyze(call) {
(call.parent as? KtCallableReferenceExpression
?: PsiTreeUtil.getParentOfType(call, KtSuperTypeCallEntry::class.java)
?: call)
?: treeUpToCall())
.resolveToCall()?.singleCallOrNull<KaCallableMemberCall<*, *>>()?.partiallyAppliedSymbol?.symbol?.psi as? KtDeclaration
} ?: return null
val callableForParameters = (if (assignment != null && originalDeclaration is KtProperty)
@@ -157,7 +163,7 @@ class CodeInliner(
processTypeParameterUsages(
callElement = call as? KtCallElement,
typeParameters = (originalDeclaration as? KtCallableDeclaration)?.typeParameters ?: emptyList(),
typeParameters = (originalDeclaration as? KtConstructor<*>)?.containingClass()?.typeParameters ?: (originalDeclaration as? KtCallableDeclaration)?.typeParameters ?: emptyList(),
namer = { it.nameAsSafeName },
typeRetriever = {
analyze(callableForParameters) {
@@ -208,6 +214,7 @@ class CodeInliner(
findAndMarkNewDeclarations()
val performer = when (elementToBeReplaced) {
is KtExpression -> ExpressionReplacementPerformer(codeToInline, elementToBeReplaced)
is KtAnnotationEntry -> AnnotationEntryReplacementPerformer(codeToInline, elementToBeReplaced)
is KtSuperTypeCallEntry -> SuperTypeCallEntryReplacementPerformer(codeToInline, elementToBeReplaced)
else -> error("Unsupported element: $elementToBeReplaced")
}
@@ -231,6 +231,7 @@ object InlinePostProcessor: AbstractInlinePostProcessor() {
}
}
val replacementMap = mutableMapOf<KtValueArgument, KtValueArgument>()
analyze(element) {
for (callExpression in callsToProcess) {
val resolvedCall = callExpression.resolveToCall()?.successfulFunctionCallOrNull() ?: return
@@ -248,9 +249,10 @@ object InlinePostProcessor: AbstractInlinePostProcessor() {
newArgument.putCopyableUserData(DEFAULT_PARAMETER_VALUE_KEY, Unit)
}
argument.replace(newArgument)
replacementMap.put(argument, newArgument)
}
}
}
replacementMap.forEach { (argument, replacement) -> argument.replace(replacement) }
}
}
@@ -8,7 +8,9 @@ import org.jetbrains.kotlin.analysis.api.permissions.KaAllowAnalysisFromWriteAct
import org.jetbrains.kotlin.analysis.api.permissions.KaAllowAnalysisOnEdt
import org.jetbrains.kotlin.analysis.api.permissions.allowAnalysisFromWriteAction
import org.jetbrains.kotlin.analysis.api.permissions.allowAnalysisOnEdt
import org.jetbrains.kotlin.analysis.api.resolution.KaCallableMemberCall
import org.jetbrains.kotlin.analysis.api.resolution.KaImplicitReceiverValue
import org.jetbrains.kotlin.analysis.api.resolution.singleCallOrNull
import org.jetbrains.kotlin.analysis.api.resolution.singleFunctionCallOrNull
import org.jetbrains.kotlin.analysis.api.resolution.singleVariableAccessCall
import org.jetbrains.kotlin.analysis.api.resolution.symbol
@@ -246,15 +248,14 @@ internal fun encodeInternalReferences(codeToInline: MutableCodeToInline, origina
if (receiverExpression == null) {
val (receiverValue, isSameReceiverType) = analyze(expression) {
val resolveCall = expression.resolveToCall()
val partiallyAppliedSymbol =
(resolveCall?.singleFunctionCallOrNull() ?: resolveCall?.singleVariableAccessCall())?.partiallyAppliedSymbol
val partiallyAppliedSymbol = resolveCall?.singleCallOrNull<KaCallableMemberCall<*, *>>()?.partiallyAppliedSymbol
val value =
(partiallyAppliedSymbol?.extensionReceiver ?: partiallyAppliedSymbol?.dispatchReceiver) as? KaImplicitReceiverValue
val originalSymbol = originalDeclaration.symbol as? KaCallableSymbol
val originalSymbolReceiverType = originalSymbol?.receiverType
val originalSymbolDispatchType = originalSymbol?.dispatchReceiverType
if (value != null) {
if (value != null && !(resolve is KtParameter && resolve.ownerFunction == originalDeclaration)) {
getThisQualifier(value) to (originalSymbolReceiverType != null && value.type.isEqualTo(originalSymbolReceiverType) ||
originalSymbolDispatchType != null && value.type.isEqualTo(originalSymbolDispatchType))
} else {
@@ -115,7 +115,7 @@ internal fun MutableTWorkspace.generateK2FixTests() {
model("$idea/quickfix/declaringJavaClass", pattern = pattern, isIgnored = true)
model("$idea/quickfix/decreaseVisibility", pattern = pattern)
model("$idea/quickfix/deprecatedJavaAnnotation", pattern = pattern, isIgnored = true)
model("$idea/quickfix/deprecatedSymbolUsage", pattern = pattern, isIgnored = false, excludedDirectories = listOf("classUsages", "publishedApi", "wholeProject"))
model("$idea/quickfix/deprecatedSymbolUsage", pattern = pattern, isIgnored = false, excludedDirectories = listOf("publishedApi", "wholeProject"))
model("$idea/quickfix/equalityNotApplicable", pattern = pattern)
model("$idea/quickfix/final", pattern = pattern, isIgnored = true)
model("$idea/quickfix/foldTryCatch", pattern = pattern)