diff --git a/plugins/kotlin/base/psi/src/org/jetbrains/kotlin/idea/base/psi/JavaPsiUtils.kt b/plugins/kotlin/base/psi/src/org/jetbrains/kotlin/idea/base/psi/JavaPsiUtils.kt index 0859f307b984..53b8509da829 100644 --- a/plugins/kotlin/base/psi/src/org/jetbrains/kotlin/idea/base/psi/JavaPsiUtils.kt +++ b/plugins/kotlin/base/psi/src/org/jetbrains/kotlin/idea/base/psi/JavaPsiUtils.kt @@ -17,7 +17,7 @@ val PsiClass.classIdIfNonLocal: ClassId? if (this is KtLightClass) { return this.kotlinOrigin?.getClassId() } - val packageName = (containingFile as? PsiJavaFile)?.packageName ?: return null + val packageName = (containingFile as? PsiClassOwner)?.packageName ?: return null val packageFqName = FqName(packageName) val classesNames = parentsOfType().map { it.name }.toList().asReversed() diff --git a/plugins/kotlin/code-insight/inspections-k2/tests/test/org/jetbrains/kotlin/idea/k2/quickfix/tests/K2CreateVariableFromUsageTest.kt b/plugins/kotlin/code-insight/inspections-k2/tests/test/org/jetbrains/kotlin/idea/k2/quickfix/tests/K2CreateVariableFromUsageTest.kt index 8ed9e3d08797..0a6ecee419ac 100644 --- a/plugins/kotlin/code-insight/inspections-k2/tests/test/org/jetbrains/kotlin/idea/k2/quickfix/tests/K2CreateVariableFromUsageTest.kt +++ b/plugins/kotlin/code-insight/inspections-k2/tests/test/org/jetbrains/kotlin/idea/k2/quickfix/tests/K2CreateVariableFromUsageTest.kt @@ -15,5 +15,6 @@ abstract class K2CreateVariableFromUsageTest : K2AbstractCreateFromUsageTest("cr class Property : K2CreateVariableFromUsageTest() { class Abstract: K2CreateVariableFromUsageTest() class FieldFromJava: K2CreateVariableFromUsageTest() + class Extension: K2CreateVariableFromUsageTest() } } \ No newline at end of file diff --git a/plugins/kotlin/code-insight/kotlin.code-insight.k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/quickFixes/createFromUsage/CreatePropertyFromKotlinUsageRequest.kt b/plugins/kotlin/code-insight/kotlin.code-insight.k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/quickFixes/createFromUsage/CreatePropertyFromKotlinUsageRequest.kt index f0916b3edf58..ed0a2b148585 100644 --- a/plugins/kotlin/code-insight/kotlin.code-insight.k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/quickFixes/createFromUsage/CreatePropertyFromKotlinUsageRequest.kt +++ b/plugins/kotlin/code-insight/kotlin.code-insight.k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/quickFixes/createFromUsage/CreatePropertyFromKotlinUsageRequest.kt @@ -10,9 +10,15 @@ import com.intellij.lang.jvm.types.JvmSubstitutor import com.intellij.psi.PsiJvmSubstitutor import com.intellij.psi.PsiSubstitutor import com.intellij.psi.createSmartPointer +import org.jetbrains.kotlin.analysis.api.KaExperimentalApi import org.jetbrains.kotlin.analysis.api.analyze +import org.jetbrains.kotlin.analysis.api.renderer.types.KaTypeRenderer +import org.jetbrains.kotlin.analysis.api.renderer.types.impl.KaTypeRendererForSource +import org.jetbrains.kotlin.analysis.api.types.KaType +import org.jetbrains.kotlin.idea.k2.codeinsight.quickFixes.createFromUsage.K2CreateFunctionFromUsageUtil.convertToJvmType import org.jetbrains.kotlin.idea.k2.codeinsight.quickFixes.createFromUsage.K2CreateFunctionFromUsageUtil.getExpectedKotlinType import org.jetbrains.kotlin.psi.KtNameReferenceExpression +import org.jetbrains.kotlin.types.Variance /** * A request to create Kotlin property from the usage in Kotlin. @@ -20,19 +26,38 @@ import org.jetbrains.kotlin.psi.KtNameReferenceExpression internal class CreatePropertyFromKotlinUsageRequest ( referenceExpression: KtNameReferenceExpression, private val modifiers: Collection, + private val receiverType: KaType?, val isExtension: Boolean ) : CreateFieldRequest { private val referencePointer = referenceExpression.createSmartPointer() - private val returnType: List = initializeReturnType(referenceExpression) + @OptIn(KaExperimentalApi::class) + val receiverTypeString: String? = getReceiverTypeString(referenceExpression, K2CreateFunctionFromUsageUtil.WITH_TYPE_NAMES_FOR_CREATE_ELEMENTS) + + @OptIn(KaExperimentalApi::class) + val receiverTypeNameString: String? = getReceiverTypeString(referenceExpression, KaTypeRendererForSource.WITH_SHORT_NAMES) private fun initializeReturnType(referenceExpression: KtNameReferenceExpression): List { return analyze(referenceExpression) { - val returnJvmType = referenceExpression.getExpectedKotlinType() ?: return emptyList() + val returnJvmType = referenceExpression.getExpectedKotlinType() + if (returnJvmType == null) { + val expectedType = builtinTypes.any + val jvmType = expectedType.convertToJvmType(referenceExpression) ?: return emptyList() + return listOf(ExpectedKotlinType(expectedType, jvmType)) + } listOf(returnJvmType) } } + @OptIn(KaExperimentalApi::class) + private fun getReceiverTypeString( + referenceExpression: KtNameReferenceExpression, renderer: KaTypeRenderer + ): String? { + return analyze(referenceExpression) { + receiverType?.render(renderer, position = Variance.IN_VARIANCE) + } + } + override fun isValid(): Boolean = referencePointer.element?.getReferencedName() != null override fun getFieldName(): String = referencePointer.element?.getReferencedName() ?: "" diff --git a/plugins/kotlin/code-insight/kotlin.code-insight.k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/quickFixes/createFromUsage/K2CreatePropertyFromUsageBuilder.kt b/plugins/kotlin/code-insight/kotlin.code-insight.k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/quickFixes/createFromUsage/K2CreatePropertyFromUsageBuilder.kt index d45ab13b0027..fadb853e2634 100644 --- a/plugins/kotlin/code-insight/kotlin.code-insight.k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/quickFixes/createFromUsage/K2CreatePropertyFromUsageBuilder.kt +++ b/plugins/kotlin/code-insight/kotlin.code-insight.k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/quickFixes/createFromUsage/K2CreatePropertyFromUsageBuilder.kt @@ -41,6 +41,7 @@ import org.jetbrains.kotlin.idea.base.analysis.api.utils.hasApplicableAllowedTar import org.jetbrains.kotlin.idea.base.analysis.api.utils.isApplicableTargetSet import org.jetbrains.kotlin.idea.base.analysis.api.utils.shortenReferences import org.jetbrains.kotlin.idea.base.codeInsight.ShortenReferencesFacility +import org.jetbrains.kotlin.idea.base.psi.classIdIfNonLocal import org.jetbrains.kotlin.idea.base.psi.getOrCreateCompanionObject import org.jetbrains.kotlin.idea.base.resources.KotlinBundle import org.jetbrains.kotlin.idea.k2.codeinsight.quickFixes.createFromUsage.K2CreateFunctionFromUsageUtil.resolveExpression @@ -109,26 +110,37 @@ object K2CreatePropertyFromUsageBuilder { else -> return emptyList() } + val receiverType = receiverExpression?.expressionType + val lightClass = (defaultContainerPsi as? KtClassOrObject)?.toLightClass() ?: defaultContainerPsi as? PsiClass val isAbstract = lightClass?.hasModifier(JvmModifier.ABSTRACT) + val containingKtFile = ref.containingKtFile + val wrapperForKtFile = JvmClassWrapperForKtClass(containingKtFile) if (defaultContainerPsi != null) { if (defaultContainerPsi.manager.isInProject(defaultContainerPsi)) { - val jvmModifiers = createModifiers(ref, defaultContainerPsi, isExtension = false, static, isAbstract == true) if (lightClass != null) { + val jvmModifiers = createModifiers(ref, defaultContainerPsi, isExtension = false, static = static, isAbstract = isAbstract == true) if (static || isAbstract!!.not()) { - requests.add(lightClass to CreatePropertyFromKotlinUsageRequest(ref, jvmModifiers, false)) + requests.add(lightClass to CreatePropertyFromKotlinUsageRequest(ref, jvmModifiers, receiverType, isExtension = false)) } if (lightClass.hasModifier(JvmModifier.ABSTRACT)) { - requests.add(lightClass to CreatePropertyFromKotlinUsageRequest(ref, jvmModifiers + JvmModifier.ABSTRACT, false)) + requests.add(lightClass to CreatePropertyFromKotlinUsageRequest(ref, jvmModifiers + JvmModifier.ABSTRACT, receiverType, isExtension = false)) } } + val jvmModifiers = createModifiers(ref, containingKtFile, isExtension = true, static = true, false) + val classId = + (defaultContainerPsi as? KtClassOrObject)?.classIdIfNonLocal ?: (defaultContainerPsi as? PsiClass)?.classIdIfNonLocal + if (classId != null) { + val targetClassType = buildClassType(if (static) ClassId.fromString(classId.asFqNameString() + ".Companion") else classId) + requests.add(wrapperForKtFile to CreatePropertyFromKotlinUsageRequest(ref, jvmModifiers, targetClassType, isExtension = true)) + } + } else { + val jvmModifiers = createModifiers(ref, containingKtFile, isExtension = true, static = true, false) + requests.add(wrapperForKtFile to CreatePropertyFromKotlinUsageRequest(ref, jvmModifiers, receiverType, isExtension = true)) } } else { - val containingKtFile = ref.containingKtFile - val jvmModifiers = createModifiers(ref, containingKtFile, isExtension = receiverExpression != null, static, false) - containingKtFile.toLightElements().firstOrNull()?.let { lightElement -> - if (lightElement is JvmClass) requests.add(lightElement to CreatePropertyFromKotlinUsageRequest(ref, jvmModifiers, receiverExpression != null)) - } + val jvmModifiers = createModifiers(ref, containingKtFile, isExtension = receiverExpression != null, static = true, isAbstract = false) + requests.add(wrapperForKtFile to CreatePropertyFromKotlinUsageRequest(ref, jvmModifiers, receiverType, isExtension = receiverExpression != null)) } return requests } @@ -184,7 +196,7 @@ object K2CreatePropertyFromUsageBuilder { .filter { it != JvmModifier.PUBLIC && it != JvmModifier.ABSTRACT } .mapNotNullTo(this, CreateFromUsageUtil::jvmModifierToKotlin) - if (lateinit) { + if (lateinit && !(request is CreatePropertyFromKotlinUsageRequest && request.isExtension)) { this += KtTokens.LATEINIT_KEYWORD } else if (request.isConstant) { this += KtTokens.CONST_KEYWORD @@ -193,8 +205,9 @@ object K2CreatePropertyFromUsageBuilder { override fun getText(): String { return if (request is CreatePropertyFromKotlinUsageRequest) { - if (request.isExtension && false) { - KotlinBundle.message("fix.create.from.usage.extension.property", """$classOrFileName.${request.fieldName}""") + if (request.isExtension) { + val receiverType = request.receiverTypeNameString?.let { "$it." } ?: "" + KotlinBundle.message("fix.create.from.usage.extension.property", """$receiverType${request.fieldName}""") } else { val key = if (JvmModifier.ABSTRACT in request.modifiers) { "fix.create.from.usage.abstract.property" @@ -233,12 +246,18 @@ object K2CreatePropertyFromUsageBuilder { append(varVal) append(" ") + if (request is CreatePropertyFromKotlinUsageRequest && request.isExtension) { + (request.receiverTypeString)?.let { append(it).append(".") } + } append(request.fieldName.quoteIfNeeded()) append(": ") analyze(container) { - val psiType = request.fieldType.firstOrNull()?.theType as? PsiType - val type = psiType?.asKaType(container) + val expectedType = request.fieldType.firstOrNull() + val type = when (expectedType) { + is ExpectedKotlinType -> expectedType.ktType + else -> (expectedType?.theType as? PsiType)?.asKaType(container) + } type?.render(KaTypeRendererForSource.WITH_QUALIFIED_NAMES, Variance.IN_VARIANCE) }?.let { append(it) } diff --git a/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/extensionPropertyOnTypeFromAnotherPackage.after.k2.kt b/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/extensionPropertyOnTypeFromAnotherPackage.after.k2.kt new file mode 100644 index 000000000000..f4d39169ca47 --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/extensionPropertyOnTypeFromAnotherPackage.after.k2.kt @@ -0,0 +1,13 @@ +// "Create extension property 'A.foo'" "true" +// ERROR: Unresolved reference: foo + +import package1.A + +private val package2.A.foo: Any + +class X { + init { + val y = package2.A() + val foo = y.foo + } +} \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/extensionValOnClassNoClassObject.k2.kt.after b/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/extensionValOnClassNoClassObject.k2.kt.after new file mode 100644 index 000000000000..f8326091e76c --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/extensionValOnClassNoClassObject.k2.kt.after @@ -0,0 +1,10 @@ +private val A.Companion.foo: Int + +// "Create extension property 'A.Companion.foo'" "true" +class A(val n: T) + +fun test() { + val a: Int = A.foo +} +// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable.CreateExtensionCallableFromUsageFix +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.quickFixes.createFromUsage.K2CreatePropertyFromUsageBuilder$CreatePropertyFromUsageAction \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/extensionValOnClassNoClassObject.kt b/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/extensionValOnClassNoClassObject.kt index 89d6360d789c..c1a53ff3096d 100644 --- a/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/extensionValOnClassNoClassObject.kt +++ b/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/extensionValOnClassNoClassObject.kt @@ -4,4 +4,5 @@ class A(val n: T) fun test() { val a: Int = A.foo } -// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable.CreateExtensionCallableFromUsageFix \ No newline at end of file +// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable.CreateExtensionCallableFromUsageFix +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.quickFixes.createFromUsage.K2CreatePropertyFromUsageBuilder$CreatePropertyFromUsageAction \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/extensionValOnClassNoClassObject.kt.after b/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/extensionValOnClassNoClassObject.kt.after index ffbd5ce5eccc..00b0e66f51f6 100644 --- a/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/extensionValOnClassNoClassObject.kt.after +++ b/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/extensionValOnClassNoClassObject.kt.after @@ -11,4 +11,5 @@ class A(val n: T) { fun test() { val a: Int = A.foo } -// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable.CreateExtensionCallableFromUsageFix \ No newline at end of file +// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable.CreateExtensionCallableFromUsageFix +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.quickFixes.createFromUsage.K2CreatePropertyFromUsageBuilder$CreatePropertyFromUsageAction \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/extensionValOnClassNoClassObject2.k2.kt.after b/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/extensionValOnClassNoClassObject2.k2.kt.after new file mode 100644 index 000000000000..2d4bef5e1cfb --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/extensionValOnClassNoClassObject2.k2.kt.after @@ -0,0 +1,10 @@ +private val A.Companion.foo: Int + +// "Create extension property 'A.Companion.foo'" "true" +class A + +fun test() { + val a: Int = A.foo +} +// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable.CreateExtensionCallableFromUsageFix +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.quickFixes.createFromUsage.K2CreatePropertyFromUsageBuilder$CreatePropertyFromUsageAction \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/extensionValOnClassNoClassObject2.kt b/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/extensionValOnClassNoClassObject2.kt index 0872d43df151..a461d449a9f4 100644 --- a/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/extensionValOnClassNoClassObject2.kt +++ b/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/extensionValOnClassNoClassObject2.kt @@ -4,4 +4,5 @@ class A fun test() { val a: Int = A.foo } -// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable.CreateExtensionCallableFromUsageFix \ No newline at end of file +// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable.CreateExtensionCallableFromUsageFix +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.quickFixes.createFromUsage.K2CreatePropertyFromUsageBuilder$CreatePropertyFromUsageAction \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/extensionValOnClassNoClassObject2.kt.after b/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/extensionValOnClassNoClassObject2.kt.after index 98dbcbc18fff..2bd6ed8a8cfe 100644 --- a/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/extensionValOnClassNoClassObject2.kt.after +++ b/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/extensionValOnClassNoClassObject2.kt.after @@ -11,4 +11,5 @@ class A { fun test() { val a: Int = A.foo } -// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable.CreateExtensionCallableFromUsageFix \ No newline at end of file +// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable.CreateExtensionCallableFromUsageFix +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.quickFixes.createFromUsage.K2CreatePropertyFromUsageBuilder$CreatePropertyFromUsageAction \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/extensionValOnGroovyType.after.k2.kt b/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/extensionValOnGroovyType.after.k2.kt new file mode 100644 index 000000000000..eae452972a30 --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/extensionValOnGroovyType.after.k2.kt @@ -0,0 +1,8 @@ +// "Create extension property 'A.foo'" "true" +// ERROR: Unresolved reference: foo + +private val A.foo: String? + +fun test(): String? { + return A().foo +} \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/extensionValOnJavaType.after.k2.kt b/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/extensionValOnJavaType.after.k2.kt new file mode 100644 index 000000000000..eae452972a30 --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/extensionValOnJavaType.after.k2.kt @@ -0,0 +1,8 @@ +// "Create extension property 'A.foo'" "true" +// ERROR: Unresolved reference: foo + +private val A.foo: String? + +fun test(): String? { + return A().foo +} \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/extensionWithTypeParameterAsReceiver.kt b/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/extensionWithTypeParameterAsReceiver.kt index dd06e967a07c..b9516b900d13 100644 --- a/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/extensionWithTypeParameterAsReceiver.kt +++ b/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/extensionWithTypeParameterAsReceiver.kt @@ -4,4 +4,6 @@ fun consume(n: Int) {} fun foo(t: T) { consume(t.bar) } -// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable.CreateExtensionCallableFromUsageFix \ No newline at end of file +// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable.CreateExtensionCallableFromUsageFix +// KTIJ-32974 +// IGNORE_K2 \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/extensionWithTypeParameterAsReceiver.kt.after b/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/extensionWithTypeParameterAsReceiver.kt.after index 98c9d10f2459..cd2260ac7845 100644 --- a/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/extensionWithTypeParameterAsReceiver.kt.after +++ b/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/extensionWithTypeParameterAsReceiver.kt.after @@ -9,4 +9,6 @@ fun consume(n: Int) {} fun foo(t: T) { consume(t.bar) } -// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable.CreateExtensionCallableFromUsageFix \ No newline at end of file +// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable.CreateExtensionCallableFromUsageFix +// KTIJ-32974 +// IGNORE_K2 \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/nullableReceiver.k2.kt.after b/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/nullableReceiver.k2.kt.after new file mode 100644 index 000000000000..4ff0fdd41cb6 --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/nullableReceiver.k2.kt.after @@ -0,0 +1,10 @@ +private val String?.notExistingVal: Int + +// "Create extension property 'String?.notExistingVal'" "true" +fun foo(n: Int) {} + +fun context(p: String?) { + foo(p.notExistingVal) +} +// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable.CreateExtensionCallableFromUsageFix +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.quickFixes.createFromUsage.K2CreatePropertyFromUsageBuilder$CreatePropertyFromUsageAction \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/nullableReceiver.kt b/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/nullableReceiver.kt index 1645e21f155c..72cecf56e98f 100644 --- a/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/nullableReceiver.kt +++ b/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/nullableReceiver.kt @@ -4,4 +4,5 @@ fun foo(n: Int) {} fun context(p: String?) { foo(p.notExistingVal) } -// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable.CreateExtensionCallableFromUsageFix \ No newline at end of file +// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable.CreateExtensionCallableFromUsageFix +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.quickFixes.createFromUsage.K2CreatePropertyFromUsageBuilder$CreatePropertyFromUsageAction \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/nullableReceiver.kt.after b/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/nullableReceiver.kt.after index 9b7435387baa..f8591b0ad418 100644 --- a/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/nullableReceiver.kt.after +++ b/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/nullableReceiver.kt.after @@ -9,4 +9,5 @@ fun foo(n: Int) {} fun context(p: String?) { foo(p.notExistingVal) } -// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable.CreateExtensionCallableFromUsageFix \ No newline at end of file +// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable.CreateExtensionCallableFromUsageFix +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.quickFixes.createFromUsage.K2CreatePropertyFromUsageBuilder$CreatePropertyFromUsageAction \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/valOnLibObject.k2.kt.after b/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/valOnLibObject.k2.kt.after new file mode 100644 index 000000000000..10951e46c2e0 --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/valOnLibObject.k2.kt.after @@ -0,0 +1,11 @@ +// "Create extension property 'Unit.foo'" "true" +// WITH_STDLIB + +private val Unit.foo: Int + +fun test() { + val a: Int = Unit.foo +} + +// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable.CreateExtensionCallableFromUsageFix +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.quickFixes.createFromUsage.K2CreatePropertyFromUsageBuilder$CreatePropertyFromUsageAction \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/valOnLibObject.kt b/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/valOnLibObject.kt index 0e1535a22636..e2af247e3f67 100644 --- a/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/valOnLibObject.kt +++ b/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/valOnLibObject.kt @@ -5,4 +5,5 @@ fun test() { val a: Int = Unit.foo } -// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable.CreateExtensionCallableFromUsageFix \ No newline at end of file +// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable.CreateExtensionCallableFromUsageFix +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.quickFixes.createFromUsage.K2CreatePropertyFromUsageBuilder$CreatePropertyFromUsageAction \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/valOnLibObject.kt.after b/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/valOnLibObject.kt.after index 9fdcfb64bfa8..79d98a166ab3 100644 --- a/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/valOnLibObject.kt.after +++ b/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/valOnLibObject.kt.after @@ -10,4 +10,5 @@ fun test() { val a: Int = Unit.foo } -// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable.CreateExtensionCallableFromUsageFix \ No newline at end of file +// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable.CreateExtensionCallableFromUsageFix +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.quickFixes.createFromUsage.K2CreatePropertyFromUsageBuilder$CreatePropertyFromUsageAction \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/valOnLibType.k2.kt.after b/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/valOnLibType.k2.kt.after new file mode 100644 index 000000000000..8f5fdb1af8bc --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/valOnLibType.k2.kt.after @@ -0,0 +1,13 @@ +// "Create extension property 'Int.foo'" "true" +// WITH_STDLIB + +private val Int.foo: A + +class A(val n: T) + +fun test() { + val a: A = 2.foo +} + +// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable.CreateExtensionCallableFromUsageFix +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.quickFixes.createFromUsage.K2CreatePropertyFromUsageBuilder$CreatePropertyFromUsageAction \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/valOnLibType.kt b/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/valOnLibType.kt index fb37a622ccda..65cb3ec8f430 100644 --- a/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/valOnLibType.kt +++ b/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/valOnLibType.kt @@ -7,4 +7,5 @@ fun test() { val a: A = 2.foo } -// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable.CreateExtensionCallableFromUsageFix \ No newline at end of file +// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable.CreateExtensionCallableFromUsageFix +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.quickFixes.createFromUsage.K2CreatePropertyFromUsageBuilder$CreatePropertyFromUsageAction \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/valOnLibType.kt.after b/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/valOnLibType.kt.after index e9259618eab5..45988e0bef4f 100644 --- a/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/valOnLibType.kt.after +++ b/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/valOnLibType.kt.after @@ -12,4 +12,5 @@ fun test() { val a: A = 2.foo } -// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable.CreateExtensionCallableFromUsageFix \ No newline at end of file +// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable.CreateExtensionCallableFromUsageFix +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.quickFixes.createFromUsage.K2CreatePropertyFromUsageBuilder$CreatePropertyFromUsageAction \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/varOnLibType.k2.kt.after b/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/varOnLibType.k2.kt.after new file mode 100644 index 000000000000..e14d6ea66ce8 --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/varOnLibType.k2.kt.after @@ -0,0 +1,13 @@ +// "Create extension property 'Int.foo'" "true" +// WITH_STDLIB + +private var Int.foo: A + +class A(val n: T) + +fun test() { + 2.foo = A("2") +} + +// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable.CreateExtensionCallableFromUsageFix +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.quickFixes.createFromUsage.K2CreatePropertyFromUsageBuilder$CreatePropertyFromUsageAction \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/varOnLibType.kt b/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/varOnLibType.kt index d7aaff1ecf08..9899ee2c75b0 100644 --- a/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/varOnLibType.kt +++ b/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/varOnLibType.kt @@ -7,4 +7,5 @@ fun test() { 2.foo = A("2") } -// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable.CreateExtensionCallableFromUsageFix \ No newline at end of file +// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable.CreateExtensionCallableFromUsageFix +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.quickFixes.createFromUsage.K2CreatePropertyFromUsageBuilder$CreatePropertyFromUsageAction \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/varOnLibType.kt.after b/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/varOnLibType.kt.after index efbfbd1a38bb..8d437be20374 100644 --- a/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/varOnLibType.kt.after +++ b/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/extension/varOnLibType.kt.after @@ -13,4 +13,5 @@ fun test() { 2.foo = A("2") } -// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable.CreateExtensionCallableFromUsageFix \ No newline at end of file +// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable.CreateExtensionCallableFromUsageFix +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.quickFixes.createFromUsage.K2CreatePropertyFromUsageBuilder$CreatePropertyFromUsageAction \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/memberValDelegateRuntime.k2.kt.after b/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/memberValDelegateRuntime.k2.kt.after deleted file mode 100644 index 5ca8ed8439e8..000000000000 --- a/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/memberValDelegateRuntime.k2.kt.after +++ /dev/null @@ -1,13 +0,0 @@ -import kotlin.properties.ReadOnlyProperty - -// "Create property 'foo'" "true" -// ERROR: Property must be initialized or be abstract -// ERROR: Variable 'foo' must be initialized - -class A { - private val foo: ReadOnlyProperty?, A> - val x: A by foo -} - -// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable.CreateCallableFromUsageFix -// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.quickFixes.createFromUsage.K2CreatePropertyFromUsageBuilder$CreatePropertyFromUsageAction \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/memberVarDelegateRuntime.k2.kt.after b/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/memberVarDelegateRuntime.k2.kt.after deleted file mode 100644 index 058527dbbd73..000000000000 --- a/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/memberVarDelegateRuntime.k2.kt.after +++ /dev/null @@ -1,13 +0,0 @@ -import kotlin.properties.ReadWriteProperty - -// "Create property 'foo'" "true" -// ERROR: Property must be initialized or be abstract -// ERROR: Variable 'foo' must be initialized - -class A { - private val foo: ReadWriteProperty?, A> - var x: A by foo -} - -// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable.CreateCallableFromUsageFix -// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.quickFixes.createFromUsage.K2CreatePropertyFromUsageBuilder$CreatePropertyFromUsageAction \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/valWithNullableType.k2.kt.after b/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/valWithNullableType.k2.kt.after index b07018e645c4..7a65ca2f502a 100644 --- a/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/valWithNullableType.k2.kt.after +++ b/plugins/kotlin/idea/tests/testData/quickfix/createFromUsage/createVariable/property/valWithNullableType.k2.kt.after @@ -3,7 +3,7 @@ // ERROR: Property must be initialized or be abstract class A(val n: T) { - val foo: A + val foo: A? } fun test() {