Safe delete: search for actual declarations more accurately
This commit is contained in:
+13
-7
@@ -51,6 +51,7 @@ import org.jetbrains.kotlin.idea.refactoring.isTrueJavaMethod
|
||||
import org.jetbrains.kotlin.idea.references.KtReference
|
||||
import org.jetbrains.kotlin.idea.search.ideaExtensions.KotlinReferencesSearchOptions
|
||||
import org.jetbrains.kotlin.idea.search.ideaExtensions.KotlinReferencesSearchParameters
|
||||
import org.jetbrains.kotlin.idea.search.projectScope
|
||||
import org.jetbrains.kotlin.idea.search.usagesSearch.processDelegationCallConstructorUsages
|
||||
import org.jetbrains.kotlin.idea.util.actualsForExpected
|
||||
import org.jetbrains.kotlin.idea.util.liftToExpected
|
||||
@@ -58,6 +59,7 @@ import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getParentOfTypeAndBranch
|
||||
import org.jetbrains.kotlin.psi.psiUtil.hasActualModifier
|
||||
import org.jetbrains.kotlin.psi.psiUtil.parameterIndex
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
@@ -97,7 +99,7 @@ class KotlinSafeDeleteProcessor : JavaSafeDeleteProcessor() {
|
||||
return elementsToSearch.asSequence().flatMap {
|
||||
val searchParameters = KotlinReferencesSearchParameters(
|
||||
it,
|
||||
it.useScope,
|
||||
if (it.hasActualModifier()) it.project.projectScope() else it.useScope,
|
||||
kotlinOptions = KotlinReferencesSearchOptions(acceptCallableOverrides = true)
|
||||
)
|
||||
ReferencesSearch.search(searchParameters).asSequence()
|
||||
@@ -265,14 +267,18 @@ class KotlinSafeDeleteProcessor : JavaSafeDeleteProcessor() {
|
||||
}
|
||||
|
||||
is KtSecondaryConstructor -> {
|
||||
element.getRepresentativeLightMethod()?.let { method ->
|
||||
findDelegationCallUsages(method)
|
||||
findUsagesByJavaProcessor(method, false)
|
||||
} ?: findKotlinDeclarationUsages(element)
|
||||
if (element.hasActualModifier()) {
|
||||
findKotlinDeclarationUsages(element)
|
||||
} else {
|
||||
element.getRepresentativeLightMethod()?.let { method ->
|
||||
findDelegationCallUsages(method)
|
||||
findUsagesByJavaProcessor(method, false)
|
||||
} ?: findKotlinDeclarationUsages(element)
|
||||
}
|
||||
}
|
||||
|
||||
is KtNamedFunction -> {
|
||||
if (element.isLocal) {
|
||||
if (element.isLocal || element.hasActualModifier()) {
|
||||
findKotlinDeclarationUsages(element)
|
||||
} else {
|
||||
val lightMethods = element.toLightMethods()
|
||||
@@ -293,7 +299,7 @@ class KotlinSafeDeleteProcessor : JavaSafeDeleteProcessor() {
|
||||
}
|
||||
|
||||
is KtProperty -> {
|
||||
if (element.isLocal) {
|
||||
if (element.isLocal || element.hasActualModifier()) {
|
||||
findKotlinDeclarationUsages(element)
|
||||
} else {
|
||||
findUsagesByJavaProcessor(element)
|
||||
|
||||
+13
-7
@@ -49,6 +49,7 @@ import org.jetbrains.kotlin.idea.refactoring.isTrueJavaMethod
|
||||
import org.jetbrains.kotlin.idea.references.KtReference
|
||||
import org.jetbrains.kotlin.idea.search.ideaExtensions.KotlinReferencesSearchOptions
|
||||
import org.jetbrains.kotlin.idea.search.ideaExtensions.KotlinReferencesSearchParameters
|
||||
import org.jetbrains.kotlin.idea.search.projectScope
|
||||
import org.jetbrains.kotlin.idea.search.usagesSearch.processDelegationCallConstructorUsages
|
||||
import org.jetbrains.kotlin.idea.util.actualsForExpected
|
||||
import org.jetbrains.kotlin.idea.util.liftToExpected
|
||||
@@ -56,6 +57,7 @@ import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getParentOfTypeAndBranch
|
||||
import org.jetbrains.kotlin.psi.psiUtil.hasActualModifier
|
||||
import org.jetbrains.kotlin.psi.psiUtil.parameterIndex
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
@@ -92,7 +94,7 @@ class KotlinSafeDeleteProcessor : JavaSafeDeleteProcessor() {
|
||||
return elementsToSearch.asSequence().flatMap {
|
||||
val searchParameters = KotlinReferencesSearchParameters(
|
||||
it,
|
||||
it.useScope,
|
||||
if (it.hasActualModifier()) it.project.projectScope() else it.useScope,
|
||||
kotlinOptions = KotlinReferencesSearchOptions(acceptCallableOverrides = true)
|
||||
)
|
||||
ReferencesSearch.search(searchParameters)
|
||||
@@ -251,14 +253,18 @@ class KotlinSafeDeleteProcessor : JavaSafeDeleteProcessor() {
|
||||
}
|
||||
|
||||
is KtSecondaryConstructor -> {
|
||||
element.getRepresentativeLightMethod()?.let { method ->
|
||||
findDelegationCallUsages(method)
|
||||
findUsagesByJavaProcessor(method, false)
|
||||
} ?: findKotlinDeclarationUsages(element)
|
||||
if (element.hasActualModifier()) {
|
||||
findKotlinDeclarationUsages(element)
|
||||
} else {
|
||||
element.getRepresentativeLightMethod()?.let { method ->
|
||||
findDelegationCallUsages(method)
|
||||
findUsagesByJavaProcessor(method, false)
|
||||
} ?: findKotlinDeclarationUsages(element)
|
||||
}
|
||||
}
|
||||
|
||||
is KtNamedFunction -> {
|
||||
if (element.isLocal) {
|
||||
if (element.isLocal || element.hasActualModifier()) {
|
||||
findKotlinDeclarationUsages(element)
|
||||
}
|
||||
else {
|
||||
@@ -281,7 +287,7 @@ class KotlinSafeDeleteProcessor : JavaSafeDeleteProcessor() {
|
||||
}
|
||||
|
||||
is KtProperty -> {
|
||||
if (element.isLocal) {
|
||||
if (element.isLocal || element.hasActualModifier()) {
|
||||
findKotlinDeclarationUsages(element)
|
||||
}
|
||||
else {
|
||||
|
||||
+13
-7
@@ -51,6 +51,7 @@ import org.jetbrains.kotlin.idea.refactoring.isTrueJavaMethod
|
||||
import org.jetbrains.kotlin.idea.references.KtReference
|
||||
import org.jetbrains.kotlin.idea.search.ideaExtensions.KotlinReferencesSearchOptions
|
||||
import org.jetbrains.kotlin.idea.search.ideaExtensions.KotlinReferencesSearchParameters
|
||||
import org.jetbrains.kotlin.idea.search.projectScope
|
||||
import org.jetbrains.kotlin.idea.search.usagesSearch.processDelegationCallConstructorUsages
|
||||
import org.jetbrains.kotlin.idea.util.actualsForExpected
|
||||
import org.jetbrains.kotlin.idea.util.liftToExpected
|
||||
@@ -58,6 +59,7 @@ import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getParentOfTypeAndBranch
|
||||
import org.jetbrains.kotlin.psi.psiUtil.hasActualModifier
|
||||
import org.jetbrains.kotlin.psi.psiUtil.parameterIndex
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
@@ -94,7 +96,7 @@ class KotlinSafeDeleteProcessor : JavaSafeDeleteProcessor() {
|
||||
return elementsToSearch.asSequence().flatMap {
|
||||
val searchParameters = KotlinReferencesSearchParameters(
|
||||
it,
|
||||
it.useScope,
|
||||
if (it.hasActualModifier()) it.project.projectScope() else it.useScope,
|
||||
kotlinOptions = KotlinReferencesSearchOptions(acceptCallableOverrides = true)
|
||||
)
|
||||
ReferencesSearch.search(searchParameters)
|
||||
@@ -261,14 +263,18 @@ class KotlinSafeDeleteProcessor : JavaSafeDeleteProcessor() {
|
||||
}
|
||||
|
||||
is KtSecondaryConstructor -> {
|
||||
element.getRepresentativeLightMethod()?.let { method ->
|
||||
findDelegationCallUsages(method)
|
||||
findUsagesByJavaProcessor(method, false)
|
||||
} ?: findKotlinDeclarationUsages(element)
|
||||
if (element.hasActualModifier()) {
|
||||
findKotlinDeclarationUsages(element)
|
||||
} else {
|
||||
element.getRepresentativeLightMethod()?.let { method ->
|
||||
findDelegationCallUsages(method)
|
||||
findUsagesByJavaProcessor(method, false)
|
||||
} ?: findKotlinDeclarationUsages(element)
|
||||
}
|
||||
}
|
||||
|
||||
is KtNamedFunction -> {
|
||||
if (element.isLocal) {
|
||||
if (element.isLocal || element.hasActualModifier()) {
|
||||
findKotlinDeclarationUsages(element)
|
||||
}
|
||||
else {
|
||||
@@ -291,7 +297,7 @@ class KotlinSafeDeleteProcessor : JavaSafeDeleteProcessor() {
|
||||
}
|
||||
|
||||
is KtProperty -> {
|
||||
if (element.isLocal) {
|
||||
if (element.isLocal || element.hasActualModifier()) {
|
||||
findKotlinDeclarationUsages(element)
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -1 +1 @@
|
||||
class test.Foo has 1 usage that is not safe to delete.
|
||||
class test.Foo has 3 usages that are not safe to delete.
|
||||
+1
-1
@@ -1 +1 @@
|
||||
function Foo.foo(Int) has 2 usages that are not safe to delete.
|
||||
function Foo.foo(Int) has 3 usages that are not safe to delete.
|
||||
+1
-1
@@ -1 +1 @@
|
||||
property Foo.foo has 2 usages that are not safe to delete.
|
||||
property Foo.foo has 3 usages that are not safe to delete.
|
||||
Vendored
+1
-1
@@ -1 +1 @@
|
||||
constructor Foo(Int) has 2 usages that are not safe to delete.
|
||||
constructor Foo(Int) has 3 usages that are not safe to delete.
|
||||
@@ -1 +1 @@
|
||||
function test.foo(Int) has 2 usages that are not safe to delete.
|
||||
function test.foo(Int) has 3 usages that are not safe to delete.
|
||||
@@ -1 +1 @@
|
||||
property test.foo has 2 usages that are not safe to delete.
|
||||
property test.foo has 3 usages that are not safe to delete.
|
||||
Reference in New Issue
Block a user