From 1ee827bfc802da34164623873a38d10c20071b80 Mon Sep 17 00:00:00 2001 From: Dmitry Gridin Date: Tue, 24 Sep 2019 16:23:46 +0700 Subject: [PATCH] Import quick fix: support `provideDelegate` #KT-28049 Fixed --- .../kotlin/idea/quickfix/ImportFix.kt | 19 ++----- .../delegateExtensionProvideDelegate.test | 50 +++++++++++++++++++ .../QuickFixMultiFileTestGenerated.java | 5 ++ 3 files changed, 59 insertions(+), 15 deletions(-) create mode 100644 idea/testData/quickfix/autoImports/delegateExtensionProvideDelegate.test diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/ImportFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/ImportFix.kt index de43a2da4b8..26bb3e31bc9 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/ImportFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/ImportFix.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.idea.quickfix @@ -57,6 +46,7 @@ import org.jetbrains.kotlin.idea.util.* import org.jetbrains.kotlin.incremental.components.NoLookupLocation import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.Name +import org.jetbrains.kotlin.platform.jvm.isJvm import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.KtPsiUtil.isSelectorInQualified import org.jetbrains.kotlin.psi.psiUtil.* @@ -65,7 +55,6 @@ import org.jetbrains.kotlin.resolve.bindingContextUtil.getDataFlowInfoBefore import org.jetbrains.kotlin.resolve.calls.callUtil.getParentCall import org.jetbrains.kotlin.resolve.calls.context.ContextDependency import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe -import org.jetbrains.kotlin.platform.jvm.isJvm import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode import org.jetbrains.kotlin.resolve.scopes.ExplicitImportsScope import org.jetbrains.kotlin.resolve.scopes.utils.addImportingScope @@ -487,7 +476,7 @@ internal class DelegateAccessorsImportFix( OperatorNameConventions.GET_VALUE else OperatorNameConventions.SET_VALUE - }.distinct() + }.plus(OperatorNameConventions.PROVIDE_DELEGATE).distinct() } override fun createImportAction(diagnostic: Diagnostic) = diff --git a/idea/testData/quickfix/autoImports/delegateExtensionProvideDelegate.test b/idea/testData/quickfix/autoImports/delegateExtensionProvideDelegate.test new file mode 100644 index 00000000000..979d9724096 --- /dev/null +++ b/idea/testData/quickfix/autoImports/delegateExtensionProvideDelegate.test @@ -0,0 +1,50 @@ +// FILE: first.before.kt +// "Import" "true" +// ERROR: Type 'A' has no method 'getValue(MyUI, KProperty<*>)' and thus it cannot serve as a delegate + +package bs + +import some.A + +class MyUI { + fun bindResource(id: Int): A = A() + + val image by bindResource(42) +} + + + +// FILE: second.kt +package some + +import bs.MyUI +import kotlin.properties.ReadOnlyProperty +import kotlin.reflect.KProperty + +class A + +operator fun A.provideDelegate( + thisRef: MyUI, + prop: KProperty<*> +): ReadOnlyProperty = TODO() + + + + +// FILE: first.after.kt +// "Import" "true" +// ERROR: Type 'A' has no method 'getValue(MyUI, KProperty<*>)' and thus it cannot serve as a delegate + +package bs + +import some.A +import some.provideDelegate + +class MyUI { + fun bindResource(id: Int): A = A() + + val image by bindResource(42) +} + + + diff --git a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiFileTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiFileTestGenerated.java index cb2de5d3d6e..1ab12cb23f9 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiFileTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiFileTestGenerated.java @@ -543,6 +543,11 @@ public class QuickFixMultiFileTestGenerated extends AbstractQuickFixMultiFileTes runTest("idea/testData/quickfix/autoImports/delegateExtensionGet.test"); } + @TestMetadata("delegateExtensionProvideDelegate.test") + public void testDelegateExtensionProvideDelegate() throws Exception { + runTest("idea/testData/quickfix/autoImports/delegateExtensionProvideDelegate.test"); + } + @TestMetadata("delegateExtensionSet.test") public void testDelegateExtensionSet() throws Exception { runTest("idea/testData/quickfix/autoImports/delegateExtensionSet.test");