Fix "Unused import" for 'provideDelegate'
#KT-31319 Fixed
This commit is contained in:
+8
-4
@@ -37,9 +37,9 @@ class KtPropertyDelegationMethodsReference(element: KtPropertyDelegate) : KtMult
|
|||||||
|
|
||||||
override fun getTargetDescriptors(context: BindingContext): Collection<DeclarationDescriptor> {
|
override fun getTargetDescriptors(context: BindingContext): Collection<DeclarationDescriptor> {
|
||||||
val property = expression.getStrictParentOfType<KtProperty>() ?: return emptyList()
|
val property = expression.getStrictParentOfType<KtProperty>() ?: return emptyList()
|
||||||
val descriptor = context[BindingContext.DECLARATION_TO_DESCRIPTOR, property] as? VariableDescriptorWithAccessors ?: return emptyList()
|
val descriptor = context[BindingContext.DECLARATION_TO_DESCRIPTOR, property] as? VariableDescriptorWithAccessors
|
||||||
return (descriptor.accessors.mapNotNull {
|
?: return emptyList()
|
||||||
accessor ->
|
return (descriptor.accessors.mapNotNull { accessor ->
|
||||||
context.get(BindingContext.DELEGATED_PROPERTY_RESOLVED_CALL, accessor)?.candidateDescriptor
|
context.get(BindingContext.DELEGATED_PROPERTY_RESOLVED_CALL, accessor)?.candidateDescriptor
|
||||||
} + listOfNotNull(context.get(BindingContext.PROVIDE_DELEGATE_RESOLVED_CALL, descriptor)?.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
|
override val resolvesByNames: Collection<Name> get() = NAMES
|
||||||
|
|
||||||
companion object {
|
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>
|
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Unused import directive</problem_class>
|
||||||
<description>Unused import directive</description>
|
<description>Unused import directive</description>
|
||||||
</problem>
|
</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>
|
</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()
|
||||||
|
}
|
||||||
+10
@@ -179,6 +179,16 @@ public class JsOptimizeImportsTestGenerated extends AbstractJsOptimizeImportsTes
|
|||||||
runTest("idea/testData/editor/optimizeImports/common/Overloads.kt");
|
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")
|
@TestMetadata("TwoConstructors.kt")
|
||||||
public void testTwoConstructors() throws Exception {
|
public void testTwoConstructors() throws Exception {
|
||||||
runTest("idea/testData/editor/optimizeImports/common/TwoConstructors.kt");
|
runTest("idea/testData/editor/optimizeImports/common/TwoConstructors.kt");
|
||||||
|
|||||||
+10
@@ -372,6 +372,16 @@ public class JvmOptimizeImportsTestGenerated extends AbstractJvmOptimizeImportsT
|
|||||||
runTest("idea/testData/editor/optimizeImports/common/Overloads.kt");
|
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")
|
@TestMetadata("TwoConstructors.kt")
|
||||||
public void testTwoConstructors() throws Exception {
|
public void testTwoConstructors() throws Exception {
|
||||||
runTest("idea/testData/editor/optimizeImports/common/TwoConstructors.kt");
|
runTest("idea/testData/editor/optimizeImports/common/TwoConstructors.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user