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)
|
ReferencesSearch.search(declaration, declaration.useScope)
|
||||||
.asSequence()
|
.asSequence()
|
||||||
.filterNot { reference -> getIgnoranceCondition().value(reference.element) }
|
.filterNot { reference -> getIgnoranceCondition().value(reference.element) }
|
||||||
.mapTo(usages) { reference ->
|
.mapNotNullTo(usages) { reference ->
|
||||||
reference.element.getNonStrictParentOfType<KtImportDirective>()?.let { importDirective ->
|
val refElement = reference.element ?: return@mapNotNullTo null
|
||||||
|
refElement.getNonStrictParentOfType<KtImportDirective>()?.let { importDirective ->
|
||||||
SafeDeleteImportDirectiveUsageInfo(importDirective, element)
|
SafeDeleteImportDirectiveUsageInfo(importDirective, element)
|
||||||
} ?: SafeDeleteReferenceSimpleDeleteUsageInfo(element, declaration, false)
|
} ?: SafeDeleteReferenceSimpleDeleteUsageInfo(refElement, declaration, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
return getSearchInfo(declaration)
|
return getSearchInfo(declaration)
|
||||||
@@ -185,10 +186,6 @@ class KotlinSafeDeleteProcessor : JavaSafeDeleteProcessor() {
|
|||||||
|
|
||||||
return when (element) {
|
return when (element) {
|
||||||
is KtClassOrObject -> {
|
is KtClassOrObject -> {
|
||||||
if (element is KtEnumEntry) {
|
|
||||||
LightClassUtil.getLightClassBackingField(element)?.let { findUsagesByJavaProcessor(it, false) }
|
|
||||||
}
|
|
||||||
|
|
||||||
element.toLightClass()?.let { klass ->
|
element.toLightClass()?.let { klass ->
|
||||||
findDelegationCallUsages(klass)
|
findDelegationCallUsages(klass)
|
||||||
findUsagesByJavaProcessor(klass, false)
|
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);
|
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")
|
@TestMetadata("noUsages.kt")
|
||||||
public void testNoUsages() throws Exception {
|
public void testNoUsages() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/safeDelete/deleteProperty/kotlinProperty/noUsages.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/safeDelete/deleteProperty/kotlinProperty/noUsages.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user