Import quick fix: support provideDelegate

#KT-28049 Fixed
This commit is contained in:
Dmitry Gridin
2019-09-24 16:23:46 +07:00
parent 79199260b9
commit 1ee827bfc8
3 changed files with 59 additions and 15 deletions
@@ -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) =
@@ -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 <T> bindResource(id: Int): A = A()
val image by <caret>bindResource<Int>(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<MyUI, A> = 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 <T> bindResource(id: Int): A = A()
val image by <caret>bindResource<Int>(42)
}
@@ -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");