Fix "Unused import" for 'provideDelegate'

#KT-31319 Fixed
This commit is contained in:
Dmitry Gridin
2019-05-14 18:18:36 +07:00
parent 3914530fa8
commit eee8d0263d
14 changed files with 108 additions and 4 deletions
@@ -37,9 +37,9 @@ class KtPropertyDelegationMethodsReference(element: KtPropertyDelegate) : KtMult
override fun getTargetDescriptors(context: BindingContext): Collection<DeclarationDescriptor> {
val property = expression.getStrictParentOfType<KtProperty>() ?: 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<Name> 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
)
}
}
@@ -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<Any, C> = TODO()
@@ -0,0 +1,8 @@
package b
import a.C
import a.provideDelegate
class Example {
val c: C = C()
}
@@ -0,0 +1,7 @@
package b
import a.C
class Example {
val c: C = C()
}
@@ -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<Any, C> = TODO()
@@ -0,0 +1,8 @@
package b
import a.C
import a.provideDelegate
class Example {
val c: C by C()
}
@@ -0,0 +1,8 @@
package b
import a.C
import a.provideDelegate
class Example {
val c: C by C()
}
@@ -106,4 +106,13 @@
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Unused import directive</problem_class>
<description>Unused import directive</description>
</problem>
<problem>
<file>provideDelegate.kt</file>
<line>2</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="provideDelegate.kt" />
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Unused import directive</problem_class>
<description>Unused import directive</description>
</problem>
</problems>
@@ -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<Any, C> = TODO()
@@ -0,0 +1,6 @@
import onetwo.C
import onetwo.provideDelegate
class Example {
val c: C by C()
}
@@ -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<Any, C> = TODO()
@@ -0,0 +1,6 @@
import a.C
import a.provideDelegate
class Example {
val c = C()
}
@@ -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");
@@ -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");