Safe Delete: Skip internal usages of class constructors when deleting class itself
#KT-8857 Fixed
This commit is contained in:
+13
-2
@@ -21,6 +21,7 @@ import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.util.Condition
|
||||
import com.intellij.openapi.util.Conditions
|
||||
import com.intellij.psi.PsiClass
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiMethod
|
||||
import com.intellij.psi.PsiParameter
|
||||
@@ -163,8 +164,18 @@ public class KotlinSafeDeleteProcessor : JavaSafeDeleteProcessor() {
|
||||
}
|
||||
|
||||
fun findDelegationCallUsages(element: PsiElement) {
|
||||
element.processDelegationCallConstructorUsages(element.getUseScope()) {
|
||||
usages.add(SafeDeleteReferenceSimpleDeleteUsageInfo(it, element, false))
|
||||
val constructors = when (element) {
|
||||
is PsiClass -> element.constructors
|
||||
is PsiMethod -> arrayOf(element)
|
||||
else -> return
|
||||
}
|
||||
for (constructor in constructors) {
|
||||
constructor.processDelegationCallConstructorUsages(constructor.useScope) {
|
||||
if (!getIgnoranceCondition().value(it)) {
|
||||
usages.add(SafeDeleteReferenceSimpleDeleteUsageInfo(it, element, false))
|
||||
}
|
||||
true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
open class <caret>Foo() {
|
||||
constructor(p: Int) : this()
|
||||
}
|
||||
|
||||
class Bar : Foo(1)
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
class Foo has 1 usage that is not safe to delete.
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
class <caret>Foo() {
|
||||
constructor(p: Int) : this()
|
||||
}
|
||||
|
||||
class Bar
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
class Bar
|
||||
Vendored
+1
-1
@@ -1 +1 @@
|
||||
class B has 4 usages that are not safe to delete.
|
||||
class B has 3 usages that are not safe to delete.
|
||||
@@ -55,6 +55,18 @@ public class SafeDeleteTestGenerated extends AbstractSafeDeleteTest {
|
||||
doClassTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("classWithExternalConstructructorUsage.kt")
|
||||
public void testClassWithExternalConstructructorUsage() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/safeDelete/deleteClass/kotlinClass/classWithExternalConstructructorUsage.kt");
|
||||
doClassTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("classWithInternalConstructructorUsage.kt")
|
||||
public void testClassWithInternalConstructructorUsage() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/safeDelete/deleteClass/kotlinClass/classWithInternalConstructructorUsage.kt");
|
||||
doClassTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("localClass1.kt")
|
||||
public void testLocalClass1() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/safeDelete/deleteClass/kotlinClass/localClass1.kt");
|
||||
|
||||
Reference in New Issue
Block a user