diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/references/KtPropertyDelegationMethodsReference.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/references/KtPropertyDelegationMethodsReference.kt index 8070756a809..616a36ca4fe 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/references/KtPropertyDelegationMethodsReference.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/references/KtPropertyDelegationMethodsReference.kt @@ -37,9 +37,9 @@ class KtPropertyDelegationMethodsReference(element: KtPropertyDelegate) : KtMult override fun getTargetDescriptors(context: BindingContext): Collection { val property = expression.getStrictParentOfType() ?: return emptyList() - val descriptor = context[BindingContext.DECLARATION_TO_DESCRIPTOR, property] as? VariableDescriptorWithAccessors ?: return emptyList() - return (descriptor.accessors.mapNotNull { - accessor -> + val descriptor = context[BindingContext.DECLARATION_TO_DESCRIPTOR, property] as? VariableDescriptorWithAccessors + ?: return emptyList() + return (descriptor.accessors.mapNotNull { accessor -> context.get(BindingContext.DELEGATED_PROPERTY_RESOLVED_CALL, accessor)?.candidateDescriptor } + listOfNotNull(context.get(BindingContext.PROVIDE_DELEGATE_RESOLVED_CALL, descriptor)?.candidateDescriptor)) } @@ -47,6 +47,10 @@ class KtPropertyDelegationMethodsReference(element: KtPropertyDelegate) : KtMult override val resolvesByNames: Collection get() = NAMES companion object { - private val NAMES = listOf(OperatorNameConventions.GET_VALUE, OperatorNameConventions.SET_VALUE) + private val NAMES = listOf( + OperatorNameConventions.GET_VALUE, + OperatorNameConventions.SET_VALUE, + OperatorNameConventions.PROVIDE_DELEGATE + ) } } diff --git a/idea/testData/editor/optimizeImports/common/ProvideDelegate.dependency.kt b/idea/testData/editor/optimizeImports/common/ProvideDelegate.dependency.kt new file mode 100644 index 00000000000..9f7675f907d --- /dev/null +++ b/idea/testData/editor/optimizeImports/common/ProvideDelegate.dependency.kt @@ -0,0 +1,7 @@ +package a + +import kotlin.properties.ReadOnlyProperty +import kotlin.reflect.KProperty + +class C +operator fun C.provideDelegate(thisRef: Any, prop: KProperty<*>): ReadOnlyProperty = TODO() \ No newline at end of file diff --git a/idea/testData/editor/optimizeImports/common/ProvideDelegate.kt b/idea/testData/editor/optimizeImports/common/ProvideDelegate.kt new file mode 100644 index 00000000000..6e7e955ae1d --- /dev/null +++ b/idea/testData/editor/optimizeImports/common/ProvideDelegate.kt @@ -0,0 +1,8 @@ +package b + +import a.C +import a.provideDelegate + +class Example { + val c: C = C() +} \ No newline at end of file diff --git a/idea/testData/editor/optimizeImports/common/ProvideDelegate.kt.after b/idea/testData/editor/optimizeImports/common/ProvideDelegate.kt.after new file mode 100644 index 00000000000..1f5d44f0da4 --- /dev/null +++ b/idea/testData/editor/optimizeImports/common/ProvideDelegate.kt.after @@ -0,0 +1,7 @@ +package b + +import a.C + +class Example { + val c: C = C() +} \ No newline at end of file diff --git a/idea/testData/editor/optimizeImports/common/ProvideDelegate2.dependency.kt b/idea/testData/editor/optimizeImports/common/ProvideDelegate2.dependency.kt new file mode 100644 index 00000000000..9f7675f907d --- /dev/null +++ b/idea/testData/editor/optimizeImports/common/ProvideDelegate2.dependency.kt @@ -0,0 +1,7 @@ +package a + +import kotlin.properties.ReadOnlyProperty +import kotlin.reflect.KProperty + +class C +operator fun C.provideDelegate(thisRef: Any, prop: KProperty<*>): ReadOnlyProperty = TODO() \ No newline at end of file diff --git a/idea/testData/editor/optimizeImports/common/ProvideDelegate2.kt b/idea/testData/editor/optimizeImports/common/ProvideDelegate2.kt new file mode 100644 index 00000000000..183ae149dda --- /dev/null +++ b/idea/testData/editor/optimizeImports/common/ProvideDelegate2.kt @@ -0,0 +1,8 @@ +package b + +import a.C +import a.provideDelegate + +class Example { + val c: C by C() +} \ No newline at end of file diff --git a/idea/testData/editor/optimizeImports/common/ProvideDelegate2.kt.after b/idea/testData/editor/optimizeImports/common/ProvideDelegate2.kt.after new file mode 100644 index 00000000000..183ae149dda --- /dev/null +++ b/idea/testData/editor/optimizeImports/common/ProvideDelegate2.kt.after @@ -0,0 +1,8 @@ +package b + +import a.C +import a.provideDelegate + +class Example { + val c: C by C() +} \ No newline at end of file diff --git a/idea/testData/inspections/unusedImport/inspectionData/expected.xml b/idea/testData/inspections/unusedImport/inspectionData/expected.xml index fd995c217ed..e713fe171cd 100644 --- a/idea/testData/inspections/unusedImport/inspectionData/expected.xml +++ b/idea/testData/inspections/unusedImport/inspectionData/expected.xml @@ -106,4 +106,13 @@ Unused import directive Unused import directive + + + provideDelegate.kt + 2 + light_idea_test_case + + Unused import directive + Unused import directive + diff --git a/idea/testData/inspections/unusedImport/noUnusedProvideDelegate.Dependency.kt b/idea/testData/inspections/unusedImport/noUnusedProvideDelegate.Dependency.kt new file mode 100644 index 00000000000..f507665838e --- /dev/null +++ b/idea/testData/inspections/unusedImport/noUnusedProvideDelegate.Dependency.kt @@ -0,0 +1,7 @@ +package onetwo + +import kotlin.properties.ReadOnlyProperty +import kotlin.reflect.KProperty + +class C +operator fun C.provideDelegate(thisRef: Any, prop: KProperty<*>): ReadOnlyProperty = TODO() \ No newline at end of file diff --git a/idea/testData/inspections/unusedImport/noUnusedProvideDelegate.kt b/idea/testData/inspections/unusedImport/noUnusedProvideDelegate.kt new file mode 100644 index 00000000000..1119d923512 --- /dev/null +++ b/idea/testData/inspections/unusedImport/noUnusedProvideDelegate.kt @@ -0,0 +1,6 @@ +import onetwo.C +import onetwo.provideDelegate + +class Example { + val c: C by C() +} \ No newline at end of file diff --git a/idea/testData/inspections/unusedImport/provideDelegate.Dependency.kt b/idea/testData/inspections/unusedImport/provideDelegate.Dependency.kt new file mode 100644 index 00000000000..9f7675f907d --- /dev/null +++ b/idea/testData/inspections/unusedImport/provideDelegate.Dependency.kt @@ -0,0 +1,7 @@ +package a + +import kotlin.properties.ReadOnlyProperty +import kotlin.reflect.KProperty + +class C +operator fun C.provideDelegate(thisRef: Any, prop: KProperty<*>): ReadOnlyProperty = TODO() \ No newline at end of file diff --git a/idea/testData/inspections/unusedImport/provideDelegate.kt b/idea/testData/inspections/unusedImport/provideDelegate.kt new file mode 100644 index 00000000000..efc87fdac50 --- /dev/null +++ b/idea/testData/inspections/unusedImport/provideDelegate.kt @@ -0,0 +1,6 @@ +import a.C +import a.provideDelegate + +class Example { + val c = C() +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/imports/JsOptimizeImportsTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/imports/JsOptimizeImportsTestGenerated.java index d7a3ec26dc5..7d1ecef9c02 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/imports/JsOptimizeImportsTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/imports/JsOptimizeImportsTestGenerated.java @@ -179,6 +179,16 @@ public class JsOptimizeImportsTestGenerated extends AbstractJsOptimizeImportsTes runTest("idea/testData/editor/optimizeImports/common/Overloads.kt"); } + @TestMetadata("ProvideDelegate.kt") + public void testProvideDelegate() throws Exception { + runTest("idea/testData/editor/optimizeImports/common/ProvideDelegate.kt"); + } + + @TestMetadata("ProvideDelegate2.kt") + public void testProvideDelegate2() throws Exception { + runTest("idea/testData/editor/optimizeImports/common/ProvideDelegate2.kt"); + } + @TestMetadata("TwoConstructors.kt") public void testTwoConstructors() throws Exception { runTest("idea/testData/editor/optimizeImports/common/TwoConstructors.kt"); diff --git a/idea/tests/org/jetbrains/kotlin/idea/imports/JvmOptimizeImportsTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/imports/JvmOptimizeImportsTestGenerated.java index 2a832462eb3..be13f6aaab9 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/imports/JvmOptimizeImportsTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/imports/JvmOptimizeImportsTestGenerated.java @@ -372,6 +372,16 @@ public class JvmOptimizeImportsTestGenerated extends AbstractJvmOptimizeImportsT runTest("idea/testData/editor/optimizeImports/common/Overloads.kt"); } + @TestMetadata("ProvideDelegate.kt") + public void testProvideDelegate() throws Exception { + runTest("idea/testData/editor/optimizeImports/common/ProvideDelegate.kt"); + } + + @TestMetadata("ProvideDelegate2.kt") + public void testProvideDelegate2() throws Exception { + runTest("idea/testData/editor/optimizeImports/common/ProvideDelegate2.kt"); + } + @TestMetadata("TwoConstructors.kt") public void testTwoConstructors() throws Exception { runTest("idea/testData/editor/optimizeImports/common/TwoConstructors.kt");