Safe Delete: Use actual usage PSI in UsageInfo instead of declaration
#KT-19161 Fixed
This commit is contained in:
+4
-7
@@ -135,10 +135,11 @@ class KotlinSafeDeleteProcessor : JavaSafeDeleteProcessor() {
|
||||
ReferencesSearch.search(declaration, declaration.useScope)
|
||||
.asSequence()
|
||||
.filterNot { reference -> getIgnoranceCondition().value(reference.element) }
|
||||
.mapTo(usages) { reference ->
|
||||
reference.element.getNonStrictParentOfType<KtImportDirective>()?.let { importDirective ->
|
||||
.mapNotNullTo(usages) { reference ->
|
||||
val refElement = reference.element ?: return@mapNotNullTo null
|
||||
refElement.getNonStrictParentOfType<KtImportDirective>()?.let { importDirective ->
|
||||
SafeDeleteImportDirectiveUsageInfo(importDirective, element)
|
||||
} ?: SafeDeleteReferenceSimpleDeleteUsageInfo(element, declaration, false)
|
||||
} ?: SafeDeleteReferenceSimpleDeleteUsageInfo(refElement, declaration, false)
|
||||
}
|
||||
|
||||
return getSearchInfo(declaration)
|
||||
@@ -185,10 +186,6 @@ class KotlinSafeDeleteProcessor : JavaSafeDeleteProcessor() {
|
||||
|
||||
return when (element) {
|
||||
is KtClassOrObject -> {
|
||||
if (element is KtEnumEntry) {
|
||||
LightClassUtil.getLightClassBackingField(element)?.let { findUsagesByJavaProcessor(it, false) }
|
||||
}
|
||||
|
||||
element.toLightClass()?.let { klass ->
|
||||
findDelegationCallUsages(klass)
|
||||
findUsagesByJavaProcessor(klass, false)
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package test
|
||||
|
||||
fun foo() {
|
||||
val <caret>x = 1
|
||||
println(x)
|
||||
println(x)
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
variable test.foo.x has 2 usages that are not safe to delete.
|
||||
+1
-1
@@ -1 +1 @@
|
||||
type alias MyString has 1 usage that is not safe to delete.
|
||||
type alias MyString has 2 usages that are not safe to delete.
|
||||
+6
@@ -503,6 +503,12 @@ public class SafeDeleteTestGenerated extends AbstractSafeDeleteTest {
|
||||
doPropertyTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("localVar.kt")
|
||||
public void testLocalVar() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/safeDelete/deleteProperty/kotlinProperty/localVar.kt");
|
||||
doPropertyTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("noUsages.kt")
|
||||
public void testNoUsages() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/safeDelete/deleteProperty/kotlinProperty/noUsages.kt");
|
||||
|
||||
Reference in New Issue
Block a user